diff options
Diffstat (limited to 'lib/exceptions.c')
-rw-r--r-- | lib/exceptions.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/exceptions.c b/lib/exceptions.c new file mode 100644 index 0000000..349e8a9 --- /dev/null +++ b/lib/exceptions.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "config.h" +#include "exceptions.h" + +char * Estrdup(char * o) { + char * r; + + if (!(r = strdup(o))) { + exception(1, _("Out of memory.")); + } + return r; +} + +void * Emalloc(size_t s) { + void * r; + + if (!(r = malloc(s))) { + exception(1, _("Out of memory.")); + } + return r; +} + +void exception(int level, char *msg) +{ + fprintf(stderr, "%s\n", msg); + exit(level); +} |