usermem_r.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*<html><pre> -<a href="qh-user_r.htm"
  2. >-------------------------------</a><a name="TOP">-</a>
  3. usermem_r.c
  4. user redefinable functions -- qh_exit, qh_free, and qh_malloc
  5. See README.txt.
  6. If you redefine one of these functions you must redefine all of them.
  7. If you recompile and load this file, then usermem.o will not be loaded
  8. from qhull.a or qhull.lib
  9. See libqhull_r.h for data structures, macros, and user-callable functions.
  10. See user_r.c for qhull-related, redefinable functions
  11. see user_r.h for user-definable constants
  12. See userprintf_r.c for qh_fprintf and userprintf_rbox_r.c for qh_fprintf_rbox
  13. Please report any errors that you fix to qhull@qhull.org
  14. */
  15. #include "libqhull_r.h"
  16. #include <stdarg.h>
  17. #include <stdlib.h>
  18. /*-<a href="qh-user_r.htm#TOC"
  19. >-------------------------------</a><a name="qh_exit">-</a>
  20. qh_exit( exitcode )
  21. exit program
  22. the exitcode must be 255 or less. Zero indicates success.
  23. Note: Exit status ('$?') in bash reports 256 as 0
  24. notes:
  25. qh_exit() is called when qh_errexit() and longjmp() are not available.
  26. This is the only use of exit() in Qhull
  27. To replace qh_exit with 'throw', see libqhullcpp/usermem_r-cpp.cpp
  28. */
  29. void qh_exit(int exitcode) {
  30. exit(exitcode);
  31. } /* exit */
  32. /*-<a href="qh-user_r.htm#TOC"
  33. >-------------------------------</a><a name="qh_fprintf_stderr">-</a>
  34. qh_fprintf_stderr( msgcode, format, list of args )
  35. fprintf to stderr with msgcode (non-zero)
  36. notes:
  37. qh_fprintf_stderr() is called when qh.ferr is not defined, usually due to an initialization error
  38. if msgcode is a MSG_ERROR (6000), caller should set qh.last_errcode (like qh_fprintf) or variable 'last_errcode'
  39. It is typically followed by qh_errexit().
  40. Redefine this function to avoid using stderr
  41. Use qh_fprintf [userprintf_r.c] for normal printing
  42. */
  43. void qh_fprintf_stderr(int msgcode, const char *fmt, ... ) {
  44. va_list args;
  45. va_start(args, fmt);
  46. if(msgcode)
  47. fprintf(stderr, "QH%.4d ", msgcode);
  48. vfprintf(stderr, fmt, args);
  49. va_end(args);
  50. } /* fprintf_stderr */
  51. /*-<a href="qh-user_r.htm#TOC"
  52. >-------------------------------</a><a name="qh_free">-</a>
  53. qh_free(qh, mem )
  54. free memory
  55. notes:
  56. same as free()
  57. No calls to qh_errexit()
  58. */
  59. void qh_free(void *mem) {
  60. free(mem);
  61. } /* free */
  62. /*-<a href="qh-user_r.htm#TOC"
  63. >-------------------------------</a><a name="qh_malloc">-</a>
  64. qh_malloc( mem )
  65. allocate memory
  66. notes:
  67. same as malloc()
  68. */
  69. void *qh_malloc(size_t size) {
  70. return malloc(size);
  71. } /* malloc */