move #define strerror... to a header not used by lib/isc code.
bk: 4ad821abEAvaJXw9f4Y2NX2GJs6yvQ
+* [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
/* 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 */
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.
*/
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);
* 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 */
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);
}
/*
/* #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
#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 */
void
NTReportError(const char *, const char *);
-char *
-ntp_strerror(int);
-
#endif