]> git.pond.sub.org Git - empserver/commitdiff
w32: Modernize for MinGW 6.0.0, and clean up
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 27 Jan 2021 07:20:05 +0000 (08:20 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 13 Feb 2021 18:25:18 +0000 (19:25 +0100)
We provide gettimeofday() only #ifdef _MSC_VER, but declare it
unconditionally in our own sys/time.h.  This is asking for trouble.
Declare it only #ifdef _MSC_VER, else pull in MinGW's sys/time.h with
#include_next.

Likewise, define macros ftruncate(), S_IRUSR & friends in our own
unistd.h only #ifdef _MSC_VER, else pull in MinGW's unistd.h with
#include_next.  The #include <getopt.h> is now useless, drop.

src/lib/commands/info.c relies on sys/time.h including windows.h.
Unclean, and no longer the case with MinGW.  Include it directly.

MinGW provides EWOULDBLOCK.  Drop our replacement.

MinGW provides inet_ntop() in ws2tcpip.h, but only if feature test
macro _WIN32_WINNT >= 0x600, i.e. Windows Vista or later.  It defaults
to 0x0502 (Windows Server 2003).  Make configure #define _WIN32_WINNT
0x0601 in config.h.  This requests Windows 7.  Trying to support Vista
feels unwise.  Include ws2tcpip.h, and drop our replacement.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
m4/my_windows_api.m4
src/lib/commands/info.c
src/lib/w32/arpa/inet.h
src/lib/w32/getrusage.c
src/lib/w32/sys/time.h
src/lib/w32/unistd.h
src/lib/w32/w32misc.h
src/lib/w32/w32sockets.c

index 63a2af622a4c48dd9fb12a9d8470ce7c92a8f21b..7bcabfc6f0f95f658742f817e8bf80371d5d5baa 100644 (file)
@@ -12,6 +12,8 @@ AC_DEFUN([MY_WINDOWS_API],
                AC_DEFINE([WINDOWS], 1, [Define if compiling for Windows API])
                AC_DEFINE([WIN32_LEAN_AND_MEAN], 1,
                        [Define to make Windows includes pull in less junk])
                AC_DEFINE([WINDOWS], 1, [Define if compiling for Windows API])
                AC_DEFINE([WIN32_LEAN_AND_MEAN], 1,
                        [Define to make Windows includes pull in less junk])
+               AC_DEFINE([_WIN32_WINNT], 0x0601,
+                       [Request Windows 7])
                LIBS_SOCKETS="-lws2_32"
        else
                LIBS_SOCKETS=
                LIBS_SOCKETS="-lws2_32"
        else
                LIBS_SOCKETS=
index 39842159e69ab7ea8da2991c9c5a9da77ead128c..0cac8d159880fdd7d1ec5887bb4b80a0b56434ee 100644 (file)
@@ -40,7 +40,9 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>
 #include <stdio.h>
-#if !defined(_WIN32)
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <strings.h>
 #include <dirent.h>
 #endif
 #include <strings.h>
 #include <dirent.h>
 #endif
index 97a19a4ce7191faf6f26502f3ddc528abe9ef012..de78f4340309df00b64a2fad01174e9e5a5189bf 100644 (file)
@@ -33,9 +33,6 @@
 #ifndef ARPA_INET_H
 #define ARPA_INET_H
 
 #ifndef ARPA_INET_H
 #define ARPA_INET_H
 
-#include "sys/socket.h"
-
-extern const char *inet_ntop(int af, const void *src, char *dst,
-                            socklen_t cnt);
+#include "ws2tcpip.h"
 
 #endif /* ARPA_INET_H */
 
 #endif /* ARPA_INET_H */
index 4a657aa205b8bf20737706ff85609e5ebdc20855..8c3a0bbce80fe26c2bb2b11c3ea1ed9b257d440f 100644 (file)
@@ -33,7 +33,7 @@
 
 #include <config.h>
 
 
 #include <config.h>
 
-#include <errno.h>
+#include <windows.h>
 #include "sys/resource.h"
 
 int
 #include "sys/resource.h"
 
 int
index cdc6b67b5d155c14818c8bbe4f98c2e0e8e06d83..4e3c12445bf973badf708c6d5dfe15b74f1a7a46 100644 (file)
 #ifndef SYS_TIME_H
 #define SYS_TIME_H
 
 #ifndef SYS_TIME_H
 #define SYS_TIME_H
 
+#ifdef _MSC_VER
+
 /* include winsock2.h thru sys/socket.h to get struct timeval */
 #include "sys/socket.h"
 
 extern int gettimeofday(struct timeval *tv, void *tz);
 
 /* include winsock2.h thru sys/socket.h to get struct timeval */
 #include "sys/socket.h"
 
 extern int gettimeofday(struct timeval *tv, void *tz);
 
+#else  /* !_MSC_VER */
+#include_next <sys/time.h>
+#endif
+
 #endif /* SYS_TIME_H */
 #endif /* SYS_TIME_H */
index 2e24d49eb2b3adb6dc6f70a106ce708881f6b815..8e594ad8517bc37629c79e54bc14d75a2f515c29 100644 (file)
@@ -46,7 +46,6 @@
  * here.  Major name space pollution, can't be helped.
  */
 #include <direct.h>
  * here.  Major name space pollution, can't be helped.
  */
 #include <direct.h>
-#include <getopt.h>
 #include <io.h>
 #include <process.h>
 #include <sys/stat.h>
 #include <io.h>
 #include <process.h>
 #include <sys/stat.h>
@@ -60,6 +59,7 @@
 extern int w32_mkdir(const char *dirname, mode_t perm);
 
 /* Should be in sys/stat.h */
 extern int w32_mkdir(const char *dirname, mode_t perm);
 
 /* Should be in sys/stat.h */
+#ifdef _MSC_VER
 #ifndef S_IRUSR
 #define S_IRUSR            _S_IREAD
 #define S_IWUSR            _S_IWRITE
 #ifndef S_IRUSR
 #define S_IRUSR            _S_IREAD
 #define S_IWUSR            _S_IWRITE
@@ -78,22 +78,28 @@ extern int w32_mkdir(const char *dirname, mode_t perm);
 #define S_IXOTH            0
 #define S_IRWXO            S_IROTH | S_IWOTH | S_IXOTH
 #endif
 #define S_IXOTH            0
 #define S_IRWXO            S_IROTH | S_IWOTH | S_IXOTH
 #endif
+#endif
 
 /* Should be in fcntl.h */
 
 /* Should be in fcntl.h */
+/* HACK, for use with fcntl() on a socket only, see w32sockets.c */
 #define O_NONBLOCK  1
 #define O_NONBLOCK  1
-
 #define F_GETFL            1
 #define F_SETFL            2
 #define F_GETFL            1
 #define F_SETFL            2
-
 extern int fcntl(int fd, int cmd, ...);
 
 /* Stuff that actually belongs here */
 #define close(fd) w32_close_function((fd))
 extern int (*w32_close_function)(int);
 extern int fcntl(int fd, int cmd, ...);
 
 /* Stuff that actually belongs here */
 #define close(fd) w32_close_function((fd))
 extern int (*w32_close_function)(int);
-#define ftruncate(fd, length) _chsize((fd), (length))
 #define read(fd, buf, sz) w32_read_function((fd), (buf), (sz))
 extern int (*w32_read_function)(int, void *, unsigned);
 #define write(fd, buf, sz) w32_write_function((fd), (buf), (sz))
 extern int (*w32_write_function)(int, const void *, unsigned);
 #define read(fd, buf, sz) w32_read_function((fd), (buf), (sz))
 extern int (*w32_read_function)(int, void *, unsigned);
 #define write(fd, buf, sz) w32_write_function((fd), (buf), (sz))
 extern int (*w32_write_function)(int, const void *, unsigned);
+#ifdef _MSC_VER
+#define ftruncate(fd, length) _chsize((fd), (length))
+#endif
+
+#ifndef _MSC_VER
+#include_next <unistd.h>
+#endif
 
 #endif /* UNISTD_H */
 
 #endif /* UNISTD_H */
index 8a27a384e9b40c9d4db6151b2bc20ed214e4a8ee..fb33466823125c00419d3345071bced0383d34c5 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2007
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2007
- *     Markus Armbruster, 2007-2013
+ *     Markus Armbruster, 2007-2021
  */
 
 /*
  */
 
 /*
 #ifdef _MSC_VER
 /* integral mismatch, due to misuse of sector short */
 #pragma warning (disable : 4761 )
 #ifdef _MSC_VER
 /* integral mismatch, due to misuse of sector short */
 #pragma warning (disable : 4761 )
+#endif
 
 /* strings.h */
 
 /* strings.h */
+#ifdef _MSC_VER
 #define strncasecmp(s1, s2, s3) _strnicmp((s1), (s2), (s3))
 #endif /* _MSC_VER */
 
 #define strncasecmp(s1, s2, s3) _strnicmp((s1), (s2), (s3))
 #endif /* _MSC_VER */
 
-/* errno.h */
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK EAGAIN
-#endif
-
 /* fcntl.h */
 #ifdef _MSC_VER
 #define O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
 /* fcntl.h */
 #ifdef _MSC_VER
 #define O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
index 3d80a2dae8a4e125f258f3ad26864673f33b9ab1..f1c36ccefacad868010bd03d6b71eecd6158b651 100644 (file)
@@ -232,43 +232,6 @@ w32_socket(int domain, int type, int protocol)
     return W32_SOCKET_TO_FD(sock);
 }
 
     return W32_SOCKET_TO_FD(sock);
 }
 
-#ifdef HAVE_GETADDRINFO
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t len)
-{
-    struct sockaddr *sa;
-    struct sockaddr_in sin;
-    struct sockaddr_in6 sin6;
-    size_t salen;
-
-    if (af == AF_INET) {
-       memset(&sin, 0, sizeof(sin));
-       sin.sin_family = af;
-       memcpy(&sin.sin_addr, src, sizeof(sin.sin_addr));
-       sa = (struct sockaddr *)&sin;
-       salen = sizeof(sin);
-    } else if (af == AF_INET6) {
-       memset(&sin6, 0, sizeof(sin6));
-       sin6.sin6_family = af;
-       memcpy(&sin6.sin6_addr, src, sizeof(sin6.sin6_addr));
-       sa = (struct sockaddr *)&sin6;
-       salen = sizeof(sin6);
-    } else {
-       WSASetLastError(WSAEAFNOSUPPORT);
-       w32_set_winsock_errno();
-       return NULL;
-    }
-
-    if (getnameinfo(sa, salen, dst, len, NULL, 0, NI_NUMERICHOST)) {
-       WSASetLastError(WSAEAFNOSUPPORT);
-       w32_set_winsock_errno();
-       return NULL;
-    }
-
-    return dst;
-}
-#endif
-
 /*
  * POSIX equivalent for fcntl().
  * Horrible hacks, just good enough support Empire's use of fcntl().
 /*
  * POSIX equivalent for fcntl().
  * Horrible hacks, just good enough support Empire's use of fcntl().