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 *
|
2023-11-07 10:06:15 +08:00
|
|
|
emalloc (size_t size) /* check return from malloc */
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
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 *
|
2023-11-07 10:06:15 +08:00
|
|
|
erealloc (void *ptr, size_t size) /* check return from realloc */
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|