00001 /* $Id: vsyslog.c,v 1.2 2000/09/20 03:42:30 robert Exp $ 00002 /* 00003 * Copyright (c) 1994-1996 Sam Leffler 00004 * Copyright (c) 1994-1996 Silicon Graphics, Inc. 00005 * HylaFAX is a trademark of Silicon Graphics, Inc. 00006 * 00007 * Permission to use, copy, modify, distribute, and sell this software and 00008 * its documentation for any purpose is hereby granted without fee, provided 00009 * that (i) the above copyright notices and this permission notice appear in 00010 * all copies of the software and related documentation, and (ii) the names of 00011 * Sam Leffler and Silicon Graphics may not be used in any advertising or 00012 * publicity relating to the software without the specific, prior written 00013 * permission of Sam Leffler and Silicon Graphics. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 00016 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 00017 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00018 * 00019 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 00020 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 00021 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 00022 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 00023 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 00024 * OF THIS SOFTWARE. 00025 */ 00026 #include <stdio.h> 00027 #include <sys/types.h> 00028 #include <stdarg.h> 00029 #include <syslog.h> 00030 #include <string.h> 00031 #include <errno.h> 00032 00033 void 00034 vsyslog(int pri, const char* fmt, va_list ap) 00035 { 00036 char tbuf[2048], fmt_cpy[1024]; 00037 char* cp; 00038 char c; 00039 00040 /* substitute error message for %m */ 00041 for (cp = fmt_cpy; c = *fmt; ++fmt) { 00042 if (c == '%' && fmt[1] == 'm') { 00043 const char* dp; 00044 ++fmt; 00045 for (dp = strerror(errno); *cp = *dp++; ++cp) 00046 ; 00047 } else 00048 *cp++ = c; 00049 *cp = '\0'; 00050 } 00051 (void) vsnprintf(tbuf, sizeof(tbuf), fmt_cpy, ap); 00052 (void) syslog(pri, "%s", tbuf); 00053 } 00054