ACPI AML decompiler w/ CFG recovery and structured pseudocode
29

Configure Feed

Select the types of activity you want to include in your feed.

tobi / src / mem.c
1.1 kB 58 lines
1#include "mem.h" 2 3#include <stdint.h> 4#include <stdio.h> 5#include <stdlib.h> 6#include <string.h> 7 8#ifdef TOBI_SAN_BUILD 9const char *__asan_default_options(void) { 10 return "detect_leaks=0:abort_on_error=1"; 11} 12#endif 13 14static void oom(void) { 15 fputs("tobi: out of memory\n", stderr); 16 abort(); 17} 18 19void *tobi_xmalloc(size_t n) { 20 void *p = malloc(n == 0 ? 1 : n); 21 if (!p) { 22 oom(); 23 } 24 return p; 25} 26 27void *tobi_xcalloc(size_t count, size_t size) { 28 if (size != 0 && count > SIZE_MAX / size) { 29 oom(); 30 } 31 void *p = calloc(count == 0 ? 1 : count, size == 0 ? 1 : size); 32 if (!p) { 33 oom(); 34 } 35 return p; 36} 37 38void *tobi_xrealloc(void *ptr, size_t n) { 39 void *p = realloc(ptr, n == 0 ? 1 : n); 40 if (!p) { 41 oom(); 42 } 43 return p; 44} 45 46char *tobi_xstrdup(const char *s) { 47 size_t n = strlen(s); 48 char *out = tobi_xmalloc(n + 1); 49 memcpy(out, s, n + 1); 50 return out; 51} 52 53char *tobi_xstrndup(const char *s, size_t n) { 54 char *out = tobi_xmalloc(n + 1); 55 memcpy(out, s, n); 56 out[n] = '\0'; 57 return out; 58}