aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-12-31 07:13:17 -0500
committerMike Frysinger <vapier@gentoo.org>2008-12-31 09:52:26 -0500
commitc9f9ef7dc32c851b44f51b67912cf2d9a48b108f (patch)
tree4dc4420892900cd2799918055ccd517fb28eb039 /libsandbox/memory.c
parentlibsandbox/libsbutil: link with -no-undefined (diff)
downloadsandbox-c9f9ef7dc32c851b44f51b67912cf2d9a48b108f.tar.gz
sandbox-c9f9ef7dc32c851b44f51b67912cf2d9a48b108f.tar.bz2
sandbox-c9f9ef7dc32c851b44f51b67912cf2d9a48b108f.zip
libsbutil: cleanup x* memory functions
Pull the x* memory functions out of rcscripts and into libsbutil and change their style to match the rest of sbutil. Also add xzalloc() and xstrdup(), and convert pointless strndup() usage to strdup(). Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/memory.c')
-rw-r--r--libsandbox/memory.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/libsandbox/memory.c b/libsandbox/memory.c
index cd208dd..d6f4b00 100644
--- a/libsandbox/memory.c
+++ b/libsandbox/memory.c
@@ -44,13 +44,7 @@ void free(void *ptr)
void *calloc(size_t nmemb, size_t size)
{
- void *ret;
- size_t malloc_size = nmemb * size;
- ret = malloc(malloc_size); /* dont care about overflow */
- if (ret == NULL)
- return NULL;
- memset(ret, 0x00, malloc_size);
- return ret;
+ return xzalloc(nmemb * size); /* dont care about overflow */
}
void *realloc(void *ptr, size_t size)
@@ -59,16 +53,14 @@ void *realloc(void *ptr, size_t size)
size_t old_malloc_size;
if (ptr == NULL)
- return malloc(size);
+ return xmalloc(size);
if (size == 0) {
free(ptr);
return ptr;
}
old_malloc_size = SB_MALLOC_TO_SIZE(ptr);
- ret = malloc(size);
- if (ret == NULL)
- return NULL;
+ ret = xmalloc(size);
memcpy(ret, ptr, MIN(size, old_malloc_size));
free(ptr);
return ret;
@@ -83,8 +75,6 @@ char *strdup(const char *s)
return NULL;
len = strlen(s);
- ret = malloc(len + 1);
- if (ret == NULL)
- return NULL;
+ ret = xmalloc(len + 1);
return memcpy(ret, s, len + 1);
}