File: xmalloc.c

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (63 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (4)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "sys-defines.h"

/* forward references */
voidptr_t xmalloc ____P((size_t length));
voidptr_t xrealloc ____P((voidptr_t p, size_t length));
voidptr_t xcalloc ____P((size_t nmemb, size_t size));

voidptr_t 
#ifdef _HAVE_PROTOS
xmalloc (size_t length)
#else
xmalloc (length)
     size_t length;
#endif
{
  voidptr_t p;
  p = (voidptr_t) malloc (length);

  if (p == (voidptr_t) NULL)
    {
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }
  return p;
}

voidptr_t 
#ifdef _HAVE_PROTOS
xrealloc (voidptr_t p, size_t length)
#else
xrealloc (p, length)
     voidptr_t p;
     size_t length;
#endif
{
  p = (voidptr_t) realloc (p, length);

  if (p == (voidptr_t) NULL)
    {
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }
  return p;
}

voidptr_t 
#ifdef _HAVE_PROTOS
xcalloc (size_t nmemb, size_t size)
#else
xcalloc (nmemb, size)
     size_t nmemb, size;
#endif
{
  voidptr_t p;
  p = (voidptr_t) calloc (nmemb, size);

  if (p == (voidptr_t) NULL)
    {
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }
  return p;
}