diff options
Diffstat (limited to 'src/shared.h')
| -rw-r--r-- | src/shared.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/shared.h b/src/shared.h index ac214f7..fef19ca 100644 --- a/src/shared.h +++ b/src/shared.h | |||
| @@ -2,13 +2,23 @@ | |||
| 2 | #define __VXGG_REWRITE___SHARED_H___3880294315821___ | 2 | #define __VXGG_REWRITE___SHARED_H___3880294315821___ |
| 3 | 3 | ||
| 4 | #include <stddef.h> | 4 | #include <stddef.h> |
| 5 | #include <stdarg.h> | ||
| 5 | 6 | ||
| 6 | // Defines how `xcalloc()` should exit. `___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions registered with | 7 | // Defines how `x___alloc()` functions should exit. `___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions |
| 7 | // `atexit()` and `on_exit()`. `___VXGG___XCALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `xcalloc()` will ALWAYS 'abort', | 8 | // registered with `atexit()` and `on_exit()`. `___VXGG___XCALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `xcalloc()` |
| 8 | // doing otherwise defeats the purpose of the function | 9 | // will ALWAYS 'abort', doing otherwise defeats the purpose of the function |
| 9 | #define ___VXGG___XCALLOC_EXIT_ON_ERROR___ 1 | 10 | #define ___VXGG___XCALLOC_EXIT_ON_ERROR___ 1 |
| 10 | 11 | ||
| 11 | // `calloc()` with error checking. Calls `error()` or `abort()` on error depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___` | 12 | // `calloc()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___` |
| 12 | void* xcalloc(size_t nmemb, size_t size); | 13 | void* xcalloc(size_t nmemb, size_t size); |
| 13 | 14 | ||
| 15 | // `reallocarray()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___` | ||
| 16 | void* xreallocarray(void *ptr, size_t nmemb, size_t size); | ||
| 17 | |||
| 18 | // `vsprintf()`, but reallocates enough room for the resulting string before writing to `str` | ||
| 19 | int vsaprintf(char **str, const char *format, va_list ap); | ||
| 20 | |||
| 21 | // `sprintf()`, but reallocates enough room for the resulting string before writing to `str` | ||
| 22 | int saprintf(char **str, const char *format, ...); | ||
| 23 | |||
| 14 | #endif \ No newline at end of file | 24 | #endif \ No newline at end of file |
