source: trunk/minix/lib/ansi/calloc.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 433 bytes
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
6void *
7calloc(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.