diff options
author | millert <> | 1999-11-09 19:25:33 +0000 |
---|---|---|
committer | millert <> | 1999-11-09 19:25:33 +0000 |
commit | 5d55745080b705a4223d109d1dbbd95cf1072a73 (patch) | |
tree | 358f23b9e3de9b2efb9df202c8cbba230073c891 /src/lib/libc/stdlib/malloc.c | |
parent | c3c518ea633f6a6753cac521b770066c6f7cc498 (diff) | |
download | openbsd-5d55745080b705a4223d109d1dbbd95cf1072a73.tar.gz openbsd-5d55745080b705a4223d109d1dbbd95cf1072a73.tar.bz2 openbsd-5d55745080b705a4223d109d1dbbd95cf1072a73.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 'src/lib/libc/stdlib/malloc.c')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 8b90bb5d57..3582d7980c 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -8,7 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #if defined(LIBC_SCCS) && !defined(lint) | 10 | #if defined(LIBC_SCCS) && !defined(lint) |
11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.36 1999/09/16 19:06:06 deraadt Exp $"; | 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.37 1999/11/09 19:25:33 millert Exp $"; |
12 | #endif /* LIBC_SCCS and not lint */ | 12 | #endif /* LIBC_SCCS and not lint */ |
13 | 13 | ||
14 | /* | 14 | /* |
@@ -1278,3 +1278,27 @@ realloc(void *ptr, size_t size) | |||
1278 | wrterror("out of memory.\n"); | 1278 | wrterror("out of memory.\n"); |
1279 | return (r); | 1279 | return (r); |
1280 | } | 1280 | } |
1281 | |||
1282 | void * | ||
1283 | calloc(size_t num, size_t size) | ||
1284 | { | ||
1285 | register void *r; | ||
1286 | |||
1287 | malloc_func = " in calloc():"; | ||
1288 | THREAD_LOCK(); | ||
1289 | if (malloc_active++) { | ||
1290 | wrtwarning("recursive call.\n"); | ||
1291 | malloc_active--; | ||
1292 | return (0); | ||
1293 | } | ||
1294 | size *= num; | ||
1295 | r = imalloc(size); | ||
1296 | if (r && !malloc_zero) | ||
1297 | memset(r, 0, size) | ||
1298 | UTRACE(0, size, r); | ||
1299 | malloc_active--; | ||
1300 | THREAD_UNLOCK(); | ||
1301 | if (malloc_xmalloc && !r) | ||
1302 | wrterror("out of memory.\n"); | ||
1303 | return (r); | ||
1304 | } | ||