]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1339] redux, use unmodified lib/isc/win32/strerror.c and
authorDave Hart <hart@ntp.org>
Fri, 16 Oct 2009 07:32:59 +0000 (07:32 +0000)
committerDave Hart <hart@ntp.org>
Fri, 16 Oct 2009 07:32:59 +0000 (07:32 +0000)
  move #define strerror... to a header not used by lib/isc code.

bk: 4ad821abEAvaJXw9f4Y2NX2GJs6yvQ

ChangeLog
include/ntp_stdlib.h
lib/isc/win32/strerror.c
ports/winnt/include/config.h
ports/winnt/include/syslog.h

index eacfbcaf9d36bc54d2dff605764cbaf0b12b93bb..c8e2025db17ac48c12ed056ea17bf60f3b42ca40 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* [Bug 1339] redux, use unmodified lib/isc/win32/strerror.c and
+  move #define strerror... to a header not used by lib/isc code.
 (4.2.5p233-RC) 2009/10/15 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1337] cast setsockopt() v4 address pointer to void *.
 * [Bug 1342] ignore|drop one IPv6 address on an interface blocks all
index 35912286cbf6a56767efd570c6598e1a5bc6414f..840c80cc0dfc3f7e04c32fcb751eada504e86332 100644 (file)
@@ -142,9 +142,18 @@ extern int ipv6_works;
 /* machines.c */
 extern const char *set_tod_using;
 
-/* mexit.c */
-#if defined SYS_WINNT || defined SYS_CYGWIN32
-extern HANDLE  hServDoneEvent;
+/* lib/isc/win32/strerror.c
+ *
+ * To minimize Windows-specific changes to the rest of the NTP code,
+ * particularly reference clocks, we hijack calls to strerror() to deal
+ * with our mixture of error codes from the  C runtime (open, write)
+ * and Windows (sockets, serial ports).  This is an ugly hack because
+ * both use the lowest values differently, but particularly for ntpd,
+ * it's not a problem.
+ */
+#ifdef NTP_REDEFINE_STRERROR
+#define        strerror(e)     ntp_strerror(e)
+extern char *  ntp_strerror    (int e);
 #endif
 
 /* systime.c */
index dec60f04729b89c1a9df6214b9614accfba5fff0..41743328a430dcc2bddd199685c6bb8586d65a30 100644 (file)
@@ -42,13 +42,6 @@ GetWSAErrorMessage(int errval);
 char *
 NTstrerror(int err, BOOL *bfreebuf);
 
-/*
- * ntp ports/winnt/include/config.h #defines strerror() to
- * ntp_strerror() to handle OS errors as well as CRT.  We need the
- * CRT strerror() here so #undef.
- */
-#undef strerror
-
 /*
  * We need to do this this way for profiled locks.
  */
@@ -81,7 +74,7 @@ isc__strerror(int num, char *buf, size_t size) {
                snprintf(buf, size, "%s", msg);
        else
                snprintf(buf, size, "Unknown error: %u", unum);
-       if (freebuf && msg != NULL) {
+       if(freebuf && msg != NULL) {
                LocalFree(msg);
        }
        UNLOCK(&isc_strerror_lock);
@@ -117,9 +110,12 @@ FormatError(int error) {
  * since those messages are not available in the system error messages.
  */
 char *
-NTstrerror(int errval, BOOL *bfreebuf) {
+NTstrerror(int err, BOOL *bfreebuf) {
        char *retmsg = NULL;
 
+       /* Copy the error value first in case of other errors */        
+       DWORD errval = err; 
+
        *bfreebuf = FALSE;
 
        /* Get the Winsock2 error messages */
@@ -128,20 +124,16 @@ NTstrerror(int errval, BOOL *bfreebuf) {
                if (retmsg != NULL)
                        return (retmsg);
        }
-
-       retmsg = strerror(errval);
-
        /*
         * If it's not one of the standard Unix error codes,
         * try a system error message
         */
-       if (retmsg == NULL) {
-               retmsg = FormatError(errval);
-               if (retmsg != NULL)
-                       *bfreebuf = TRUE;
+       if (errval > (DWORD) _sys_nerr) {
+               *bfreebuf = TRUE;
+               return (FormatError(errval));
+       } else {
+               return (strerror(errval));
        }
-
-       return (retmsg);
 }
 
 /*
index ec4733f95c397149a95d4d829dc9928999c7136a..d67968b3b998f42bf66465040136da8365cb1f71 100644 (file)
 /* #define MALLOC_LINT */      /* defers free() */
 #endif
 
-/*
- * We need to include string.h first before we override strerror
- * otherwise we can get errors during the build
- */
-#include <string.h>
-
 /*
  * We need to include stdio.h first before we #define snprintf
  * otherwise we can get errors during the build
@@ -290,8 +284,18 @@ typedef __int32 int32_t;   /* define a typedef for int32_t */
 #define STDOUT_FILENO  _fileno(stdout)
 #define STDERR_FILENO  _fileno(stderr)
 
-/* Point to a local version for error string handling */
-#define        strerror(e)     ntp_strerror(e)
+/*
+ * To minimize Windows-specific changes to the rest of the NTP code,
+ * particularly reference clocks, ntp_stdlib.h will
+ *
+ * #define strerror(e) ntp_strerror(e)
+ *
+ * to deal with our mixture of C runtime (open, write) and Windows
+ * (sockets, serial ports) error codes.  This is an ugly hack because
+ * both use the lowest values differently, but particularly for ntpd,
+ * it's not a problem.
+ */
+#define NTP_REDEFINE_STRERROR
 
 # define MCAST                         /* Enable Multicast Support */
 # define MULTICAST_NONEWSOCKET         /* Don't create a new socket for mcast address */
index e4fe166e0994b619d111bf58e3ea483317c493b6..5cbf30a00a13acafb503d5a37d966d35e033963b 100644 (file)
@@ -79,7 +79,4 @@ InitNTLogging(FILE *, int);
 void
 NTReportError(const char *, const char *);
 
-char *
-ntp_strerror(int);
-
 #endif