From: Dave Hart Date: Wed, 13 Apr 2011 01:02:31 +0000 (+0000) Subject: Move rpl_vsnprintf() declaration and #define vsnprintf to config.h X-Git-Tag: NTP_4_2_7P150~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=856705e555227ab1628b2db4ff804c90a015a6b0;p=thirdparty%2Fntp.git Move rpl_vsnprintf() declaration and #define vsnprintf to config.h bk: 4da4f627hFjJhyXmZKCX9S-KlRhdRw --- diff --git a/include/l_stdlib.h b/include/l_stdlib.h index 7c787aff4..073ea4641 100644 --- a/include/l_stdlib.h +++ b/include/l_stdlib.h @@ -131,16 +131,6 @@ struct sigvec; extern int sigvec (int, struct sigvec *, struct sigvec *); #endif -#if HW_WANT_RPL_VSNPRINTF -#define vsnprintf rpl_vsnprintf -int rpl_vsnprintf(char *, size_t, const char *, va_list); -#endif - -#if HW_WANT_RPL_SNPRINTF -#define snprintf rpl_snprintf -int rpl_snprintf(char *, size_t, const char *, ...); -#endif - #ifdef DECL_STDIO_0 #if defined(FILE) || defined(BUFSIZ) extern int _flsbuf (int, FILE *); diff --git a/lib/isc/inet_ntop.c b/lib/isc/inet_ntop.c index febbfb35c..3eee8feb7 100644 --- a/lib/isc/inet_ntop.c +++ b/lib/isc/inet_ntop.c @@ -90,9 +90,8 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size) static const char *fmt = "%u.%u.%u.%u"; char tmp[sizeof("255.255.255.255")]; - /* NTP local change to use SNPRINTF() macro for SunOS4 compat */ - if (SNPRINTF((tmp, sizeof(tmp), fmt, src[0], src[1], src[2], - src[3])) >= size) + if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], + src[3]) >= size) { errno = ENOSPC; return (NULL); diff --git a/libntp/msyslog.c b/libntp/msyslog.c index 7c9e904a5..f2c38ed1d 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -15,9 +15,9 @@ #endif #include +#include "ntp_string.h" #include "ntp.h" #include "ntp_debug.h" -#include "ntp_string.h" #include "ntp_syslog.h" #ifdef SYS_WINNT @@ -40,6 +40,13 @@ extern char * progname; void addto_syslog (int, const char *); void format_errmsg (char *, size_t, const char *, int); +/* + * Work around misdetection by AC_FUNC_STRERROR_R on Debian Linux. + */ +#if defined(STRERROR_R_CHAR_P) && strerror_r == __xpg_strerror_r +# undef STRERROR_R_CHAR_P +#endif + /* * errno_to_str() - a thread-safe strerror() replacement. @@ -58,6 +65,7 @@ errno_to_str( # if defined(STRERROR_R_CHAR_P) || !HAVE_DECL_STRERROR_R char * pstatic; + buf[0] = '\0'; # ifdef STRERROR_R_CHAR_P /* * For older GNU strerror_r, the return value either points to @@ -67,7 +75,16 @@ errno_to_str( # else pstatic = strerror(err); # endif - if (pstatic != buf) + if (NULL == pstatic && '\0' == buf[0]) + snprintf(buf, bufsiz, "%s(%d): errno %d", +# ifdef STRERROR_R_CHAR_P + "strerror_r", +# else + "strerror", +# endif + err, errno); + /* protect against believing an int return is a pointer */ + else if (pstatic != buf && pstatic > (char *)bufsiz) strlcpy(buf, pstatic, bufsiz); # else int rc; diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 4ffe3ea96..45299fc6b 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -389,7 +389,12 @@ typedef __int32 int32_t; /* define a typedef for int32_t */ #define HAVE_BSD_NICE /* emulate BSD setpriority() */ #define HW_WANT_RPL_VSNPRINTF 1 +#define vsnprintf rpl_vsnprintf +#include +int rpl_vsnprintf(char *, size_t, const char *, va_list); #define HW_WANT_RPL_SNPRINTF 1 +#define snprintf rpl_snprintf +int rpl_snprintf(char *, size_t, const char *, ...); #define HAVE_VSNPRINTF 1 #define HAVE_SNPRINTF 1 diff --git a/ports/winnt/libntp/syslog.c b/ports/winnt/libntp/syslog.c index 6b82e924e..71c90c237 100644 --- a/ports/winnt/libntp/syslog.c +++ b/ports/winnt/libntp/syslog.c @@ -28,6 +28,8 @@ #include #include +#include "ntp_stdlib.h" + #include "messages.h" static HANDLE hAppLog = NULL; diff --git a/sntp/m4/ntp_libntp.m4 b/sntp/m4/ntp_libntp.m4 index 50c2a6738..dbf43dfe0 100644 --- a/sntp/m4/ntp_libntp.m4 +++ b/sntp/m4/ntp_libntp.m4 @@ -27,6 +27,7 @@ NTP_LIB_M AC_FUNC_FORK AC_FUNC_ALLOCA +AC_FUNC_STRERROR_R ac_busted_vpath_in_make=no case "$build" in @@ -279,7 +280,6 @@ case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in esac AC_TYPE_UID_T -AC_FUNC_STRERROR_R m4_divert_text([HELP_ENABLE], [AS_HELP_STRING([defaults:], @@ -455,27 +455,53 @@ AC_SUBST([LIBISC_PTHREADS_NOTHREADS]) AM_CONDITIONAL([PTHREADS], [test "$have_pthreads" != "no"]) AC_DEFUN([NTP_BEFORE_HW_FUNC_VSNPRINTF], [ -AC_BEFORE([$0], [HW_FUNC_VSNPRINTF]) -AC_BEFORE([$0], [HW_FUNC_SNPRINTF]) -AC_ARG_ENABLE( - [c99-snprintf], - [AS_HELP_STRING([--enable-c99-snprintf], [s force replacement])], - [force_c99_snprintf=$enableval], - [force_c99_snprintf=no] - ) -case "$force_c99_snprintf" in - yes) - hw_force_rpl_snprintf=yes - hw_force_rpl_vsnprintf=yes -esac -hw_nodef_snprintf=yes -hw_nodef_vsnprintf=yes + AC_BEFORE([$0], [HW_FUNC_VSNPRINTF])dnl + AC_BEFORE([$0], [HW_FUNC_SNPRINTF])dnl + AC_ARG_ENABLE( + [c99-snprintf], + [AS_HELP_STRING([--enable-c99-snprintf], [s force replacement])], + [force_c99_snprintf=$enableval], + [force_c99_snprintf=no] + ) + case "$force_c99_snprintf" in + yes) + hw_force_rpl_snprintf=yes + hw_force_rpl_vsnprintf=yes + esac + AH_TOP([ + #if !defined(_KERNEL) && !defined(PARSESTREAM) + # include /* before #define vsnprintf rpl_... */ + #endif + ]) + AH_BOTTOM([ + #if !defined(_KERNEL) && !defined(PARSESTREAM) + # if defined(HW_WANT_RPL_VSNPRINTF) + # if defined(__cplusplus) + extern "C" { + # endif + # include + int rpl_vsnprintf(char *, size_t, const char *, va_list); + # if defined(__cplusplus) + } + # endif + # endif + # if defined(HW_WANT_RPL_SNPRINTF) + # if defined(__cplusplus) + extern "C" { + # endif + int rpl_snprintf(char *, size_t, const char *, ...); + # if defined(__cplusplus) + } + # endif + # endif + #endif /* !defined(_KERNEL) && !defined(PARSESTREAM) */ + ]) ]) dnl end of AC_DEFUN of NTP_BEFORE_HW_FUNC_VSNPRINTF AC_DEFUN([NTP_C99_SNPRINTF], [ -AC_REQUIRE([NTP_BEFORE_HW_FUNC_VSNPRINTF]) -AC_REQUIRE([HW_FUNC_VSNPRINTF]) -AC_REQUIRE([HW_FUNC_SNPRINTF]) + AC_REQUIRE([NTP_BEFORE_HW_FUNC_VSNPRINTF])dnl + AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl + AC_REQUIRE([HW_FUNC_SNPRINTF])dnl ]) dnl end of DEFUN of NTP_C99_SNPRINTF NTP_C99_SNPRINTF diff --git a/sntp/m4/snprintf.m4 b/sntp/m4/snprintf.m4 index ad1f5c70e..34c092d10 100644 --- a/sntp/m4/snprintf.m4 +++ b/sntp/m4/snprintf.m4 @@ -7,12 +7,7 @@ # libopts to avoid their own replacement of snprintf. # # Changed to honor hw_nodef_snprintf, etc. which prevent config.h from -# aliasing snprintf to rpl_snprintf, etc. NTP uses this to defer that -# definition until after system include files to avoid problems seen -# on Linux building sntp/tests: -# /usr/include/c++/4.4/cstdio:165: error: '::snprintf' has not been declared -# This cstdio #undef's snprintf and then re-declares ::snprintf, however -# the earlier stdio.h had its declarations aliased to rpl_snprintf, etc. +# aliasing snprintf to rpl_snprintf, etc. # # Changed to honor hw_force_rpl_snprintf=yes, etc. This is used by NTP # to test rpl_snprintf() and rpl_vsnprintf() on platforms which provide diff --git a/tests/libntp/msyslog.cpp b/tests/libntp/msyslog.cpp index 491ad5ab1..eddcfc50f 100644 --- a/tests/libntp/msyslog.cpp +++ b/tests/libntp/msyslog.cpp @@ -2,6 +2,7 @@ extern "C" { #include +#include #include // format_errmsg() is normally private to msyslog.c void format_errmsg (char *, size_t, const char *, int);