xrealloc.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* xrealloc.c -new memory or bust-
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /*
  16. NAME
  17. xrealloc () - get more memory or bust
  18. INDEX
  19. xrealloc () uses realloc ()
  20. SYNOPSIS
  21. char *my_memory;
  22. my_memory = xrealloc (my_memory, 42);
  23. / * my_memory gets (perhaps new) address of 42 chars * /
  24. DESCRIPTION
  25. Use xrealloc () as an "error-free" realloc ().It does almost the same
  26. job. When it cannot honour your request for memory it BOMBS your
  27. program with a "virtual memory exceeded" message. Realloc() returns
  28. NULL and does not bomb your program.
  29. SEE ALSO
  30. realloc ()
  31. */
  32. #ifdef USG
  33. #include <malloc.h>
  34. #endif
  35. char *
  36. xrealloc (ptr, n)
  37. register char *ptr;
  38. long n;
  39. {
  40. char *realloc ();
  41. void error();
  42. if ((ptr = realloc (ptr, (unsigned)n)) == 0)
  43. error ("virtual memory exceeded");
  44. return (ptr);
  45. }
  46. /* end: xrealloc.c */