00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include "debug.h"
00042 #include "xalloc.h"
00043
00044
00045 void *xcalloc(size_t nmemb, size_t size)
00046 {
00047 void *res = calloc(nmemb, size);
00048 if (!res) RUNTIME_ERROR("calloc failed.");
00049 return res;
00050 }
00051
00052
00053 void *xmalloc(size_t size)
00054 {
00055 void *res = malloc(size);
00056 if (!res) RUNTIME_ERROR("malloc failed.");
00057 return res;
00058 }
00059
00060 void xfree(void **ptr)
00061 {
00062 free(*ptr);
00063 *ptr = NULL;
00064 }
00065
00066 void *xrealloc(void *ptr, size_t size)
00067 {
00068 void *res = realloc(ptr, size);
00069 if (!res) RUNTIME_ERROR("realloc failed.");
00070 return res;
00071 }
00072
00073
00074 char *xstrdup(const char *s)
00075 {
00076 char *res = (char*) strdup(s);
00077 if (!res) RUNTIME_ERROR("realloc failed.");
00078 return res;
00079 }