base.h (1147B)
1 #pragma once 2 #define _XOPEN_SOURCE 600 3 4 #include <sys/types.h> 5 #include <stdbool.h> 6 #include <stdlib.h> 7 #include <stdint.h> 8 9 #ifndef nil 10 # define nil ((void*)0) 11 #endif 12 13 #ifndef nelem 14 # define nelem(ary) (sizeof(ary) / sizeof(*ary)) 15 #endif 16 17 #ifndef offsetof 18 # define offsetof(type, member) ((size_t)&((type*)0)->member) 19 #endif 20 #define structptr(ptr, type, offset) \ 21 ((type*)((char*)(ptr) + (offset))) 22 #define structmember(ptr, type, offset) \ 23 (*structptr(ptr, type, offset)) 24 25 #undef uchar 26 #undef ushort 27 #undef uint 28 #undef ulong 29 #undef uvlong 30 #undef vlong 31 #define uchar _x_uchar 32 #define ushort _x_ushort 33 #define uint _x_uint 34 #define ulong _x_ulong 35 #define uvlong _x_uvlong 36 #define vlong _x_vlong 37 38 typedef unsigned char uchar; 39 typedef unsigned short ushort; 40 typedef unsigned int uint; 41 typedef unsigned long ulong; 42 typedef unsigned long long uvlong; 43 typedef long long vlong; 44 45 #define BLOCK(x) do { x; }while(0) 46 47 static inline void 48 _used(long a, ...) { 49 if(a){} 50 } 51 #ifndef KENC 52 # undef USED 53 # undef SET 54 # define USED(...) _used((long)__VA_ARGS__) 55 # define SET(x) (x = 0) 56 /* # define SET(x) USED(&x) GCC 4 is 'too smart' for this. */ 57 #endif