~ubuntu-branches/ubuntu/jaunty/plotutils/jaunty

« back to all changes in this revision

Viewing changes to lib/xmalloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "sys-defines.h"
2
 
 
3
 
/* forward references */
4
 
voidptr_t xmalloc ____P((size_t length));
5
 
voidptr_t xrealloc ____P((voidptr_t p, size_t length));
6
 
voidptr_t xcalloc ____P((size_t nmemb, size_t size));
7
 
 
8
 
voidptr_t 
9
 
#ifdef _HAVE_PROTOS
 
1
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
 
2
   1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
 
3
 
 
4
   The GNU plotutils package is free software.  You may redistribute it
 
5
   and/or modify it under the terms of the GNU General Public License as
 
6
   published by the Free Software foundation; either version 2, or (at your
 
7
   option) any later version.
 
8
 
 
9
   The GNU plotutils package is distributed in the hope that it will be
 
10
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License along
 
15
   with the GNU plotutils package; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
 
17
   Boston, MA 02110-1301, USA. */
 
18
 
 
19
#include "libcommon.h"
 
20
 
 
21
void * 
10
22
xmalloc (size_t length)
11
 
#else
12
 
xmalloc (length)
13
 
     size_t length;
14
 
#endif
15
 
{
16
 
  voidptr_t p;
17
 
  p = (voidptr_t) malloc (length);
18
 
 
19
 
  if (p == (voidptr_t) NULL)
20
 
    {
21
 
      perror ("out of memory");
22
 
      exit (EXIT_FAILURE);
23
 
    }
24
 
  return p;
25
 
}
26
 
 
27
 
voidptr_t 
28
 
#ifdef _HAVE_PROTOS
29
 
xrealloc (voidptr_t p, size_t length)
30
 
#else
31
 
xrealloc (p, length)
32
 
     voidptr_t p;
33
 
     size_t length;
34
 
#endif
35
 
{
36
 
  p = (voidptr_t) realloc (p, length);
37
 
 
38
 
  if (p == (voidptr_t) NULL)
39
 
    {
40
 
      perror ("out of memory");
41
 
      exit (EXIT_FAILURE);
42
 
    }
43
 
  return p;
44
 
}
45
 
 
46
 
voidptr_t 
47
 
#ifdef _HAVE_PROTOS
 
23
{
 
24
  void * p;
 
25
  p = (void *) malloc (length);
 
26
 
 
27
  if (p == (void *) NULL)
 
28
    {
 
29
      perror ("out of memory");
 
30
      exit (EXIT_FAILURE);
 
31
    }
 
32
  return p;
 
33
}
 
34
 
 
35
void * 
 
36
xrealloc (void * p, size_t length)
 
37
{
 
38
  p = (void *) realloc (p, length);
 
39
 
 
40
  if (p == (void *) NULL)
 
41
    {
 
42
      perror ("out of memory");
 
43
      exit (EXIT_FAILURE);
 
44
    }
 
45
  return p;
 
46
}
 
47
 
 
48
void * 
48
49
xcalloc (size_t nmemb, size_t size)
49
 
#else
50
 
xcalloc (nmemb, size)
51
 
     size_t nmemb, size;
52
 
#endif
53
50
{
54
 
  voidptr_t p;
55
 
  p = (voidptr_t) calloc (nmemb, size);
 
51
  void * p;
 
52
  p = (void *) calloc (nmemb, size);
56
53
 
57
 
  if (p == (voidptr_t) NULL)
 
54
  if (p == (void *) NULL)
58
55
    {
59
56
      perror ("out of memory");
60
57
      exit (EXIT_FAILURE);