Line | |
---|
1 | /* $Header: /cvsup/minix/src/lib/ansi/calloc.c,v 1.1.1.1 2005/04/21 14:56:04 beng Exp $ */
|
---|
2 | #include <stdlib.h>
|
---|
3 |
|
---|
4 | #define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1))
|
---|
5 |
|
---|
6 | void *
|
---|
7 | calloc(size_t nelem, size_t elsize)
|
---|
8 | {
|
---|
9 | register char *p;
|
---|
10 | register size_t *q;
|
---|
11 | size_t size = ALIGN(nelem * elsize);
|
---|
12 |
|
---|
13 | p = malloc(size);
|
---|
14 | if (p == NULL) return NULL;
|
---|
15 | q = (size_t *) (p + size);
|
---|
16 | while ((char *) q > p) *--q = 0;
|
---|
17 | return p;
|
---|
18 | }
|
---|
19 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.