summaryrefslogtreecommitdiff
path: root/src/shared.h
blob: 5894b41316e9a4794f018d79d6a581fcd3176683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef __VXGG_REWRITE___SHARED_H___3880294315821___
#define __VXGG_REWRITE___SHARED_H___3880294315821___

#include <stddef.h>
#include <stdarg.h>

#define STATICARR_SIZE(arr) (sizeof((arr))/sizeof((arr)[0]))

// Defines how `x___alloc()` functions should exit. `___VXGG___XALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions
// registered with `atexit()` and `on_exit()`. `___VXGG___XALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `x___alloc()` 
// type functions will ALWAYS 'abort', doing otherwise defeats the purpose of the function type
#define ___VXGG___XALLOC_EXIT_ON_ERROR___ 1

// `calloc()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
void* xcalloc(size_t nmemb, size_t size);

// `reallocarray()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
void* xreallocarray(void *ptr, size_t nmemb, size_t size);

#if !defined _GNU_SOURCE
int vasprintf(char **str, const char *format, va_list ap);
int asprintf(char **str, const char *format, ...);
#endif

#endif