summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-11-09 19:25:33 +0000
committermillert <millert@openbsd.org>1999-11-09 19:25:33 +0000
commit19951a96a997f3a9bd276d340496b1457130e599 (patch)
tree40f00a13b29c90f2d4566c0850235ec6bec3ccfe /lib/libc/stdlib/malloc.c
parentremove really lame bug espie created; ca@zardoc.endmail.org (diff)
downloadwireguard-openbsd-19951a96a997f3a9bd276d340496b1457130e599.tar.xz
wireguard-openbsd-19951a96a997f3a9bd276d340496b1457130e599.zip
Move calloc() into malloc.c and only zero out the area if malloc()
didn't do so for us. By default, malloc() zeros out the space it allocates but the programmer cannot rely on this as it is implementation- specific (and configurable via /etc/malloc.conf)
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 8b90bb5d57b..3582d7980cc 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -8,7 +8,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: malloc.c,v 1.36 1999/09/16 19:06:06 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: malloc.c,v 1.37 1999/11/09 19:25:33 millert Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -1278,3 +1278,27 @@ realloc(void *ptr, size_t size)
wrterror("out of memory.\n");
return (r);
}
+
+void *
+calloc(size_t num, size_t size)
+{
+ register void *r;
+
+ malloc_func = " in calloc():";
+ THREAD_LOCK();
+ if (malloc_active++) {
+ wrtwarning("recursive call.\n");
+ malloc_active--;
+ return (0);
+ }
+ size *= num;
+ r = imalloc(size);
+ if (r && !malloc_zero)
+ memset(r, 0, size)
+ UTRACE(0, size, r);
+ malloc_active--;
+ THREAD_UNLOCK();
+ if (malloc_xmalloc && !r)
+ wrterror("out of memory.\n");
+ return (r);
+}