/* * _snprintk - format a message into a buffer. Like sprintf except we * also specify the length of the output buffer, and we handle * %m (error message), %t (current time) and %I (IP address) formats. * Returns the number of chars put into buf. * * NB! Doesn't do floating-point formats and long modifiers. * (e.g. "%lu"). */ int MS_CDECL _snprintk (char *buf, int buflen, const char *fmt, ...) { int len; va_list args; va_start (args, fmt); len = _vsnprintk (buf, buflen, fmt, args); va_end (args); return (len); }
int MS_CDECL _printk (const char *fmt, ...) { int left = (int)(printk_end - printk_ptr); int len = -1; if (_printk_file && fmt && left > 0) { va_list args; va_start (args, fmt); len = _vsnprintk (printk_ptr, left, fmt, args); printk_ptr += len; _printk_flush(); va_end (args); } return (len); }
void vsyslog (int pri, const char *fmt, va_list ap) { char *p; char tbuffer [2048]; int left = sizeof(tbuffer); int saved_errno = errno; time_t t; #if 0 /* Check for invalid bits */ if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) { syslog (INTERNALLOG, "syslog: unknown facility/priority: 0x%X", pri); pri &= (LOG_PRIMASK | LOG_FACMASK); } #endif /* Check priority against setlogmask values */ #if 0 if (!(LOG_MASK(LOG_PRI(pri)) & logMask)) return; #else if (!(LOG_UPTO(LOG_PRI(pri)))) return; #endif /* Set default facility if none specified */ if (!(pri & LOG_FACMASK)) pri |= logFacil; /* Build the message */ time (&t); p = tbuffer; p += _snprintk (p, left, "<%3d>%.15s ", pri, ctime(&t)+4); left -= p - tbuffer; if (logTag) { p += _snprintk (p, left, logTag); left -= p - tbuffer; } if (logStat & LOG_PID) { p += _snprintk (p, left, "[%d]", getpid()); left -= p - tbuffer; } if (logTag) { p += _snprintk (p, left, ": "); left -= p - tbuffer; } errno = errno_s = saved_errno; p += _vsnprintk (p, left, fmt, ap); if (*(p-1) != '\n') { *p++ = '\n'; *p = 0; } if (!logOpened) openlog (logTag, logStat | LOG_NDELAY, logFacil); if (logFile) _fputsk (tbuffer, logFile); if (logSock) { int len = sock_puts (logSock, (const BYTE*)tbuffer); const char *err = sockerr ((const tcp_Socket*)logSock); if (len == 0 || err) { sock_close (logSock); free (logSock); logSock = NULL; syslog (LOG_ERR, "UDP-write failed: %s\n", err); } } }