File: fmalloc.c

package info (click to toggle)
xwrits 2.21-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 576 kB
  • ctags: 651
  • sloc: ansic: 5,393; sh: 330; makefile: 98
file content (41 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (22)
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