From: Dave Hart Date: Fri, 16 Oct 2009 07:32:59 +0000 (+0000) Subject: [Bug 1339] redux, use unmodified lib/isc/win32/strerror.c and X-Git-Tag: NTP_4_2_5P234_RC~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61ed83f7fa0da9783b8f7e4a840008811ce81f6a;p=thirdparty%2Fntp.git [Bug 1339] redux, use unmodified lib/isc/win32/strerror.c and move #define strerror... to a header not used by lib/isc code. bk: 4ad821abEAvaJXw9f4Y2NX2GJs6yvQ --- diff --git a/ChangeLog b/ChangeLog index eacfbcaf9..c8e2025db 100644 --- 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 * [Bug 1337] cast setsockopt() v4 address pointer to void *. * [Bug 1342] ignore|drop one IPv6 address on an interface blocks all diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index 35912286c..840c80cc0 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -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 */ diff --git a/lib/isc/win32/strerror.c b/lib/isc/win32/strerror.c index dec60f047..41743328a 100644 --- a/lib/isc/win32/strerror.c +++ b/lib/isc/win32/strerror.c @@ -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); } /* diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index ec4733f95..d67968b3b 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -37,12 +37,6 @@ /* #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 - /* * 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 */ diff --git a/ports/winnt/include/syslog.h b/ports/winnt/include/syslog.h index e4fe166e0..5cbf30a00 100644 --- a/ports/winnt/include/syslog.h +++ b/ports/winnt/include/syslog.h @@ -79,7 +79,4 @@ InitNTLogging(FILE *, int); void NTReportError(const char *, const char *); -char * -ntp_strerror(int); - #endif