aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-08-01 14:03:21 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-08-01 14:03:21 -0700
commit7602ec169ae0464a73cb3a5b4b1eefbbfae43057 (patch)
treefccf7daa214a9a4fd25b757e1c9e0a4e2135b5f5 /com32
parentd721352927d7743d3e18dfd72e2a60d729377c8b (diff)
downloadsyslinux-elf-7602ec169ae0464a73cb3a5b4b1eefbbfae43057.tar.gz
syslinux-elf-7602ec169ae0464a73cb3a5b4b1eefbbfae43057.tar.xz
syslinux-elf-7602ec169ae0464a73cb3a5b4b1eefbbfae43057.zip
com32/lib: add zalloc()
Add the nonstandard, but often useful, zalloc() function. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32')
-rw-r--r--com32/include/stdlib.h1
-rw-r--r--com32/lib/Makefile2
-rw-r--r--com32/lib/calloc.c9
-rw-r--r--com32/lib/zalloc.c17
4 files changed, 20 insertions, 9 deletions
diff --git a/com32/include/stdlib.h b/com32/include/stdlib.h
index be4e76ed..e0fe7e39 100644
--- a/com32/include/stdlib.h
+++ b/com32/include/stdlib.h
@@ -37,6 +37,7 @@ static __inline__ long long llabs(long long __n) {
}
__extern __mallocfunc void *malloc(size_t);
+__extern __mallocfunc void *zalloc(size_t);
__extern __mallocfunc void *calloc(size_t, size_t);
__extern __mallocfunc void *realloc(void *, size_t);
__extern long strtol(const char *, char **, int);
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 74f3d7ee..c2b4e3d2 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -19,7 +19,7 @@ LIBOBJS = \
strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o \
strtoumax.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o \
asprintf.o vasprintf.o strlcpy.o strlcat.o \
- vsscanf.o \
+ vsscanf.o zalloc.o \
\
libgcc/__ashldi3.o libgcc/__udivdi3.o \
libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o \
diff --git a/com32/lib/calloc.c b/com32/lib/calloc.c
index ebab49bf..97659b16 100644
--- a/com32/lib/calloc.c
+++ b/com32/lib/calloc.c
@@ -9,12 +9,5 @@
void *calloc(size_t nmemb, size_t size)
{
- void *ptr;
-
- size *= nmemb;
- ptr = malloc(size);
- if ( ptr )
- memset(ptr, 0, size);
-
- return ptr;
+ return zalloc(size*nmemb);
}
diff --git a/com32/lib/zalloc.c b/com32/lib/zalloc.c
new file mode 100644
index 00000000..2a58a11e
--- /dev/null
+++ b/com32/lib/zalloc.c
@@ -0,0 +1,17 @@
+/*
+ * zalloc.c
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+void *zalloc(size_t size)
+{
+ void *ptr;
+
+ ptr = malloc(size);
+ if ( ptr )
+ memset(ptr, 0, size);
+
+ return ptr;
+}