calloc.c 373 B

1234567891011121314151617
  1. /* $Id$ */
  2. #define ALIGN(sz) ((((sz) + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long))
  3. char *
  4. calloc(nelem, elsize)
  5. unsigned int nelem, elsize;
  6. {
  7. register char *p;
  8. register long *q;
  9. unsigned int size = ALIGN(nelem * elsize);
  10. extern char *malloc();
  11. p = malloc(size);
  12. if (p == 0) return 0;
  13. q = (long *) (p + size);
  14. while ((char *) q > p) *--q = 0;
  15. return p;
  16. }