alloc.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include "raster3d_intern.h"
  6. /*---------------------------------------------------------------------------*/
  7. /*!
  8. * \brief
  9. *
  10. * Same as <em>malloc (nBytes)</em>, except that in case of error
  11. * <tt>Rast3d_error()</tt> is invoked.
  12. *
  13. * \param nBytes
  14. * \return void *: a pointer ... if successful,
  15. * NULL ... otherwise.
  16. */
  17. void *Rast3d_malloc(int nBytes)
  18. {
  19. void *buf;
  20. if (nBytes <= 0)
  21. nBytes = 1;
  22. if ((buf = malloc(nBytes)) != NULL)
  23. return buf;
  24. Rast3d_error("Rast3d_malloc: out of memory");
  25. return (void *)NULL;
  26. }
  27. /*!
  28. * \brief
  29. *
  30. * Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
  31. * <tt>Rast3d_error()</tt> is invoked.
  32. *
  33. * \param ptr
  34. * \param nBytes
  35. * \return void *: a pointer ... if successful,
  36. * NULL ... otherwise.
  37. */
  38. void *Rast3d_realloc(void *ptr, int nBytes)
  39. {
  40. if (nBytes <= 0)
  41. nBytes = 1;
  42. if ((ptr = realloc(ptr, nBytes)) != NULL)
  43. return ptr;
  44. Rast3d_error("Rast3d_realloc: out of memory");
  45. return (void *)NULL;
  46. }
  47. /*!
  48. * \brief
  49. *
  50. * Same as <em>free (ptr)</em>.
  51. *
  52. * \param buf
  53. * \return void
  54. */
  55. void Rast3d_free(void *buf)
  56. {
  57. free(buf);
  58. }