annotate kpathsea/xrealloc.c @ 1349:33cf1f36aec6

[project @ 1995-09-05 07:06:43 by jwe]
author jwe
date Tue, 05 Sep 1995 07:09:38 +0000
parents 611d403c7f3d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1268
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
1 /* xrealloc.c: realloc with error checking.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
2
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 1992, 93 Free Software Foundation, Inc.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
4
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
8 any later version.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
9
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
13 GNU General Public License for more details.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
14
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
16 along with this program; if not, write to the Free Software
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1268
diff changeset
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1268
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
18
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
19 /* Don't include config.h or all our other usual includes, since
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
20 it's useful to just throw this file into other programs. */
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
21
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
22 #include <stdio.h>
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
23 extern char *realloc ();
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
24
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
25
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
26 extern void *xmalloc ();
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
27
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
28 void *
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
29 xrealloc (old_ptr, size)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
30 void *old_ptr;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
31 unsigned size;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
32 {
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
33 void *new_mem;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
34
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
35 if (old_ptr == NULL)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
36 new_mem = xmalloc (size);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
37 else
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
38 {
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
39 new_mem = (void *) realloc (old_ptr, size);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
40 if (new_mem == NULL)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
41 {
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
42 /* We used to print OLD_PTR here using %x, and casting its
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
43 value to unsigned, but that lost on the Alpha, where
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
44 pointers and unsigned had different sizes. Since the info
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
45 is of little or no value anyway, just don't print it. */
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
46 fprintf (stderr, "fatal: memory exhausted (realloc of %u bytes).\n",
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
47 size);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
48 /* 1 means success on VMS, so pick a random number (ASCII `B'). */
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
49 exit (66);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
50 }
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
51 }
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
52
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
53 return new_mem;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
54 }