You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.3 KiB

  1. /* $Id: macros.h,v 1.1 1999/11/21 22:01:04 tausq Exp $ */
  2. #ifndef _MACROS_H
  3. #define _MACROS_H
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #ifdef DEBUG
  7. #define DPRINTF(fmt, arg...) \
  8. do { \
  9. fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  10. fprintf(stderr, fmt, ##arg); \
  11. fprintf(stderr, "\r\n"); \
  12. } while (0);
  13. #define ASSERT(cond) \
  14. if (!(cond)) { \
  15. fprintf(stderr, "ASSERTION FAILED at %s:%d! (%s)\n", __FILE__, __LINE__, #cond); \
  16. exit(255); \
  17. }
  18. #define VERIFY(cond) ASSERT(cond)
  19. #define ABORT abort()
  20. #define STRDUP(s) safe_strdup(s)
  21. #define MALLOC(sz) safe_malloc(sz)
  22. #define FREE(p) safe_free((void **)&p);
  23. #else
  24. #define DPRINTF(fmt, arg...)
  25. #define ASSERT(cond)
  26. #define VERIFY(cond)
  27. #define ABORT exit(255)
  28. #define STRDUP(s) (s ? strdup(s) : NULL)
  29. #define MALLOC(sz) malloc(sz)
  30. #define FREE(p) if (p) free(p)
  31. #endif
  32. /* Do you see a perl influence? :-) */
  33. #define DIE(fmt, arg...) \
  34. do { \
  35. fprintf(stderr, "Fatal error encountered at %s:%d\r\n\t", __FILE__, __LINE__); \
  36. fprintf(stderr, fmt, ##arg); \
  37. fprintf(stderr, "\r\n"); \
  38. ABORT; \
  39. } while (0);
  40. #define PERROR(ctx) \
  41. do { \
  42. fprintf(stderr, "I/O error at %s:%d\r\n\t", __FILE__, __LINE__); \
  43. fprintf(stderr, "%s: %s\r\n", ctx, strerror(errno)); \
  44. ABORT; \
  45. } while (0);
  46. #define NEW(S) (S *)MALLOC(sizeof(S))
  47. #define _(s) gettext(s)
  48. #endif