spf_log.c

Go to the documentation of this file.
00001 /* 
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of either:
00004  * 
00005  *   a) The GNU Lesser General Public License as published by the Free
00006  *      Software Foundation; either version 2.1, or (at your option) any
00007  *      later version,
00008  * 
00009  *   OR
00010  * 
00011  *   b) The two-clause BSD license.
00012  *
00013  * These licenses can be found with the distribution in the file LICENSES
00014  */
00015 
00016 
00017 #include "spf_sys_config.h"
00018 
00019 
00020 #ifdef STDC_HEADERS
00021 # include <stdlib.h>       /* malloc / free */
00022 # include <stdarg.h>
00023 # include <stdio.h>
00024 #endif
00025 
00026 #include "spf.h"
00027 #include "spf_internal.h"
00028 
00029 
00030 /*
00031  * standard expanded error formating routines
00032  */
00033 
00034 void
00035 SPF_errorx( const char *file, int line, const char *format, ... )
00036 {
00037     char        errmsg[SPF_SYSLOG_SIZE];
00038     va_list ap;
00039     
00040     if (SPF_error_handler == NULL)
00041                 abort();
00042     
00043     va_start(ap, format);
00044     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00045     va_end(ap);
00046 
00047     SPF_error_handler(file, line, errmsg);
00048     abort();
00049 }
00050 
00051 
00052 void
00053 SPF_warningx( const char *file, int line, const char *format, ... )
00054 {
00055     char        errmsg[SPF_SYSLOG_SIZE];
00056     va_list ap;
00057 
00058     if (SPF_warning_handler == NULL)
00059                 return;
00060 
00061     va_start(ap, format);
00062     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00063     va_end(ap);
00064 
00065     SPF_warning_handler(file, line, errmsg);
00066 }
00067 
00068 
00069 void
00070 SPF_infox( const char *file, int line, const char *format, ... )
00071 {
00072     char        errmsg[SPF_SYSLOG_SIZE];
00073     va_list ap;
00074 
00075     if (SPF_info_handler == NULL)
00076                 return;
00077 
00078     va_start(ap, format);
00079     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00080     va_end(ap);
00081 
00082     SPF_info_handler(file, line, errmsg);
00083 }
00084 
00085 
00086 void
00087 SPF_debugx( const char *file, int line, const char *format, ... )
00088 {
00089     char        errmsg[SPF_SYSLOG_SIZE];
00090     va_list ap;
00091 
00092     if (SPF_debug_handler == NULL)
00093                 return;
00094 
00095     va_start(ap, format);
00096     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00097     va_end(ap);
00098 
00099     SPF_debug_handler(file, line, errmsg);
00100 }
00101 
00102 
00103 
00104 /*
00105  * error reporting routines that accept a va_list
00106  */
00107 
00108 void
00109 SPF_errorv(const char *file, int line, const char *format, va_list ap)
00110 {
00111     char        errmsg[SPF_SYSLOG_SIZE];
00112     
00113     if (SPF_error_handler == NULL)
00114                 abort();
00115     
00116     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00117     SPF_error_handler( file, line, errmsg );
00118 
00119     abort();
00120 }
00121 
00122 
00123 void
00124 SPF_warningv(const char *file, int line, const char *format, va_list ap)
00125 {
00126     char        errmsg[SPF_SYSLOG_SIZE];
00127     
00128     if (SPF_warning_handler == NULL)
00129                 return;
00130     
00131     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00132     SPF_warning_handler(file, line, errmsg);
00133 }
00134 
00135 
00136 void
00137 SPF_infov(const char *file, int line, const char *format, va_list ap)
00138 {
00139     char        errmsg[SPF_SYSLOG_SIZE];
00140     
00141     if (SPF_info_handler == NULL)
00142                 return;
00143     
00144     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00145     SPF_info_handler(file, line, errmsg);
00146 }
00147 
00148 
00149 void
00150 SPF_debugv(const char *file, int line, const char *format, va_list ap)
00151 {
00152     char        errmsg[SPF_SYSLOG_SIZE];
00153     
00154     if (SPF_debug_handler == NULL)
00155                 return;
00156     
00157     vsnprintf(errmsg, sizeof(errmsg), format, ap);
00158     SPF_debug_handler(file, line, errmsg);
00159 }
00160 
00161 
00162 /*
00163  * reporting routines for braindead compilers
00164  */
00165 
00166 void
00167 SPF_errorx2(const char *format, ...)
00168 {
00169     va_list ap;
00170     va_start(ap, format);
00171     SPF_errorv(NULL, 0, format, ap);
00172     va_end(ap);
00173 }
00174 
00175 void
00176 SPF_warningx2(const char *format, ...)
00177 {
00178     va_list ap;
00179     va_start(ap, format);
00180     SPF_warningv(NULL, 0, format, ap);
00181     va_end(ap);
00182 }
00183 
00184 void
00185 SPF_infox2(const char *format, ...)
00186 {
00187     va_list ap;
00188     va_start(ap, format);
00189     SPF_infov(NULL, 0, format, ap);
00190     va_end(ap);
00191 }
00192 
00193 void
00194 SPF_debugx2(const char *format, ...)
00195 {
00196     va_list ap;
00197     va_start(ap, format);
00198     SPF_debugv(NULL, 0, format, ap);
00199     va_end(ap);
00200 }

Generated on Tue Nov 4 13:27:39 2008 for libspf2 by  doxygen 1.5.4