libutil: add O_NOCTTY back to old pty open code
[minix.git] / lib / libc / minix / minix-calloc.c
blob0c4323902b81d9e7a538178c837c54057532cc3f
1 /* $Header$ */
2 #include <stdlib.h>
4 /* replace undef by define */
5 #define ALIGN_EIGHT_BYTES /* Use 8-byte alignment. */
7 #ifdef ALIGN_EIGHT_BYTES
8 #define ALIGN_SIZE 8
9 #else
10 #define ALIGN_SIZE sizeof(size_t)
11 #endif
13 #define ALIGN(x) (((x) + (ALIGN_SIZE - 1)) & ~(ALIGN_SIZE - 1))
15 void *
16 calloc(size_t nelem, size_t elsize)
18 register char *p;
19 register size_t *q;
20 size_t size = ALIGN(nelem * elsize);
22 p = malloc(size);
23 if (p == NULL) return NULL;
24 q = (size_t *) (p + size);
25 while ((char *) q > p) *--q = 0;
26 return p;