forked from kohler/xwrits
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmalloc.c
More file actions
41 lines (36 loc) · 743 Bytes
/
Copy pathfmalloc.c
File metadata and controls
41 lines (36 loc) · 743 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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
static void
fail_die_malloc_die(size_t size, const char *file, int line)
{
fprintf(stderr, "Out of memory! (wanted %lu at %s:%d)\n",
(unsigned long)size, file, line);
exit(1);
}
void *
fail_die_malloc(size_t size, const char *file, int line)
{
void *p = malloc(size);
if (!p && size)
fail_die_malloc_die(size, file, line);
return p;
}
void *
fail_die_realloc(void *p, size_t size, const char *file, int line)
{
if (!p)
return fail_die_malloc(size, file, line);
p = realloc(p, size);
if (!p && size)
fail_die_malloc_die(size, file, line);
return p;
}
#ifdef __cplusplus
}
#endif