home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / internet / desc03.sh / allocate.c next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  1000 b   |  46 lines

  1. /* allocate.c -    Interface to malloc/realloc
  2.  *
  3.  * DESCRIPTION
  4.  *    These routines, allocate and re_allocate call malloc(3) and
  5.  *    realloc(3) respectively.  If malloc or realloc returns NULL,
  6.  *    an error message is printed and execution is terminated,
  7.  *    otherwise, the value returned by malloc/realloc is returned.
  8.  *
  9.  * Copyright (c) 1991,1992 Tim Cook.
  10.  * Non-profit distribution allowed.  See README for details.
  11.  */
  12.  
  13. static char rcsid[] = "$Id: allocate.c,v 1.1 1992/10/30 06:19:34 tim Exp $";
  14.  
  15. #include "config.h"
  16.  
  17. extern VOID_PTR malloc () ;
  18. extern VOID_PTR realloc () ;
  19.  
  20.  
  21. VOID_PTR allocate (length)
  22.    size_t length ;
  23. {
  24.    VOID_PTR tmp ;
  25.  
  26.    if ((tmp = malloc (length)) == (VOID_PTR) NULL) {
  27.       perror ("malloc") ;
  28.       exit (1) ; }
  29.    else
  30.       return tmp ;
  31.    }
  32.  
  33.  
  34. VOID_PTR re_allocate (p, length)
  35.    VOID_PTR p ;
  36.    size_t length ;
  37. {
  38.    VOID_PTR tmp ;
  39.  
  40.    if ((tmp = realloc (p, length)) == (VOID_PTR) NULL) {
  41.       perror ("realloc") ;
  42.       exit (1) ; }
  43.    else
  44.       return tmp ;
  45.    }
  46.