diff options
Diffstat (limited to 'src/memory.c')
-rw-r--r-- | src/memory.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/memory.c b/src/memory.c index 037807a..e73b87e 100644 --- a/src/memory.c +++ b/src/memory.c @@ -66,11 +66,30 @@ MyFree(void *x) free(x); } -void -_DupString(char **x, const char *y) +void * +xstrdup(const char *s) +{ + void *ret = malloc(strlen(s) + 1); + + if (ret == NULL) + outofmemory(); + + strcpy(ret, s); + + return ret; +} + +void * +xstrndup(const char *s, size_t len) { - (*x) = malloc(strlen(y) + 1); - strcpy((*x), y); + void *ret = malloc(len + 1); + + if (ret == NULL) + outofmemory(); + + strlcpy(ret, s, len + 1); + + return ret; } /* outofmemory() |