• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/json-c/debug.c

  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 
 12 #include "config.h"
 13 
 14 #include <stdio.h>
 15 #include <stdlib.h>
 16 #include <string.h>
 17 #include <stdarg.h>
 18 
 19 #if HAVE_SYSLOG_H
 20 # include <syslog.h>
 21 #endif /* HAVE_SYSLOG_H */
 22 
 23 #if HAVE_UNISTD_H
 24 # include <unistd.h>
 25 #endif /* HAVE_UNISTD_H */
 26 
 27 #if HAVE_SYS_PARAM_H
 28 #include <sys/param.h>
 29 #endif /* HAVE_SYS_PARAM_H */
 30 
 31 #include "debug.h"
 32 
 33 static int _syslog = 0;
 34 static int _debug = 0;
 35 
 36 void mc_set_debug(int debug) { _debug = debug; }
 37 int mc_get_debug(void) { return _debug; }
 38 
 39 extern void mc_set_syslog(int syslog)
 40 {
 41   _syslog = syslog;
 42 }
 43 
 44 void mc_abort(const char *msg, ...)
 45 {
 46   va_list ap;
 47   va_start(ap, msg);
 48 #if HAVE_VSYSLOG
 49   if(_syslog) {
 50           vsyslog(LOG_ERR, msg, ap);
 51   } else
 52 #endif
 53           vprintf(msg, ap);
 54   va_end(ap);
 55   exit(1);
 56 }
 57 
 58 
 59 void mc_debug(const char *msg, ...)
 60 {
 61   va_list ap;
 62   if(_debug) {
 63     va_start(ap, msg);
 64 #if HAVE_VSYSLOG
 65     if(_syslog) {
 66                 vsyslog(LOG_DEBUG, msg, ap);
 67         } else
 68 #endif
 69                 vprintf(msg, ap);
 70     va_end(ap);
 71   }
 72 }
 73 
 74 void mc_error(const char *msg, ...)
 75 {
 76   va_list ap;
 77   va_start(ap, msg);
 78 #if HAVE_VSYSLOG
 79     if(_syslog) {
 80                 vsyslog(LOG_ERR, msg, ap);
 81         } else
 82 #endif
 83                 vfprintf(stderr, msg, ap);
 84   va_end(ap);
 85 }
 86 
 87 void mc_info(const char *msg, ...)
 88 {
 89   va_list ap;
 90   va_start(ap, msg);
 91 #if HAVE_VSYSLOG
 92     if(_syslog) {
 93                 vsyslog(LOG_INFO, msg, ap);
 94         } else 
 95 #endif
 96                 vfprintf(stderr, msg, ap);
 97   va_end(ap);
 98 }
 99 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt