Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
fmalloc.c
Go to the documentation of this file.00001 #ifdef HAVE_CONFIG_H
00002 # include "config.h"
00003 #endif
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010
00011 static void
00012 fail_die_malloc_die(size_t size, const char *file, int line)
00013 {
00014 fprintf(stderr, "Out of memory! (wanted %lu at %s:%d)\n",
00015 (unsigned long)size, file, line);
00016 exit(1);
00017 }
00018
00019 void *
00020 fail_die_malloc(size_t size, const char *file, int line)
00021 {
00022 void *p = malloc(size);
00023 if (!p && size)
00024 fail_die_malloc_die(size, file, line);
00025 return p;
00026 }
00027
00028 void *
00029 fail_die_realloc(void *p, size_t size, const char *file, int line)
00030 {
00031 if (!p)
00032 return fail_die_malloc(size, file, line);
00033 p = realloc(p, size);
00034 if (!p && size)
00035 fail_die_malloc_die(size, file, line);
00036 return p;
00037 }
00038
00039 #ifdef __cplusplus
00040 }
00041 #endif