]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
sprintf portability fixes (thanks Paul!)
authorHarlan Stenn <stenn@ntp.org>
Wed, 30 Apr 2003 06:03:30 +0000 (02:03 -0400)
committerHarlan Stenn <stenn@ntp.org>
Wed, 30 Apr 2003 06:03:30 +0000 (02:03 -0400)
bk: 3eaf67320QLqEDKo9bk01x_laqQiHQ

configure.in
include/Makefile.am
include/ntp_sprintf.h [new file with mode: 0644]
libisc/inet_ntop.c
ntpd/refclock_mx4200.c

index d8d92d37416af46208bd749716eb1503344250a5..2c45cd37d458e654ad1cb28ee2e04d79814876ad 100644 (file)
@@ -762,6 +762,12 @@ case "$host" in
 esac
 AC_CHECK_FUNCS(uname updwtmp updwtmpx vsprintf)
 
+case "$host" in
+ *-*-sunos4*)
+    AC_DEFINE(SPRINTF_CHAR, 1, [*s*printf() functions are char*])
+    ;;
+esac
+
 AC_CACHE_CHECK(number of arguments to gettimeofday(), ac_cv_func_Xettimeofday_nargs,
 [AC_TRY_COMPILE([#include <sys/time.h>],[
 gettimeofday((struct timeval*)0,(struct timezone*)0);
index 9bb7da22b1268ba4528ba822676ebb93208e8fe6..f78f4e7ad2776bc96fe6652fc45b9f6e44c3f2c8 100644 (file)
@@ -40,6 +40,7 @@ noinst_HEADERS = \
        ntp_request.h \
        ntp_rfc2553.h \
        ntp_select.h \
+       ntp_sprintf.h \
        ntp_stdlib.h \
        ntp_string.h \
        ntp_syscall.h \
diff --git a/include/ntp_sprintf.h b/include/ntp_sprintf.h
new file mode 100644 (file)
index 0000000..a456a89
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Handle ancient char* *s*printf*() systems
+ */
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x)    strlen(sprintf/**/x)
+# define SNPRINTF(x)   strlen(snprintf/**/x)
+# define VSNPRINTF(x)  strlen(vsnprintf/**/x)
+#else
+# define SPRINTF(x)    ((size_t)sprintf x)
+# define SNPRINTF(x)   ((size_t)snprintf x)
+# define VSNPRINTF(x)  ((size_t)vsnprintf x)
+#endif
index 50677cdbc50431794584a52b8ec82384af5decd0..5a4845a1c75fb1508abd2b0b4a876a13e97f0db1 100644 (file)
@@ -28,6 +28,8 @@ static char rcsid[] =
 
 #include <isc/net.h>
 
+#include "ntp_sprintf.h"
+
 #define NS_INT16SZ      2
 #define NS_IN6ADDRSZ   16
 
@@ -175,7 +177,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
                        tp += strlen(tp);
                        break;
                }
-               tp += sprintf(tp, "%x", words[i]);
+               tp += SPRINTF((tp, "%x", words[i]));
        }
        /* Was it a trailing run of 0x00's? */
        if (best.base != -1 && (best.base + best.len) ==
index 7acb11b2de92ea72a138b7e4ce04e8a8dc4cab16..bc694ad0a69a834a26c6346d51ee95dedb6e24ad 100644 (file)
@@ -67,6 +67,8 @@
 # include <sys/ppsclock.h>
 #endif
 
+#include "ntp_sprintf.h"
+
 #ifndef HAVE_STRUCT_PPSCLOCKEV
 struct ppsclockev {
 # ifdef HAVE_STRUCT_TIMESPEC
@@ -1634,25 +1636,11 @@ mx4200_send(peer, fmt, va_alist)
 
        cp = buf;
        *cp++ = '$';
-#ifdef notdef
-       /* BSD is rational */
-       n = vsnprintf(cp, sizeof(buf) - 1, fmt, ap);
-#else
-       /* SunOS sucks */
-       (void)vsprintf(cp, fmt, ap);
-       n = strlen(cp);
-#endif /* notdef */
+       n = VSNPRINTF((cp, sizeof(buf) - 1, fmt, ap));
        ck = mx4200_cksum(cp, n);
        cp += n;
        ++n;
-#ifdef notdef
-       /* BSD is rational */
-       n += snprintf(cp, sizeof(buf) - n - 5, "*%02X\r\n", ck);
-#else
-       /* SunOS sucks */
-       sprintf(cp, "*%02X\r\n", ck);
-       n += strlen(cp);
-#endif /* notdef */
+       n += SNPRINTF((cp, sizeof(buf) - n - 5, "*%02X\r\n", ck));
 
        m = write(pp->io.fd, buf, (unsigned)n);
        if (m < 0)