X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Flib.h;h=99b848e348c4d1cd0ce3aa1cab85d2f20d3bf9ee;hb=bcd1c2df2198ba426455e7fdeba7dea0e0c8e0cf;hp=43a777e227e94037bdd09da721c7e141bd2c8ece;hpb=031256ad2e123eec58521f8e3eb9496c197641d2;p=libucw.git diff --git a/ucw/lib.h b/ucw/lib.h index 43a777e2..99b848e3 100644 --- a/ucw/lib.h +++ b/ucw/lib.h @@ -20,7 +20,7 @@ #define CHECK_PTR_TYPE(x, type) ((x)-(type)(x) + (type)(x)) #define PTR_TO(s, i) &((s*)0)->i -#define OFFSETOF(s, i) ((unsigned int) PTR_TO(s, i)) +#define OFFSETOF(s, i) ((unsigned int) (uintptr_t) PTR_TO(s, i)) #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) #define ALIGN_TO(s, a) (((s)+a-1)&~(a-1)) #define ALIGN_PTR(p, s) ((uintptr_t)(p) % (s) ? (typeof(p))((uintptr_t)(p) + (s) - (uintptr_t)(p) % (s)) : (p)) @@ -43,7 +43,8 @@ #define COMPARE_LT(x,y) do { if ((x)<(y)) return 1; if ((x)>(y)) return 0; } while(0) #define COMPARE_GT(x,y) COMPARE_LT(y,x) -#define ROL(x, bits) (((x) << (bits)) | ((x) >> (sizeof(uns)*8 - (bits)))) /* Bitwise rotation of an uns to the left */ +#define ROL(x, bits) (((x) << (bits)) | ((uns)(x) >> (sizeof(uns)*8 - (bits)))) /* Bitwise rotation of an uns to the left */ +#define ROR(x, bits) (((uns)(x) >> (bits)) | ((x) << (sizeof(uns)*8 - (bits)))) /* GCC Extensions */ @@ -132,22 +133,10 @@ void assert_failed_noinfo(void) NONRET; /* Memory allocation */ -#define xmalloc sh_xmalloc -#define xrealloc sh_xrealloc -#define xfree sh_xfree +#define xmalloc ucw_xmalloc +#define xrealloc ucw_xrealloc +#define xfree ucw_xfree -#ifdef DEBUG_DMALLOC -/* - * The standard dmalloc macros tend to produce lots of namespace - * conflicts and we use only xmalloc and xfree, so we can define - * the stubs ourselves. - */ -#define DMALLOC_DISABLE -#include -#define sh_xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size) -#define sh_xrealloc(ptr,size) _xrealloc_leap(__FILE__, __LINE__, ptr, size) -#define sh_xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr) -#else /* * Unfortunately, several libraries we might want to link to define * their own xmalloc and we don't want to interfere with them, hence @@ -156,32 +145,17 @@ void assert_failed_noinfo(void) NONRET; void *xmalloc(uns) LIKE_MALLOC; void *xrealloc(void *, uns); void xfree(void *); -#endif void *xmalloc_zero(uns) LIKE_MALLOC; char *xstrdup(const char *) LIKE_MALLOC; -/* Content-Type pattern matching and filters */ - -int match_ct_patt(const char *, const char *); - -/* prime.c */ - -int isprime(uns x); -uns nextprime(uns x); - -/* primetable.c */ - -uns next_table_prime(uns x); -uns prev_table_prime(uns x); - /* timer.c */ timestamp_t get_timestamp(void); void init_timer(timestamp_t *timer); uns get_timer(timestamp_t *timer); -uns switch_timer(timestamp_t *old, timestamp_t *new); +uns switch_timer(timestamp_t *oldt, timestamp_t *newt); /* random.c */ @@ -230,11 +204,11 @@ void sync_dir(const char *name); /* sighandler.c */ -typedef int (*sh_sighandler_t)(int); // gets signum, returns nonzero if abort() should be called +typedef int (*ucw_sighandler_t)(int); // gets signum, returns nonzero if abort() should be called void handle_signal(int signum); void unhandle_signal(int signum); -sh_sighandler_t set_signal_handler(int signum, sh_sighandler_t new); +ucw_sighandler_t set_signal_handler(int signum, ucw_sighandler_t newh); /* bigalloc.c */