home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38B.ZIP / DBUG / MALLOC / CALLOC.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  74 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.1 1992/01/24 03:28:58 dvadura 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.1  1992/01/24  03:28:58  dvadura
  53.  * dmake Version 3.8, Initial revision
  54.  *
  55.  * Revision 1.6  90/05/11  00:13:07  cpcahil
  56.  * added copyright statment
  57.  * 
  58.  * Revision 1.5  90/02/24  20:41:57  cpcahil
  59.  * lint changes.
  60.  * 
  61.  * Revision 1.4  90/02/24  17:25:47  cpcahil
  62.  * changed $header to $id so full path isn't included.
  63.  * 
  64.  * Revision 1.3  90/02/24  13:32:24  cpcahil
  65.  * added function header.  moved log to end of file.
  66.  * 
  67.  * Revision 1.2  90/02/22  23:08:26  cpcahil
  68.  * fixed rcs_header line
  69.  * 
  70.  * Revision 1.1  90/02/22  23:07:38  cpcahil
  71.  * Initial revision
  72.  * 
  73.  */
  74.