File: g_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 (85 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Wrappers for standard storage allocation functions, for
   libplot/libplotter with the exception of the libxmi scan conversion
   module, which has its own more complicated versions (see mi_alloc.c). */

#include "sys-defines.h"
#include "extern.h"

/* wrapper for malloc() */
voidptr_t 
#ifdef _HAVE_PROTOS
_plot_xmalloc (size_t size)
#else
_plot_xmalloc (size)
     size_t size;
#endif
{
  voidptr_t p;

  p = (voidptr_t) malloc (size);
  if (p == (voidptr_t)NULL)
    {
      fputs ("libplot: ", stderr);
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }

#ifdef DEBUG_MALLOC
  fprintf (stderr, "malloc (%d) = %p\n", size, p);
#endif

  return p;
}

/* wrapper for calloc() */
voidptr_t 
#ifdef _HAVE_PROTOS
_plot_xcalloc (size_t nmemb, size_t size)
#else
_plot_xcalloc (nmemb, size)
     size_t nmemb, size;
#endif
{
  voidptr_t p;

  p = (voidptr_t) calloc (nmemb, size);
  if (p == (voidptr_t)NULL)
    {
      fputs ("libplot: ", stderr);
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }

#ifdef DEBUG_MALLOC
  fprintf (stderr, "calloc (%d, %d) = %p\n", nmemb, size, p);
#endif

  return p;
}

/* wrapper for realloc() */
voidptr_t 
#ifdef _HAVE_PROTOS
_plot_xrealloc (voidptr_t p, size_t size)
#else
_plot_xrealloc (p, size)
     voidptr_t p;
     size_t size;
#endif
{
  voidptr_t q;

  q = (voidptr_t) realloc (p, size);
  if (q == (voidptr_t)NULL)
    {
      fputs ("libplot: ", stderr);
      perror ("out of memory");
      exit (EXIT_FAILURE);
    }

#ifdef DEBUG_MALLOC
  fprintf (stderr, "realloc (%p, %d) = %p\n", p, size, q);
#endif

  return q;
}