version 1.3, 1999/09/30 04:30:03 |
version 1.4, 1999/11/23 22:25:56 |
|
|
|
|
#include "ssh.h" |
#include "ssh.h" |
|
|
void *xmalloc(size_t size) |
void * |
|
xmalloc(size_t size) |
{ |
{ |
void *ptr = malloc(size); |
void *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 *xrealloc(void *ptr, size_t new_size) |
void * |
|
xrealloc(void *ptr, size_t new_size) |
{ |
{ |
void *new_ptr; |
void *new_ptr; |
|
|
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); |
if (new_ptr == NULL) |
if (new_ptr == NULL) |
fatal("xrealloc: out of memory (new_size %d bytes)", (int)new_size); |
fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size); |
return new_ptr; |
return new_ptr; |
} |
} |
|
|
void xfree(void *ptr) |
void |
|
xfree(void *ptr) |
{ |
{ |
if (ptr == NULL) |
if (ptr == NULL) |
fatal("xfree: NULL pointer given as argument"); |
fatal("xfree: NULL pointer given as argument"); |
free(ptr); |
free(ptr); |
} |
} |
|
|
char *xstrdup(const char *str) |
char * |
|
xstrdup(const char *str) |
{ |
{ |
int len = strlen(str) + 1; |
int len = strlen(str) + 1; |
|
|
char *cp = xmalloc(len); |
char *cp = xmalloc(len); |
strlcpy(cp, str, len); |
strlcpy(cp, str, len); |
return cp; |
return cp; |
} |
} |