netcdf-c/nctest/emalloc.c

53 lines
1.1 KiB
C
Raw Normal View History

2010-06-03 21:24:43 +08:00
/*********************************************************************
2018-12-07 06:47:47 +08:00
* Copyright 2018, UCAR/Unidata
2010-06-03 21:24:43 +08:00
* 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;
}