]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Move rpl_vsnprintf() declaration and #define vsnprintf to config.h
authorDave Hart <hart@ntp.org>
Wed, 13 Apr 2011 01:02:31 +0000 (01:02 +0000)
committerDave Hart <hart@ntp.org>
Wed, 13 Apr 2011 01:02:31 +0000 (01:02 +0000)
bk: 4da4f627hFjJhyXmZKCX9S-KlRhdRw

include/l_stdlib.h
lib/isc/inet_ntop.c
libntp/msyslog.c
ports/winnt/include/config.h
ports/winnt/libntp/syslog.c
sntp/m4/ntp_libntp.m4
sntp/m4/snprintf.m4
tests/libntp/msyslog.cpp

index 7c787aff45b4110a2ad2ea69dd86221fb0184e02..073ea464123686bc20678efe9b9b5421a8a1a833 100644 (file)
@@ -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 *);
index febbfb35cc1f3d22120c7cf9a7fbf65e4915d453..3eee8feb7f6463f2fce480a19a2339c9ad9ea65b 100644 (file)
@@ -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);
index 7c9e904a5d4ec545cafa6ef2a43ebf6d1bc3495d..f2c38ed1dd3c8da76843c3b31eb3c96d9b866b59 100644 (file)
@@ -15,9 +15,9 @@
 #endif
 #include <stdio.h>
 
+#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;
index 4ffe3ea96c1bb7c521aa270f6e3b40bd97805324..45299fc6bdd54a6d03ff6c1a9e4d0ba2669ebe15 100644 (file)
@@ -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 <stdarg.h>
+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
 
index 6b82e924ed9df267d043c95cfbb3d9bddc234f87..71c90c237ec3f575b3caaec77f1bc941b60d2881 100644 (file)
@@ -28,6 +28,8 @@
 #include <isc/strerror.h>
 #include <lib_strbuf.h>
 
+#include "ntp_stdlib.h"
+
 #include "messages.h"
 
 static HANDLE hAppLog = NULL;
index 50c2a67381f4e51f0a5f8e947f24485c5f25a7d0..dbf43dfe0ad261bc9b0192bac44b23b584e0695f 100644 (file)
@@ -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 <stdio.h>     /* 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 <stdarg.h>
+       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
index ad1f5c70edff4581663eefd98e4ac34f0337d13d..34c092d10f74cd1ab1d9240b8222a7257dc53802 100644 (file)
@@ -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
index 491ad5ab189da321f3540850b17624b5427b8774..eddcfc50fdcd71f2f62a15ae961f390df2fd17b8 100644 (file)
@@ -2,6 +2,7 @@
 
 extern "C" {
 #include <stdio.h>
+#include <string.h>
 #include <errno.h>
 // format_errmsg() is normally private to msyslog.c
 void   format_errmsg   (char *, size_t, const char *, int);