From: Harlan Stenn Date: Wed, 30 Apr 2003 06:03:30 +0000 (-0400) Subject: sprintf portability fixes (thanks Paul!) X-Git-Tag: NTP_4_1_80_RC1~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b110d0d4f28d54ca10426c3887cd60010b27da5e;p=thirdparty%2Fntp.git sprintf portability fixes (thanks Paul!) bk: 3eaf67320QLqEDKo9bk01x_laqQiHQ --- diff --git a/configure.in b/configure.in index d8d92d374..2c45cd37d 100644 --- a/configure.in +++ b/configure.in @@ -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 ],[ gettimeofday((struct timeval*)0,(struct timezone*)0); diff --git a/include/Makefile.am b/include/Makefile.am index 9bb7da22b..f78f4e7ad 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..a456a8925 --- /dev/null +++ b/include/ntp_sprintf.h @@ -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 diff --git a/libisc/inet_ntop.c b/libisc/inet_ntop.c index 50677cdbc..5a4845a1c 100644 --- a/libisc/inet_ntop.c +++ b/libisc/inet_ntop.c @@ -28,6 +28,8 @@ static char rcsid[] = #include +#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) == diff --git a/ntpd/refclock_mx4200.c b/ntpd/refclock_mx4200.c index 7acb11b2d..bc694ad0a 100644 --- a/ntpd/refclock_mx4200.c +++ b/ntpd/refclock_mx4200.c @@ -67,6 +67,8 @@ # include #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)