calloc.c 860 B

12345678910111213141516171819202122232425
  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 <string.h>
  11. #include "malloc.h"
  12. /* Allocate space for the given number of elements of the given
  13. size, initializing the whole region to binary zeroes. */
  14. void *
  15. calloc(size_t nelem, size_t size)
  16. {
  17. void *result;
  18. result = malloc(size * nelem);
  19. if (result)
  20. memset(result, 0, nelem * size);
  21. return result;
  22. }