--- rxvt-unicode/src/rxvtutil.h 2008/11/05 14:43:54 1.38 +++ rxvt-unicode/src/rxvtutil.h 2011/01/03 03:05:47 1.42 @@ -3,9 +3,12 @@ #include #include +#include using namespace std; +#define ARRAY_LENGTH(v) (sizeof (v) / sizeof ((v)[0])) + #define PP_CONCAT_(a, b) a ## b #define PP_CONCAT(a, b) PP_CONCAT_(a, b) #define PP_STRINGIFY_(a) #a @@ -22,7 +25,7 @@ #endif // put into ifs if you are very sure that the expression -// is mostly true or mosty false. note that these return +// is mostly true or mostly false. note that these return // booleans, not the expression. #define expect_false(expr) expect ((expr) != 0, 0) #define expect_true(expr) expect ((expr) != 0, 1) @@ -40,16 +43,18 @@ # define THROW(x) throw x #endif -extern class byteorder { - static unsigned int e; // at least 32 bits -public: - byteorder (); - - static bool big_endian () { return e == 0x11223344; }; - static bool network () { return e == 0x11223344; }; - static bool little_endian () { return e == 0x44332211; }; - static bool vax () { return e == 0x44332211; }; -} byteorder; +namespace byteorder { + static uint32_t e () + { + char c [4] = { 0x11, 0x22, 0x33, 0x44 }; + return *(uint32_t *)c; + } + + static bool big_endian () { return e () == 0x11223344; }; + static bool network () { return big_endian (); }; + static bool little_endian () { return e () == 0x44332211; }; + static bool vax () { return little_endian (); }; +}; // various utility functions template static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } @@ -93,12 +98,13 @@ // some bit functions, xft fuck me plenty #if HAVE_GCC_BUILTINS -static inline int ctz (unsigned int x) { return __builtin_ctz (x); } -static inline int popcount (unsigned int x) { return __builtin_popcount (x); } +/* netbsd stupidly defines popcount itself and puts it into string.h */ +static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); } +static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); } #else // count trailing zero bits and count # of one bits -int ctz (unsigned int x) CONST; -int popcount (unsigned int x) CONST; +int rxvt_ctz (unsigned int x) CONST; +int rxvt_popcount (unsigned int x) CONST; #endif // in range including end