6 /* Portability definitions. */
11 #define sleep(seconds) Sleep((seconds) * 1000)
12 #define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), (b));
13 #define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), -(b));
15 /* MinGW gcc, no function prototype for built-in function stpcpy() */
16 char *stpcpy (char *dest
, const char *src
);
19 static inline const char *
20 strcasestr(const char *haystack
, const char *needle
)
22 for (const char *p
= haystack
; *p
; p
++) {
23 for (int ni
= 0; needle
[ni
]; ni
++) {
26 if (toupper(p
[ni
]) != toupper(needle
[ni
]))
36 /* Misc. definitions. */
38 /* Use make DOUBLE=1 in large configurations with counts > 1M
39 * where 24 bits of floating_t mantissa become insufficient. */
41 # define floating_t double
42 # define PRIfloating "%lf"
44 # define floating_t float
45 # define PRIfloating "%f"
48 #define likely(x) __builtin_expect(!!(x), 1)
49 #define unlikely(x) __builtin_expect((x), 0)
52 checked_malloc(size_t size
, char *filename
, unsigned int line
, const char *func
)
54 void *p
= malloc(size
);
56 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY malloc(%zu)\n",
57 filename
, line
, func
, size
);
64 checked_calloc(size_t nmemb
, size_t size
, char *filename
, unsigned int line
, const char *func
)
66 void *p
= calloc(nmemb
, size
);
68 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY calloc(%zu, %zu)\n",
69 filename
, line
, func
, nmemb
, size
);
75 #define malloc2(size) checked_malloc((size), __FILE__, __LINE__, __func__)
76 #define calloc2(nmemb, size) checked_calloc((nmemb), (size), __FILE__, __LINE__, __func__)