version 1.11, 2001/02/04 15:32:27 |
version 1.12, 2001/02/07 08:57:26 |
|
|
void * |
void * |
xmalloc(size_t size) |
xmalloc(size_t size) |
{ |
{ |
void *ptr = malloc(size); |
void *ptr; |
|
|
|
if (size == 0) |
|
fatal("xmalloc: zero size"); |
|
ptr = malloc(size); |
if (ptr == NULL) |
if (ptr == NULL) |
fatal("xmalloc: out of memory (allocating %d bytes)", (int) size); |
fatal("xmalloc: out of memory (allocating %d bytes)", (int) size); |
return ptr; |
return ptr; |
|
|
{ |
{ |
void *new_ptr; |
void *new_ptr; |
|
|
|
if (new_size == 0) |
|
fatal("xmalloc: zero size"); |
if (ptr == NULL) |
if (ptr == NULL) |
fatal("xrealloc: NULL pointer given as argument"); |
fatal("xrealloc: NULL pointer given as argument"); |
new_ptr = realloc(ptr, new_size); |
new_ptr = realloc(ptr, new_size); |
|
|
xstrdup(const char *str) |
xstrdup(const char *str) |
{ |
{ |
size_t len = strlen(str) + 1; |
size_t len = strlen(str) + 1; |
|
char *cp; |
|
|
char *cp = xmalloc(len); |
if (len == 0) |
|
fatal("xmalloc: zero size"); |
|
cp = xmalloc(len); |
strlcpy(cp, str, len); |
strlcpy(cp, str, len); |
return cp; |
return cp; |
} |
} |