• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2 
3    This program is Open Source software; you can redistribute it and/or
4    modify it under the terms of the Open Software License version 1.0 as
5    published by the Open Source Initiative.
6 
7    You should have received a copy of the Open Software License along
8    with this program; if not, you may obtain a copy of the Open Software
9    License version 1.0 from http://www.opensource.org/licenses/osl.php or
10    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
11    3001 King Ranch Road, Ukiah, CA 95482.   */
12 
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16 
17 #include <error.h>
18 //#include <libintl.h>
19 #include <stddef.h>
20 #include <stdlib.h>
21 #include <sys/types.h>
22 #include "system.h"
23 
24 #ifndef _
25 # define _(str) gettext (str)
26 #endif
27 
28 
29 /* Allocate N bytes of memory dynamically, with error checking.  */
30 void *
xmalloc(n)31 xmalloc (n)
32      size_t n;
33 {
34   void *p;
35 
36   p = malloc (n);
37   if (p == NULL)
38     error (EXIT_FAILURE, 0, _("memory exhausted"));
39   return p;
40 }
41 
42 
43 /* Allocate memory for N elements of S bytes, with error checking.  */
44 void *
xcalloc(n,s)45 xcalloc (n, s)
46      size_t n, s;
47 {
48   void *p;
49 
50   p = calloc (n, s);
51   if (p == NULL)
52     error (EXIT_FAILURE, 0, _("memory exhausted"));
53   return p;
54 }
55 
56 
57 /* Change the size of an allocated block of memory P to N bytes,
58    with error checking.  */
59 void *
xrealloc(p,n)60 xrealloc (p, n)
61      void *p;
62      size_t n;
63 {
64   p = realloc (p, n);
65   if (p == NULL)
66     error (EXIT_FAILURE, 0, _("memory exhausted"));
67   return p;
68 }
69