alloc.c 1.2 KB

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