diff options
Diffstat (limited to 'src/shared.h')
| -rw-r--r-- | src/shared.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/shared.h b/src/shared.h index b7fe7c3..1a629e6 100644 --- a/src/shared.h +++ b/src/shared.h | |||
| @@ -50,4 +50,36 @@ int wwbuf(int fd, const unsigned char *buf, int len); | |||
| 50 | // `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits/aborts on alloc error. | 50 | // `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits/aborts on alloc error. |
| 51 | char * xdirname(const char * const path); | 51 | char * xdirname(const char * const path); |
| 52 | 52 | ||
| 53 | |||
| 54 | |||
| 55 | // Cleanup callback. Should act like `free()`, in that it doesn't crash if the pointer it's given is null | ||
| 56 | typedef void (*cleanup_callback)(void*); | ||
| 57 | |||
| 58 | // Cleanup struct. Stores a STATICALLY defined array of callbacks and void* arguments | ||
| 59 | typedef struct cl { | ||
| 60 | cleanup_callback *funcs; | ||
| 61 | void **args; | ||
| 62 | |||
| 63 | int size; | ||
| 64 | int used; | ||
| 65 | } cleanup; | ||
| 66 | |||
| 67 | int cleanup_init(cleanup * const loc, int size, cleanup_callback funcs[], void *args[]); | ||
| 68 | int cleanup_register(cleanup * const loc, cleanup_callback cb, void *arg); | ||
| 69 | int cleanup_cndregister(cleanup * const loc, unsigned char flag, cleanup_callback cb, void *arg); | ||
| 70 | int cleanup_clear(cleanup * const loc); | ||
| 71 | cleanup_callback cleanup_peekf(cleanup * const loc); | ||
| 72 | cleanup_callback cleanup_popf(cleanup * const loc); | ||
| 73 | void * cleanup_peeka(cleanup * const loc); | ||
| 74 | void * cleanup_popa(cleanup * const loc); | ||
| 75 | int cleanup_fire(cleanup * const loc); | ||
| 76 | |||
| 77 | /* Cleanup environment creator. Automatically defines the variables `__CLEANUP`, `__CLEANUP_FUNCS`, and `__CLEANUP_ARGS` and initializes | ||
| 78 | // via `cleanup_init()` using these variables. */ | ||
| 79 | #define cleanup_create(size) \ | ||
| 80 | cleanup __CLEANUP; \ | ||
| 81 | cleanup_callback __CLEANUP_FUNCS[(size)]; \ | ||
| 82 | void *__CLEANUP_ARGS[(size)]; \ | ||
| 83 | cleanup_init(&__CLEANUP, (size), __CLEANUP_FUNCS, __CLEANUP_ARGS) | ||
| 84 | |||
| 53 | #endif \ No newline at end of file | 85 | #endif \ No newline at end of file |
