-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmalloc.c
More file actions
41 lines (33 loc) · 811 Bytes
/
xmalloc.c
File metadata and controls
41 lines (33 loc) · 811 Bytes
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
/* xmalloc.c - memory allocation with error checking
*
* Copyright 1998 Jochen Voss */
static const char rcsid[] = "$Id: xmalloc.c,v 1.7 1999/07/21 10:37:53 voss Rel $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "moon-buggy.h"
void *
xmalloc (size_t size)
/* Like `malloc', but check for shortage of memory. `xmalloc' never
* returns `NULL'. */
{
void *ptr = malloc (size);
if (ptr == NULL) fatal ("Memory exhausted");
return ptr;
}
void *
xrealloc (void *ptr, size_t size)
/* Like `realloc', but check for shortage of memory. `xrealloc' never
* returns `NULL'. */
{
void *tmp;
if (ptr) {
tmp = realloc (ptr, size);
} else {
tmp = malloc (size);
}
if (tmp == NULL) fatal ("Memory exhausted");
return tmp;
}