emulate-vsyslog-20071213
[openafs.git] / src / util / snprintf.c
index 603d174..7f2452c 100644 (file)
@@ -10,6 +10,7 @@ RCSID
 #include <stdarg.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <string.h>
 #ifndef AFS_NT40_ENV
 #include <netinet/in.h>
 #include <netdb.h>
@@ -19,13 +20,6 @@ RCSID
 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SGI65_ENV)
 #include <sys/socket.h>
 #endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 
 #define MAXPREC 100
 
@@ -43,7 +37,7 @@ mkint(char *buf, afs_uintmax_t val, int base, int uc, unsigned prec)
     int len = 0, dig, i;
 
     while (val) {
-       dig = val % base;
+       dig = (int) (val % base);
        val = (val - dig) / base;
        if (dig < 10)
            dig = dig + '0';
@@ -137,7 +131,8 @@ mkint(char *buf, afs_uintmax_t val, int base, int uc, unsigned prec)
 int
 afs_vsnprintf(char *p, size_t avail, const char *fmt, va_list ap)
 {
-    unsigned int width, precision, haveprec, len;
+    unsigned int width, precision, haveprec;
+    size_t len;
     int ljust, plsign, spsign, altform, zfill;
     int hflag, lflag, count, *countp, j;
     char *x, *y, xbuf[MAXPREC + 21], fbuf[20];
@@ -408,7 +403,7 @@ afs_vsnprintf(char *p, size_t avail, const char *fmt, va_list ap)
                                 * if spsign specified, IPaddr fields are space-filled to 3 digits
                                 */
            UVAL = va_arg(ap, unsigned long);
-           ia.s_addr = UVAL;
+           ia.s_addr = (unsigned long)UVAL;
            if (haveprec && !precision)
                he = 0;
            else
@@ -428,7 +423,7 @@ afs_vsnprintf(char *p, size_t avail, const char *fmt, va_list ap)
                            *y = toupper(*y);
                }
            } else {
-               UVAL = ntohl(UVAL);
+               UVAL = ntohl((unsigned long)UVAL);
                if (zfill) {
                    x = "%03u.%03u.%03u.%03u";
                } else if (spsign) {
@@ -520,12 +515,22 @@ vsnprintf(char *p, unsigned int avail, char *fmt, va_list ap)
 {
     int result;
     result = afs_vsnprintf(p, avail, fmt, ap);
-#ifdef AFS_AIX51_ENV
+#if defined(AFS_AIX51_ENV) || defined(AFS_NT40_ENV)
     return result;
 #endif
 }
 #endif /* AFS_OSF20_ENV || AFS_AIX32_ENV */
 
+#ifndef HAVE_VSYSLOG
+void
+vsyslog(int priority, const char *format, va_list args)
+{
+  char buf[1024];
+  vsnprintf(buf, sizeof(buf), format, args);
+  syslog(priority, "%s", buf);
+}
+#endif
+
 #ifndef AFS_NT40_ENV
 #if defined(AFS_OSF20_ENV) && !defined(AFS_DUX50_ENV) || defined(AFS_AIX32_ENV) || (defined(AFS_SUN55_ENV) && !defined(AFS_SUN56_ENV)) || !defined(HAVE_SNPRINTF)