From: matz@... (Yukihiro Matsumoto) Date: 1996-12-26T12:44:14+09:00 Subject: [ruby-list:1518] dynamic endian check for nextstep まつもと ゆきひろです NEXTSTEPのFat Binary用のendian check patchです. これで実行時にendianをチェックします.でもテストしてません.^^;; --- defines.h~ Wed Dec 25 10:22:07 1996 +++ defines.h Thu Dec 26 02:51:49 1996 @@ -17,6 +17,7 @@ #undef SJIS #ifdef NeXT +#define DYNAMIC_ENDIAN /* determine endian at runtime */ #define S_IXUSR _S_IXUSR /* execute/search permission, owner */ #define S_IXGRP 0000010 /* execute/search permission, group */ #define S_IXOTH 0000001 /* execute/search permission, other */ --- pack.c~ Tue Dec 24 15:39:08 1996 +++ pack.c Thu Dec 26 02:50:19 1996 @@ -19,6 +19,36 @@ +(((x)>>24)&0xFF) \ +(((x)&0x0000FF00)<<8) \ +(((x)&0x00FF0000)>>8) ) + +#ifdef DYNAMIC_ENDIAN +#ifdef ntohs +#undef ntohs +#undef ntohl +#undef htons +#undef htonl +#endif +static int +endian() +{ + static int init = 0; + static int endian_value; + char *p; + + if (init) return endian_value; + init = 1; + p = (char*)&init; + return endian_value = p[0]?0:1; +} + +#define ntohs(x) (endian()?(x):swaps(x)) +#define ntohl(x) (endian()?(x):swapl(x)) +#define htons(x) (endian()?(x):swaps(x)) +#define htonl(x) (endian()?(x):swapl(x)) +#define htovs(x) (endian()?swaps(x):(x)) +#define htovl(x) (endian()?swapl(x):(x)) +#define vtohs(x) (endian()?swaps(x):(x)) +#define vtohl(x) (endian()?swapl(x):(x)) +#else #ifdef WORDS_BIGENDIAN #ifndef ntohs #define ntohs(x) (x) @@ -41,6 +71,7 @@ #define htovl(x) (x) #define vtohs(x) (x) #define vtohl(x) (x) +#endif #endif extern VALUE cString, cArray;