diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:11:51 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:11:51 +0100 |
| commit | b7a82c980fe7e0c1f9029b55be97422428d65d5a (patch) | |
| tree | 67bedc856eb1f72a2daa8ef8347b904269b06df5 /src/util/emalloc.h | |
| parent | vu-crop: add -t (diff) | |
| download | blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.gz blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.bz2 blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.xz | |
Clean up code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util/emalloc.h')
| -rw-r--r-- | src/util/emalloc.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/emalloc.h b/src/util/emalloc.h new file mode 100644 index 0000000..7c4266e --- /dev/null +++ b/src/util/emalloc.h @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdlib.h> + +#define emalloc(...) enmalloc(1, __VA_ARGS__) +#define ecalloc(...) encalloc(1, __VA_ARGS__) + +static inline void * +enmalloc(int status, size_t n) +{ + void *ptr = malloc(n); + if (!ptr) + enprintf(status, "malloc: out of memory\n"); + return ptr; +} + +static inline void * +encalloc(int status, size_t n, size_t m) +{ + void *ptr = calloc(n, m); + if (!ptr) + enprintf(status, "malloc: out of memory\n"); + return ptr; +} |
