endian_utils.h

説明を見る。
00001 /*------------------------------------------------------------------------*/
00013 #ifndef ENDIAN_UTILS_H
00014 #define ENDIAN_UTILS_H
00015 
00016 
00017 /* ヘッダファイル */
00018 #ifdef HAVE_CONFIG_H
00019     #include "config.h"
00020 #endif
00021 
00022 
00023 #ifdef HAVE_STDINT_H
00024     #include <stdint.h>
00025 #else
00026     #include <inttypes.h>
00027 #endif
00028 
00029 
00030 #if defined(HAVE_ENDIAN_H)
00031     #include <endian.h>
00032 #elif defined(HAVE_MACHINE_ENDIAN_H)
00033     #include <machine/endian.h>
00034 #else
00035     #ifdef ntohs
00036     #undef ntohs
00037     #endif
00038 
00039     #ifdef htons
00040     #undef htons
00041     #endif
00042 
00043     #ifdef ntohl
00044     #undef ntohl
00045     #endif
00046 
00047     #ifdef htonl
00048     #undef htonl
00049     #endif
00050 #endif
00051 
00052 
00053 /* マクロ定義 */
00054 #ifdef __BIG_ENDIAN__
00055     #define ntohd(d)    (d)
00056     #define htond(d)    (d)
00057 #else
00058     #define ntohd(d)    swapd(d)
00059     #define htond(d)    swapd(d)
00060 #endif /* __BIG_ENDIAN__ */
00061 
00062 
00063 #ifndef ntohl
00064     #define swap16(n)   (((((uint16_t) n) << 8) & 0xff00) | 
00065                          ((((uint16_t) n) >> 8) & 0x00ff))
00066 
00067     #define swap32(n)   (((((uint32_t) n) << 24) & 0xff000000) | 
00068                          ((((uint32_t) n) <<  8) & 0x00ff0000) | 
00069                          ((((uint32_t) n) >>  8) & 0x0000ff00) | 
00070                          ((((uint32_t) n) >> 24) & 0x000000ff))
00071 
00072     #ifdef __BIG_ENDIAN__
00073         #define ntohs(n)    (n)
00074         #define htons(n)    (n)
00075         #define ntohl(n)    (n)
00076         #define htonl(n)    (n)
00077     #else
00078         #define ntohs(n)    swap16(n)
00079         #define htons(n)    swap16(n)
00080         #define ntohl(n)    swap32(n)
00081         #define htonl(n)    swap32(n)
00082     #endif /* __BIG_ENDIAN__ */
00083 #endif
00084 
00085 
00086 /* 関数プロトタイプ */
00087 
00088 #ifdef __cplusplus
00089 extern "C" {
00090 #endif
00091 
00092 
00093 double      swapd(double d);
00094 
00095 
00096 #ifdef __cplusplus
00097 }
00098 #endif
00099 
00100 
00101 #endif /* ENDIAN_UTILS_H */
00102 

NEWT/0に対してThu Nov 23 16:50:42 2006に生成されました。  doxygen 1.5.0