ocdebug.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
  2. See the COPYRIGHT file for more information. */
  3. #include "config.h"
  4. #include <stdarg.h>
  5. #include "ocinternal.h"
  6. #include "ocdebug.h"
  7. int ocdebug;
  8. #ifdef OCCATCHERROR
  9. /* Place breakpoint here to catch errors close to where they occur*/
  10. int
  11. ocbreakpoint(int err) {return err;}
  12. int
  13. octhrow(int err)
  14. {
  15. if(err == 0) return err;
  16. return ocbreakpoint(err);
  17. }
  18. #endif
  19. int
  20. xdrerror(void)
  21. {
  22. oc_log(LOGERR,"xdr failure");
  23. return OCTHROW(OC_EDATADDS);
  24. }
  25. void*
  26. occalloc(size_t size, size_t nelems)
  27. {
  28. return ocmalloc(size*nelems);
  29. }
  30. void*
  31. ocmalloc(size_t size)
  32. {
  33. void* memory = calloc(size,1); /* use calloc to zero memory*/
  34. if(memory == NULL) oc_log(LOGERR,"ocmalloc: out of memory");
  35. return memory;
  36. }
  37. void
  38. ocfree(void* mem)
  39. {
  40. if(mem != NULL) free(mem);
  41. }
  42. int
  43. ocpanic(const char* fmt, ...)
  44. {
  45. va_list args;
  46. if(fmt != NULL) {
  47. va_start(args, fmt);
  48. vfprintf(stderr, fmt, args);
  49. fprintf(stderr, "\n" );
  50. va_end( args );
  51. } else {
  52. fprintf(stderr, "panic" );
  53. }
  54. fprintf(stderr, "\n" );
  55. fflush(stderr);
  56. return 0;
  57. }