File: emalloc.c

package info (click to toggle)
libhdf4 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,384 kB
  • sloc: ansic: 128,700; sh: 15,015; fortran: 12,444; java: 5,863; xml: 1,205; makefile: 794; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (46 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (2)
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
/*********************************************************************
 *   Copyright 1993, UCAR/Unidata
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
 *********************************************************************/

#include <stdio.h>
#include <stdlib.h>

#include "error.h"
#include "emalloc.h"

/* Check return from malloc */
void *
emalloc(size_t size)
{
    void *p = NULL;

    if (size == 0)
        return NULL;

    p = (void *)malloc(size);
    if (p == NULL) {
        error("out of memory\n");
        exit(EXIT_FAILURE);
    }

    return p;
}

/* Check return from realloc
 *
 * NOTE: realloc(NULL, 0) behavior is implementation-defined
 */
void *
erealloc(void *ptr, size_t size)
{
    void *p = NULL;

    p = (void *)realloc(ptr, size);
    if (p == NULL) {
        error("out of memory");
        exit(EXIT_FAILURE);
    }

    return p;
}