1 /********************************************************************* 2 * Copyright 1993, UCAR/Unidata 3 * See netcdf/COPYRIGHT file for copying and redistribution conditions. 4 * $Id$ 5 *********************************************************************/ 6 7 /*LINTLIBRARY*/ 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include "error.h" 11 #include "emalloc.h" 12 #ifdef HDF 13 #include "hdf.h" 14 #endif 15 16 void * emalloc(size)17emalloc (size) /* check return from malloc */ 18 int size; 19 { 20 void *p; 21 22 if (size < 0) { 23 error ("negative arg to emalloc: %d", size); 24 return 0; 25 } 26 if (size == 0) 27 return 0; 28 #ifdef HDF 29 p = (void *) HDmalloc((uint32)size); 30 #else 31 p = (void *) malloc ((unsigned) size); 32 #endif 33 if (p == 0) { 34 error ("out of memory\n"); 35 exit (1); 36 } 37 return p; 38 } 39 40 void * erealloc(ptr,size)41erealloc (ptr,size) /* check return from realloc */ 42 void *ptr; 43 int size; 44 { 45 void *p; 46 47 if (size < 0) { 48 error ("negative arg to realloc"); 49 return 0; 50 } 51 #ifdef HDF 52 p = (void *) HDrealloc((VOIDP) ptr, (uint32) size); 53 #else 54 p = (void *) realloc ((char *) ptr, (unsigned) size); 55 #endif 56 57 if (p == 0) { 58 error ("out of memory"); 59 exit(1); 60 } 61 return p; 62 } 63 64