diff --git a/README.md b/README.md index 0de8ae5..b9f767a 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,31 @@ Helper Macros Mysteriously missing from GLIBC +- `ISCLR(word,bit)` + + Is bit in (integer) word cleared? + +- `ISSET(word,bit)` + + Is bit in (integer) word set? + +- `ISOTHER(word,bit)` + + Is any other bits, except bit, in (integer) word set? + +- `SETBIT(word,bit)` + + Set bit in (integer) word. + +- `CLRBIT(word,bit)` + + Clear bit in (integer) word. + +- `NELEMS(array)` + + Returns the number of elements in an array. From the great book, The + Practice of Programming, by Kernighan and Pike. + - `UNUSED(var)` Shorter and more readable version of `var __attribute__ ((unused))` diff --git a/lite.h b/lite.h index 0d0bcae..6cdd4fc 100644 --- a/lite.h +++ b/lite.h @@ -87,9 +87,34 @@ long long strtonum (const char *numstr, long long minval, long long maxval, cons #ifndef blkdev # define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min))) #endif + #ifndef S_ISEXEC # define S_ISEXEC(m) (((m) & S_IXUSR) == S_IXUSR) #endif + +/* Unline isset(), setbit() et al, these work with integers/shorts/longwords/etc. */ +#ifndef ISCLR +#define ISCLR(word,bit) ((word & (1 << (bit)) ? 0 : 1)) +#endif +#ifndef ISSET +#define ISSET(word,bit) ((word & (1 << (bit)) ? 1 : 0)) +#endif +#ifndef ISOTHER +#define ISOTHER(word,bit) ((word & ~(1 << (bit)) ? 1 : 0)) /* Is any other bit set? */ +#endif +#ifndef SETBIT +#define SETBIT(word,bit) (word |= (1 << (bit))) +#endif +#ifndef CLRBIT +#define CLRBIT(word,bit) (word &= ~(1 << (bit))) +#endif + +/* From The Practice of Programming, by Kernighan and Pike */ +#ifndef NELEMS +#define NELEMS(array) (sizeof(array) / sizeof(array[0])) +#endif + +/* Mark a function variable as unused, useful for generic callbacks */ #ifndef UNUSED #define UNUSED(x) UNUSED_ ## x __attribute__ ((unused)) #endif