81047ca13f32ea1a3b1c815fc198f501c84ec723
[deeprace] / src / util.h
1 #ifndef UTIL_H_
2 #define UTIL_H_
3
4 #include <stdlib.h>
5
6 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
7 #include <malloc.h>
8 #else
9 #include <alloca.h>
10 #endif
11
12 /* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
13  * demo_abort on failure. Use the macros, don't call the *_impl functions.
14  */
15 #define malloc_nf(sz)   malloc_nf_impl(sz, __FILE__, __LINE__)
16 void *malloc_nf_impl(size_t sz, const char *file, int line);
17 #define calloc_nf(n, sz)        calloc_nf_impl(n, sz, __FILE__, __LINE__)
18 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line);
19 #define realloc_nf(p, sz)       realloc_nf_impl(p, sz, __FILE__, __LINE__)
20 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line);
21 #define strdup_nf(s)    strdup_nf_impl(s, __FILE__, __LINE__)
22 char *strdup_nf_impl(const char *s, const char *file, int line);
23
24 #endif  /* UTIL_H_ */