Main Page | Data Structures | Directories | File List | Data Fields | Globals

ks_error.c

Go to the documentation of this file.
00001 /*
00002  * libkarmaclient - A C Library to the Karmasphere Reputation Server
00003  * Copyright (C) 2006 Karmasphere <http://www.karmasphere.com/>
00004  *  - Shevek <shevek@karmasphere.com>
00005  *  - Dave Stewart <dave.stewart@karmasphere.com>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020  */
00021 
00026 #include "ks_config.h"
00027 #include "ks_common.h"
00028 
00029 #ifdef STDC_HEADERS
00030 # include <stdlib.h>
00031 # include <stdarg.h>
00032 # include <stdio.h>
00033 #endif
00034 
00035 #ifdef HAVE_STRING_H
00036 #include <string.h>
00037 #endif
00038 
00039 #ifdef HAVE_STDIO_H
00040 #include <stdio.h>
00041 #endif
00042 
00043 #define KS_ERRTAG               "libkarmaclient: "
00044 #define KS_ERRBUFSIZ    1024
00045 
00049 static ks_error_handler_t       ks_error_handler = NULL;
00050 
00057 void
00058 ks_error_handler_set(ks_error_handler_t handler)
00059 {
00060         ks_error_handler = handler;
00061 }
00062 
00063 /* XXX: Don't know how to document varargs */
00071 void
00072 ks_error(const char *format, ...)
00073 {
00074         char    buffer[KS_ERRBUFSIZ];
00075         va_list ap;
00076 
00077         strcpy(buffer, KS_ERRTAG);
00078 
00079         va_start(ap, format);
00080         vsnprintf(&(buffer[strlen(KS_ERRTAG)]),
00081                         sizeof(buffer) - strlen(KS_ERRTAG),
00082                         format, ap);
00083         va_end(ap);
00084         buffer[sizeof(buffer) - 1] = '\0';
00085 
00086         if (ks_error_handler) {
00087                 ks_error_handler(buffer);
00088         }
00089         else {
00090                 fputs(buffer, stderr);
00091                 putc('\n', stderr);
00092         }
00093 }

Generated on Tue Aug 7 21:11:30 2007 for libkarmaclient by  doxygen 1.4.4