calloc.c 860 B

123456789101112131415161718192021222324
  1. /* calloc.c - C standard library routine.
  2. Copyright (c) 1989, 1993 Michael J. Haertel
  3. You may redistribute this library under the terms of the
  4. GNU Library General Public License (version 2 or any later
  5. version) as published by the Free Software Foundation.
  6. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED
  7. WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION OR
  8. WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
  9. SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */
  10. #include <stdlib.h>
  11. #include <string.h>
  12. /* Allocate space for the given number of elements of the given
  13. size, initializing the whole region to binary zeroes. */
  14. void * calloc(size_t nelem, size_t size)
  15. {
  16. void *result;
  17. result = malloc(size * nelem);
  18. if (result)
  19. memset(result, 0, nelem * size);
  20. return result;
  21. }