summaryrefslogtreecommitdiff
path: root/src/shared.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared.h')
-rw-r--r--src/shared.h26
1 files changed, 5 insertions, 21 deletions
diff --git a/src/shared.h b/src/shared.h
index 0b401fe..efb95ad 100644
--- a/src/shared.h
+++ b/src/shared.h
@@ -32,26 +32,19 @@ typedef void (*fcallback)(void*); // free()-like callback signature
32 exit(EXIT_FAILURE); /* Makes gcc happy */\ 32 exit(EXIT_FAILURE); /* Makes gcc happy */\
33} while (0) 33} while (0)
34 34
35// Whether to use `XALLOC` or normal `malloc` functions for acquiring new memory via the `VALLOC()` macro. `> 0` 35
36// enables XALLOC functionality 36#define VALLOC(nmemb, size) malloc((nmemb) * (size))
37#define ___VXGG___USE_XALLOC_FOR_VALLOC___ 0
38#define VALLOC(nmemb, size) ((___VXGG___USE_XALLOC_FOR_VALLOC___ > 0) ? xmalloc((nmemb) * (size)) : malloc((nmemb) * (size)))
39 37
40// Error macro that gcc will not complain about 38// Error macro that gcc will not complain about
41#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0) 39#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0)
40#define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0)
42 41
43// `malloc()` with error checking. Calls `exit()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
44void * xmalloc(size_t size);
45// `calloc()` with error checking. Calls `exit()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
46void * xcalloc(size_t nmemb, size_t size);
47// `reallocarray()` with error checking. Calls `exit()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
48void * xreallocarray(void *ptr, size_t nmemb, size_t size);
49// Read the entire contents of a file descriptor into a malloc()'ed buffer 42// Read the entire contents of a file descriptor into a malloc()'ed buffer
50int rwbuf(char **str, unsigned long int initsize, int fd); 43int rwbuf(char **str, unsigned long int initsize, int fd);
51// Write the entire contents of a buffer into a file descriptor 44// Write the entire contents of a buffer into a file descriptor
52int wwbuf(int fd, const unsigned char *buf, int len); 45int wwbuf(int fd, const unsigned char *buf, int len);
53// `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits/aborts on alloc error. 46// `dirname()` reimplementation that returns a malloc()'ed string
54char * xdirname(const char * const path); 47char * vxdirname(const char * const path);
55 48
56 49
57 50
@@ -87,13 +80,4 @@ cleanup_init(&__CLEANUP, __CLEANUP_FUNCS, __CLEANUP_ARGS, (size))
87#define cleanup_ERRORFLAGGED (__FLAG != 0) 80#define cleanup_ERRORFLAGGED (__FLAG != 0)
88#define cleanup_CNDEXEC(code) while(!cleanup_ERRORFLAGGED) {code; break;} 81#define cleanup_CNDEXEC(code) while(!cleanup_ERRORFLAGGED) {code; break;}
89 82
90
91
92// Generic task to be executed by a consumer
93typedef struct task task;
94// A queue of tasks
95typedef struct taskqueue taskqueue;
96// A concurrent queue of tasks, basically a threadpool tasks can be dispatched to
97typedef struct ctqueue ctqueue;
98
99#endif \ No newline at end of file 83#endif \ No newline at end of file