Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

flow_print.c

Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 
00005 #include "flow_print.h"
00006 #include "flow_error.h"
00007 
00008 #include <unistd.h>
00009 #include <syslog.h>
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <stdarg.h>
00013 
00014 static int s_daemon = 0;  /* what mode is this library running in */
00015 
00016 #define BUFSIZE 1024
00017 
00018 /** 
00019  * Make this library print to syslog
00020  * 
00021  * 
00022  * @return FLOW_SUCCESS
00023  */
00024 int flow_set_daemon(void)
00025 {
00026     s_daemon = 1;
00027     
00028     return FLOW_SUCCESS;
00029 }
00030 
00031 /** 
00032  * flow's printf
00033  * 
00034  * @param format format to print in
00035  * @param  ... args
00036  * 
00037  * @return FLOW_SUCCESS on sucess
00038  */
00039 int flow_printf(const char *format, ...)
00040 {
00041     char buf[BUFSIZE + 1];
00042     va_list ap;
00043     
00044     va_start(ap,format);
00045     vsnprintf(buf, BUFSIZE, format, ap);
00046     va_end(ap);
00047 
00048     buf[BUFSIZE] = '\0';
00049 
00050     if(s_daemon)
00051     {
00052         syslog(LOG_CONS | LOG_DAEMON | LOG_ERR, "%s", buf);
00053     }
00054     else
00055     {
00056         fprintf(stdout, "%s", buf);        
00057     }
00058     
00059     return FLOW_SUCCESS;
00060 }
00061 
00062 int flow_fatalerror(const char *format, ...)
00063 {
00064     char buf[BUFSIZE + 1];
00065     char fmt[BUFSIZE + 1];    
00066     va_list ap;
00067 
00068 
00069     snprintf(fmt, BUFSIZE, "FatalError: %s", format);
00070     fmt[BUFSIZE] = '\0';
00071     
00072     va_start(ap,format);
00073     vsnprintf(buf, BUFSIZE, format, ap);
00074     va_end(ap);
00075 
00076     buf[BUFSIZE] = '\0';
00077 
00078     if(s_daemon)
00079     {
00080         syslog(LOG_CONS | LOG_DAEMON | LOG_ERR, "%s", buf);
00081     }
00082     else
00083     {
00084         fprintf(stderr, "%s", buf);        
00085     }
00086 
00087     exit(1);
00088     /* not reached */
00089     return FLOW_SUCCESS;
00090 }
00091 
00092 int flow_errormsg(const char *format, ...)
00093 {
00094     char buf[BUFSIZE + 1];
00095     char fmt[BUFSIZE + 1];    
00096     va_list ap;
00097 
00098     snprintf(fmt, BUFSIZE, "ERROR: %s", format);
00099     fmt[BUFSIZE] = '\0';
00100     
00101     va_start(ap,format);
00102     vsnprintf(buf, BUFSIZE, format, ap);
00103     va_end(ap);
00104 
00105     buf[BUFSIZE] = '\0';
00106 
00107     if(s_daemon)
00108     {
00109         syslog(LOG_CONS | LOG_DAEMON | LOG_ERR, "%s", buf);
00110     }
00111     else
00112     {
00113         fprintf(stderr, "%s", buf);        
00114     }
00115 
00116     exit(1);
00117     return FLOW_SUCCESS;
00118 
00119 }

Generated on Sun May 14 14:51:15 2006 by  doxygen 1.4.2