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

debug.c 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * $Id: debug.c,v 1.4 2005/06/14 22:41:51 mclark Exp $
  3. *
  4. * Copyright Metaparadigm Pte. Ltd. 2004.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public (LGPL)
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details: http://www.gnu.org/
  16. *
  17. */
  18. #include "config.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdarg.h>
  23. #if HAVE_SYSLOG_H
  24. # include <syslog.h>
  25. #endif /* HAVE_SYSLOG_H */
  26. #if HAVE_UNISTD_H
  27. # include <unistd.h>
  28. #endif /* HAVE_UNISTD_H */
  29. #if HAVE_SYS_PARAM_H
  30. #include <sys/param.h>
  31. #endif /* HAVE_SYS_PARAM_H */
  32. #include "debug.h"
  33. static int _syslog = 0;
  34. static int _debug = 0;
  35. void mc_set_debug(int debug) { _debug = debug; }
  36. int mc_get_debug() { return _debug; }
  37. extern void mc_set_syslog(int syslog)
  38. {
  39. _syslog = syslog;
  40. }
  41. void mc_abort(const char *msg, ...)
  42. {
  43. va_list ap;
  44. va_start(ap, msg);
  45. #if HAVE_VSYSLOG
  46. if(_syslog) {
  47. vsyslog(LOG_ERR, msg, ap);
  48. } else
  49. #endif
  50. vprintf(msg, ap);
  51. exit(1);
  52. }
  53. void mc_debug(const char *msg, ...)
  54. {
  55. va_list ap;
  56. if(_debug) {
  57. va_start(ap, msg);
  58. #if HAVE_VSYSLOG
  59. if(_syslog) {
  60. vsyslog(LOG_DEBUG, msg, ap);
  61. } else
  62. #endif
  63. vprintf(msg, ap);
  64. }
  65. }
  66. void mc_error(const char *msg, ...)
  67. {
  68. va_list ap;
  69. va_start(ap, msg);
  70. #if HAVE_VSYSLOG
  71. if(_syslog) {
  72. vsyslog(LOG_ERR, msg, ap);
  73. } else
  74. #endif
  75. vfprintf(stderr, msg, ap);
  76. }
  77. void mc_info(const char *msg, ...)
  78. {
  79. va_list ap;
  80. va_start(ap, msg);
  81. #if HAVE_VSYSLOG
  82. if(_syslog) {
  83. vsyslog(LOG_INFO, msg, ap);
  84. } else
  85. #endif
  86. vfprintf(stderr, msg, ap);
  87. }

No Description

Contributors (1)