xmalloc.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* xmalloc.c - get 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. xmalloc() - get memory or bust
  18. INDEX
  19. xmalloc() uses malloc()
  20. SYNOPSIS
  21. char * my_memory;
  22. my_memory = xmalloc(42); / * my_memory gets address of 42 chars * /
  23. DESCRIPTION
  24. Use xmalloc() as an "error-free" malloc(). It does almost the same job.
  25. When it cannot honour your request for memory it BOMBS your program
  26. with a "virtual memory exceeded" message. Malloc() returns NULL and
  27. does not bomb your program.
  28. SEE ALSO
  29. malloc()
  30. */
  31. #ifdef USG
  32. #include <malloc.h>
  33. #endif
  34. char * xmalloc(n)
  35. long n;
  36. {
  37. char * retval;
  38. char * malloc();
  39. void error();
  40. if ( ! (retval = malloc ((unsigned)n)) )
  41. {
  42. error("virtual memory exceeded");
  43. }
  44. return (retval);
  45. }
  46. /* end: xmalloc.c */