00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __PREPROC_H__
00009 #define __PREPROC_H__
00010
00015 #include <fcntl.h>
00016 #include <sys/stat.h>
00017
00018
00022 #define _BITCOUNTx(x, m, s) ( ((x) & m) + (((x) & (m << s)) >> s) )
00023 #define _BITCOUNT6(x) (_BITCOUNTx( (x), 0x5555555555555555ULL, 1))
00024 #define _BITCOUNT5(x) (_BITCOUNTx(_BITCOUNT6(x), 0x3333333333333333ULL, 2))
00025 #define _BITCOUNT4(x) (_BITCOUNTx(_BITCOUNT5(x), 0x0f0f0f0f0f0f0f0fULL, 4))
00026 #define _BITCOUNT3(x) (_BITCOUNTx(_BITCOUNT4(x), 0x00ff00ff00ff00ffULL, 8))
00027 #define _BITCOUNT2(x) (_BITCOUNTx(_BITCOUNT3(x), 0x0000ffff0000ffffULL, 16))
00028 #define _BITCOUNT1(x) (_BITCOUNTx(_BITCOUNT2(x), 0x00000000ffffffffULL, 32))
00029 #define _BITCOUNT(x) ( (int)_BITCOUNT1(x) )
00030
00036 #define MODE_T_SHIFT_BITS (_BITCOUNT(S_IFMT ^ (S_IFMT-1)) -1)
00037
00039 #define PACKED_MODE_T_NEEDED_BITS (_BITCOUNT(S_IFMT))
00040
00041
00045 #define MODE_T_to_PACKED(mode) ((mode) >> MODE_T_SHIFT_BITS)
00046 #define PACKED_to_MODE_T(p) ((p) << MODE_T_SHIFT_BITS)
00047
00050 #define TEST_PACKED(test, val) test(PACKED_to_MODE_T(val))
00051
00052
00053 #endif