zc_profile.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This file is part of the zlog Library.
  3. *
  4. * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING in base directory.
  7. */
  8. #ifndef __zc_profile_h
  9. #define __zc_profile_h
  10. #include <stdarg.h>
  11. #define EMPTY()
  12. #define zc_assert(expr, rv) \
  13. if(!(expr)) { \
  14. zc_error(#expr" is null or 0"); \
  15. return rv; \
  16. }
  17. enum zc_profile_flag {
  18. ZC_DEBUG = 0,
  19. ZC_WARN = 1,
  20. ZC_ERROR = 2
  21. };
  22. #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  23. #define zc_debug(...) \
  24. zc_profile_inner(ZC_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
  25. #define zc_warn(...) \
  26. zc_profile_inner(ZC_WARN, __FILE__, __LINE__, __VA_ARGS__)
  27. #define zc_error(...) \
  28. zc_profile_inner(ZC_ERROR, __FILE__, __LINE__, __VA_ARGS__)
  29. #define zc_profile(flag, ...) \
  30. zc_profile_inner(flag, __FILE__, __LINE__, __VA_ARGS__)
  31. #elif defined __GNUC__
  32. #define zc_debug(fmt, args...) \
  33. zc_profile_inner(ZC_DEBUG, __FILE__, __LINE__, fmt, ## args)
  34. #define zc_warn(fmt, args...) \
  35. zc_profile_inner(ZC_WARN, __FILE__, __LINE__, fmt, ## args)
  36. #define zc_error(fmt, args...) \
  37. zc_profile_inner(ZC_ERROR, __FILE__, __LINE__, fmt, ## args)
  38. #define zc_profile(flag, fmt, args...) \
  39. zc_profile_inner(flag, __FILE__, __LINE__, fmt, ## args)
  40. #endif
  41. int zc_profile_inner(int flag,
  42. const char *file, const long line,
  43. const char *fmt, ...);
  44. #endif