1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
/*********************************************************************
* Copyright 2018, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
* $Header: /upc/share/CVS/netcdf-3/nctest/emalloc.c,v 1.11 2006/10/31 16:21:56 ed Exp $
*********************************************************************/
/*LINTLIBRARY*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include "error.h"
#include "emalloc.h"
void *
emalloc (size) /* check return from malloc */
size_t size;
{
void *p;
if (size > (unsigned long)32767) {
error ("absurd arg to emalloc: %lu", (unsigned long) size);
return 0;
}
if (size == 0)
return 0;
p = (void *) malloc (size);
if (p == 0) {
error ("out of memory\n");
exit (1);
}
return p;
}
void *
erealloc (ptr, size) /* check return from realloc */
void *ptr;
size_t size;
{
void *p;
if (size > (unsigned long)32767) {
error ("absurd arg to erealloc %lu", (unsigned long) size);
return 0;
}
p = (void *) realloc (ptr, size);
if (p == 0) {
error ("out of memory");
exit(1);
}
return p;
}
|