summaryrefslogtreecommitdiff
path: root/src/shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared.c')
-rw-r--r--src/shared.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/shared.c b/src/shared.c
index 1dd0309..5e425f0 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -12,6 +12,30 @@
12#ifndef __VXGG_REWRITE___SHARED_C___3880294315821___ 12#ifndef __VXGG_REWRITE___SHARED_C___3880294315821___
13#define __VXGG_REWRITE___SHARED_C___3880294315821___ 1 13#define __VXGG_REWRITE___SHARED_C___3880294315821___ 1
14 14
15#include <stdlib.h>
16#include <string.h>
17#include <unistd.h>
18#include <errno.h>
19#include <error.h>
20
21
22#define VXGG_MALLOC(size) malloc((size))
23#define VXGG_CALLOC(nmemb, size) calloc((nmemb), (size))
24#ifdef DEBUG
25#undef VXGG_MALLOC
26#undef VXGG_CALLOC
27
28void* VXGG_ALLOC(size_t size) {
29 void *mem = malloc(size);
30 if(!mem) return NULL;
31 memset(mem, 0x57, size); // VX -> {21, 23} % 16 -> 0x57
32 return mem;
33}
34
35#define VXGG_MALLOC(size) VXGG_ALLOC((size))
36#define VXGG_CALLOC(nmemb, size) VXGG_ALLOC((nmemb) * (size))
37#endif
38
15#define STATIC_ARRAY_LEN(arr) (sizeof((arr))/sizeof((arr)[0])) 39#define STATIC_ARRAY_LEN(arr) (sizeof((arr))/sizeof((arr)[0]))
16 40
17#define ERRRET(errval, retval) do {\ 41#define ERRRET(errval, retval) do {\
@@ -40,17 +64,11 @@
40#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0) 64#define ERROR(status, errnum, format, ...) do {error((status), (errnum), (format)__VA_ARGS__); exit((status));} while (0)
41//! Spit out a warning using `error` 65//! Spit out a warning using `error`
42#define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0) 66#define WARN(errnum, format, ...) do {error(0, (errnum), (format)__VA_ARGS__);} while (0)
43 67// TODO: gcc is yelling at me about these functions implicitly falling through. Not sure why
44 68
45typedef int (*gcallback)(void*); //!< Generic callback signature 69typedef int (*gcallback)(void*); //!< Generic callback signature
46typedef void (*fcallback)(void*); //!< free()-like callback signature 70typedef void (*fcallback)(void*); //!< free()-like callback signature
47 71
48#include <stdlib.h>
49#include <string.h>
50#include <unistd.h>
51#include <errno.h>
52#include <error.h>
53
54/** 72/**
55 * @brief Read the entire contents of a file descriptor into a malloc()'ed buffer 73 * @brief Read the entire contents of a file descriptor into a malloc()'ed buffer
56 * 74 *