Back to index

tetex-bin  3.0
xrealloc.c
Go to the documentation of this file.
00001 /* xrealloc.c: realloc with error checking.
00002 
00003 Copyright (C) 1992, 93 Free Software Foundation, Inc.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #include <stdio.h>
00020 #include <kpathsea/config.h>
00021 
00022 extern void *xmalloc P1H(unsigned);
00023 
00024 void *
00025 xrealloc P2C(void *, old_ptr, unsigned, size)
00026 {
00027   void *new_mem;
00028 
00029   if (old_ptr == NULL)
00030     new_mem = xmalloc (size);
00031   else
00032     {
00033       new_mem = (void *) realloc (old_ptr, size);
00034       if (new_mem == NULL)
00035         {
00036           /* We used to print OLD_PTR here using %x, and casting its
00037              value to unsigned, but that lost on the Alpha, where
00038              pointers and unsigned had different sizes.  Since the info
00039              is of little or no value anyway, just don't print it.  */
00040           fprintf (stderr, "fatal: memory exhausted (realloc of %u bytes).\n",
00041                    size);
00042           /* 1 means success on VMS, so pick a random number (ASCII `B').  */
00043           exit (66);
00044         }
00045     }
00046 
00047   return new_mem;
00048 }