vsyslog.c
00001 #include <u/libu_conf.h>
00002 #include <u/missing.h>
00003
00004
00005
00006
00007
00008 #if !defined(HAVE_VSYSLOG)
00009 #if defined(OS_WIN)
00010
00011 #include <windows.h>
00012 #include <io.h>
00013 #include <sys/locking.h>
00014 #include <errno.h>
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017
00018 void vsyslog(int priority, const char *fmt, va_list ap)
00019 {
00020 #define LIBU_WIN_LOGFILE "libu.log"
00021 enum { BUFSZ = 1024 };
00022 static FILE *df = NULL, *lock = NULL;
00023 char buf[BUFSZ];
00024 int i;
00025
00026
00027 if(df == NULL)
00028 {
00029 df = fopen(LIBU_WIN_LOGFILE, "a+");
00030 lock = fopen(LIBU_WIN_LOGFILE ".lock", "a+");
00031 if(df == NULL || lock == NULL)
00032 exit(1);
00033 }
00034
00035 vsnprintf(buf, BUFSZ, fmt, ap);
00036
00037
00038 for(i = 0;
00039 _locking(fileno(lock), _LK_NBLCK, 1) == EACCES && i < 10; ++i)
00040 Sleep(100);
00041
00042 if(i < 10)
00043 {
00044 fprintf(df, "%s\n", buf);
00045 fflush(df);
00046
00047 _locking(fileno(lock), _LK_UNLCK, 1);
00048 } else {
00049
00050 ;
00051 }
00052
00053 return;
00054 }
00055
00056 #else
00057
00058 #include <stdarg.h>
00059 #include <stdio.h>
00060
00061
00062 void vsyslog(int priority, const char *fmt, va_list args)
00063 {
00064 char buf[1024];
00065
00066 (void) vsnprintf(buf, sizeof buf, fmt, args);
00067 syslog(priority, "%s", buf);
00068
00069 return;
00070 }
00071
00072 #endif
00073
00074 #else
00075
00076 #include <syslog.h>
00077 #include <stdarg.h>
00078 void vsyslog(int priority, const char *fmt, va_list args);
00079
00080 #endif