libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / hotplug2 / mem_utils.c
blobdb2b0ff5b7d640293391535048eefd0377c1559e
1 /*****************************************************************************\
2 * _ _ _ _ ___ *
3 * | || | ___ | |_ _ __ | | _ _ __ _ |_ ) *
4 * | __ |/ _ \| _|| '_ \| || || |/ _` | / / *
5 * |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___| *
6 * |_| |___/ *
7 \*****************************************************************************/
9 #include <stdlib.h>
10 #include <stdio.h>
12 /**
13 * A malloc wrapper. Exits if no memory.
15 * @1 Ammount of memory to allocate
17 * Returns: Pointer to freshly allocated memory
19 inline void *xmalloc(size_t size) {
20 void *ptr;
21 ptr = malloc(size);
22 if (ptr == NULL) {
23 fprintf(stderr, "MALLOC FAILURE!\n");
24 exit(127);
26 return ptr;
29 /**
30 * A realloc wrapper. Exits if no memory.
32 * @1 Old pointer
33 * @2 Ammount of memory to allocate
35 * Returns: Pointer to reallocated memory
37 inline void *xrealloc(void *inptr, size_t size) {
38 void *ptr;
39 ptr = realloc(inptr, size);
40 if (ptr == NULL) {
41 fprintf(stderr, "MALLOC FAILURE!\n");
42 exit(127);
44 return ptr;