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 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * $Id: debug.c,v 1.5 2006/01/26 02:16:28 mclark Exp $
  3. *
  4. * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the MIT license. See COPYING for details.
  9. *
  10. */
  11. #include "config.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. #if HAVE_SYSLOG_H
  17. # include <syslog.h>
  18. #endif /* HAVE_SYSLOG_H */
  19. #if HAVE_UNISTD_H
  20. # include <unistd.h>
  21. #endif /* HAVE_UNISTD_H */
  22. #if HAVE_SYS_PARAM_H
  23. #include <sys/param.h>
  24. #endif /* HAVE_SYS_PARAM_H */
  25. #include "debug.h"
  26. static int _syslog = 0;
  27. static int _debug = 0;
  28. void mc_set_debug(int debug) { _debug = debug; }
  29. int mc_get_debug() { return _debug; }
  30. extern void mc_set_syslog(int syslog)
  31. {
  32. _syslog = syslog;
  33. }
  34. void mc_abort(const char *msg, ...)
  35. {
  36. va_list ap;
  37. va_start(ap, msg);
  38. #if HAVE_VSYSLOG
  39. if(_syslog) {
  40. vsyslog(LOG_ERR, msg, ap);
  41. } else
  42. #endif
  43. vprintf(msg, ap);
  44. exit(1);
  45. }
  46. void mc_debug(const char *msg, ...)
  47. {
  48. va_list ap;
  49. if(_debug) {
  50. va_start(ap, msg);
  51. #if HAVE_VSYSLOG
  52. if(_syslog) {
  53. vsyslog(LOG_DEBUG, msg, ap);
  54. } else
  55. #endif
  56. vprintf(msg, ap);
  57. }
  58. }
  59. void mc_error(const char *msg, ...)
  60. {
  61. va_list ap;
  62. va_start(ap, msg);
  63. #if HAVE_VSYSLOG
  64. if(_syslog) {
  65. vsyslog(LOG_ERR, msg, ap);
  66. } else
  67. #endif
  68. vfprintf(stderr, msg, ap);
  69. }
  70. void mc_info(const char *msg, ...)
  71. {
  72. va_list ap;
  73. va_start(ap, msg);
  74. #if HAVE_VSYSLOG
  75. if(_syslog) {
  76. vsyslog(LOG_INFO, msg, ap);
  77. } else
  78. #endif
  79. vfprintf(stderr, msg, ap);
  80. }

No Description

Contributors (1)