home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DMAKE37S.ZIP / DMAKE / DBUG / MALLOC / CALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  1.4 KB  |  71 lines

  1. /*
  2.  * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  3.  * You may copy, distribute, and use this software as long as this
  4.  * copyright statement is not removed.
  5.  */
  6. #include <stdio.h>
  7.  
  8. /*
  9.  * Function:    calloc()
  10.  *
  11.  * Purpose:    to allocate and nullify a data area
  12.  *
  13.  * Arguments:    nelem    - number of elements
  14.  *        elsize    - size of each element
  15.  *
  16.  * Returns:    NULL    - if malloc fails
  17.  *        or pointer to allocated space
  18.  *
  19.  * Narrative:    determine size of area to malloc
  20.  *        malloc area.
  21.  *        if malloc succeeds
  22.  *            fill area with nulls
  23.  *        return ptr to malloc'd region
  24.  */
  25. #ifndef lint
  26. static char rcs_header[] = "$Id: calloc.c,v 1.6 90/05/11 00:13:07 cpcahil Exp $";
  27. #endif
  28.  
  29. char *
  30. calloc(nelem,elsize)
  31.     unsigned int       nelem;
  32.     unsigned int       elsize;
  33. {
  34.     char        * malloc();
  35.     char        * memset();
  36.     char        * ptr;
  37.     unsigned int      size;
  38.  
  39.     size = elsize * nelem;
  40.  
  41.     if( (ptr = malloc(size)) != NULL)
  42.     {
  43.         (void) memset(ptr,'\0',(int)size);
  44.     }
  45.  
  46.     return(ptr);
  47. }
  48.  
  49.  
  50. /*
  51.  * $Log:    calloc.c,v $
  52.  * Revision 1.6  90/05/11  00:13:07  cpcahil
  53.  * added copyright statment
  54.  * 
  55.  * Revision 1.5  90/02/24  20:41:57  cpcahil
  56.  * lint changes.
  57.  * 
  58.  * Revision 1.4  90/02/24  17:25:47  cpcahil
  59.  * changed $header to $id so full path isn't included.
  60.  * 
  61.  * Revision 1.3  90/02/24  13:32:24  cpcahil
  62.  * added function header.  moved log to end of file.
  63.  * 
  64.  * Revision 1.2  90/02/22  23:08:26  cpcahil
  65.  * fixed rcs_header line
  66.  * 
  67.  * Revision 1.1  90/02/22  23:07:38  cpcahil
  68.  * Initial revision
  69.  * 
  70.  */
  71.