[PATCH 2/4] include: Remove workarounds for using host headers without USE_WS_PREFIX.

Zebediah Figura z.figura12 at gmail.com
Sun Apr 25 15:39:05 CDT 2021


All modules either build with msvcrt headers or define USE_WS_PREFIX now.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/http.sys/http.c               |   1 +
 dlls/inetmib1/main.c               |   1 +
 dlls/ntdll/rtl.c                   |   1 +
 dlls/ntoskrnl.exe/tests/ntoskrnl.c |   1 +
 dlls/rpcrt4/rpcrt4_main.c          |   1 +
 dlls/ws2_32/tests/sock.c           |   5 --
 include/iphlpapi.h                 |  16 ++---
 include/winsock.h                  | 103 +----------------------------
 include/ws2tcpip.h                 |   6 +-
 programs/ipconfig/ipconfig.c       |   1 +
 10 files changed, 15 insertions(+), 121 deletions(-)

diff --git a/dlls/http.sys/http.c b/dlls/http.sys/http.c
index e655edfeea2..ab021b9d8eb 100644
--- a/dlls/http.sys/http.c
+++ b/dlls/http.sys/http.c
@@ -19,6 +19,7 @@
  */
 
 #include <assert.h>
+#include <stdlib.h>
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
 #include "wine/http.h"
diff --git a/dlls/inetmib1/main.c b/dlls/inetmib1/main.c
index 6345573350e..2aa8b43dc21 100644
--- a/dlls/inetmib1/main.c
+++ b/dlls/inetmib1/main.c
@@ -26,6 +26,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "snmp.h"
+#include "winsock2.h"
 #include "iphlpapi.h"
 #include "wine/debug.h"
 
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index cf21c980a45..04690e8fb06 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -24,6 +24,7 @@
  */
 
 #include <stdarg.h>
+#include <stdlib.h>
 
 #include "ntstatus.h"
 #define NONAMELESSUNION
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
index 9fe4cd03175..efab9a01f22 100644
--- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
@@ -22,6 +22,7 @@
  */
 
 #include <stdio.h>
+#include <time.h>
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
 #include "windows.h"
diff --git a/dlls/rpcrt4/rpcrt4_main.c b/dlls/rpcrt4/rpcrt4_main.c
index 57e33673c7a..6889bf131a0 100644
--- a/dlls/rpcrt4/rpcrt4_main.c
+++ b/dlls/rpcrt4/rpcrt4_main.c
@@ -42,6 +42,7 @@
 #include "winnt.h"
 #include "winternl.h"
 #include "ntsecapi.h"
+#include "winsock2.h"
 #include "iptypes.h"
 #include "iphlpapi.h"
 #include "rpc.h"
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 61af5b0183a..717c6264fc0 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -4147,11 +4147,6 @@ static void test_dns(void)
        "hostent->h_addr_list[0] should be in %p, it is in %p\n", addr.mem, h->h_addr_list[0]);
 }
 
-/* Our winsock headers don't define gethostname because it conflicts with the
- * definition in unistd.h. Define it here to get rid of the warning. */
-
-int WINAPI gethostname(char *name, int namelen);
-
 static void test_gethostbyname(void)
 {
     struct hostent *he;
diff --git a/include/iphlpapi.h b/include/iphlpapi.h
index da5819c8423..cd4bf50b39e 100644
--- a/include/iphlpapi.h
+++ b/include/iphlpapi.h
@@ -26,6 +26,12 @@ extern "C" {
 #include <ipexport.h>
 #include <iptypes.h>
 
+#ifdef USE_WS_PREFIX
+# define WS(x)    WS_##x
+#else
+# define WS(x)    x
+#endif
+
 #define NET_STRING_IPV4_ADDRESS           0x00000001
 #define NET_STRING_IPV4_SERVICE           0x00000002
 #define NET_STRING_IPV4_NETWORK           0x00000004
@@ -124,15 +130,7 @@ DWORD WINAPI GetUniDirectionalAdapterInfo(
 
 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex);
 
-#ifdef __WINE_WINSOCKAPI_STDLIB_H
-DWORD WINAPI GetBestInterfaceEx(
-#ifdef USE_WS_PREFIX
-    struct WS_sockaddr *pDestAddr,
-#else
-    struct sockaddr *pDestAddr,
-#endif
-    PDWORD pdwBestIfIndex);
-#endif
+DWORD WINAPI GetBestInterfaceEx(struct WS(sockaddr) *addr, DWORD *index);
 
 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr,
  PMIB_IPFORWARDROW   pBestRoute);
diff --git a/include/winsock.h b/include/winsock.h
index 1d33d573329..4b65c38da68 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -26,87 +26,6 @@
 # endif
 #endif
 
-#ifndef __WINE_WINSOCKAPI_STDLIB_H
-#define __WINE_WINSOCKAPI_STDLIB_H
-
-/*
- * This section defines the items that conflict with the Unix headers.
- */
-#ifndef USE_WS_PREFIX
-/* We are not using the WS_ prefix we risk getting conflicts for
- * everything related to select.
- */
-# ifdef FD_CLR
-/* Too late, the Unix version of stdlib.h was included before winsock.h.
- * This means select and all the related stuff is already defined and we
- * cannot override types and function prototypes.
- * All we can do is disable all these symbols so that they are not used
- * inadvertently.
- */
-#  include <sys/types.h>
-#  undef FD_SETSIZE
-#  undef FD_CLR
-#  undef FD_SET
-#  undef FD_ZERO
-#  undef FD_ISSET
-
-#  define FD_SETSIZE Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define FD_CLR     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define FD_SET     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define FD_ZERO    Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define FD_ISSET   Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define fd_set     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define select     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-# elif defined(RLIM_INFINITY)
-/* On Darwin stdlib.h includes sys/resource.h which defines timeval but not the fd_set macros */
-#  define fd_set unix_fd_set
-#  include <sys/types.h>
-#  include <time.h>
-#  include <stdlib.h>
-#  undef fd_set
-#  undef FD_SETSIZE
-#  undef FD_CLR
-#  undef FD_SET
-#  undef FD_ZERO
-#  undef FD_ISSET
-#  define select     Include_winsock_h_before_sys_types_h_or_use_the_MSVCRT_library
-#  define timeval    Include_winsock_h_before_sys_types_h_or_use_the_MSVCRT_library
-# else  /* FD_CLR */
-/* stdlib.h has not been included yet so it's not too late. Include it now
- * making sure that none of the select symbols is affected. Then we can
- * define them with our own values.
- */
-#  define fd_set unix_fd_set
-#  define timeval unix_timeval
-#  define select unix_select
-#  define socklen_t unix_socklen_t
-#  define u_long unix_u_long
-#  include <sys/types.h>
-#  include <time.h>
-#  include <stdlib.h>
-#  undef fd_set
-#  undef timeval
-#  undef select
-#  undef socklen_t
-#  undef u_long
-#  undef FD_SETSIZE
-#  undef FD_CLR
-#  undef FD_SET
-#  undef FD_ZERO
-#  undef FD_ISSET
-#  undef _TIMEVAL_DEFINED
-
-#  define WS_DEFINE_SELECT
-# endif /* FD_CLR */
-
-#else
-# define WS_DEFINE_SELECT
-# include <sys/types.h>
-# include <stdlib.h>
-#endif /* !USE_WS_PREFIX */
-
-#endif /* __WINE_WINSOCKAPI_STDLIB_H */
-
 #include <windows.h>
 
 #ifndef _WINSOCKAPI_
@@ -408,9 +327,6 @@ typedef struct WS(linger)
  * Select
  */
 
-#ifdef WS_DEFINE_SELECT
-/* Define our own version of select and the associated types and macros */
-
 # ifndef USE_WS_PREFIX
 #  ifndef FD_SETSIZE
 #   define FD_SETSIZE              64
@@ -431,14 +347,11 @@ typedef struct WS(fd_set)
 # endif
 } WS(fd_set), FD_SET, *PFD_SET, *LPFD_SET;
 
-#ifndef _TIMEVAL_DEFINED
-#define _TIMEVAL_DEFINED
 typedef struct WS(timeval)
 {
     LONG    tv_sec;                /* seconds */
     LONG    tv_usec;               /* and microseconds */
 } TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
-#endif
 
 #define __WS_FD_CLR(fd, set, cast) do { \
     unsigned int __i; \
@@ -498,16 +411,8 @@ typedef struct WS(timeval)
 
 int WINAPI __WSAFDIsSet(SOCKET,WS(fd_set)*);
 
-#endif /* WS_DEFINE_SELECT */
-
-/* we have to define hton/ntoh as macros to avoid conflicts with Unix headers */
 #ifndef USE_WS_PREFIX
 
-#undef htonl
-#undef htons
-#undef ntohl
-#undef ntohs
-
 #ifdef WORDS_BIGENDIAN
 
 static inline u_short __wine_ushort_noop(u_short s)
@@ -1020,12 +925,11 @@ int WINAPI WS(closesocket)(SOCKET);
 int WINAPI WS(connect)(SOCKET,const struct WS(sockaddr)*,int);
 struct WS(hostent)* WINAPI WS(gethostbyaddr)(const char*,int,int);
 struct WS(hostent)* WINAPI WS(gethostbyname)(const char*);
+int WINAPI WS(gethostname)(char*,int);
 int WINAPI WS(getpeername)(SOCKET,struct WS(sockaddr)*,int*);
 struct WS(protoent)* WINAPI WS(getprotobyname)(const char*);
 struct WS(protoent)* WINAPI WS(getprotobynumber)(int);
-#ifdef WS_DEFINE_SELECT
 int WINAPI WS(select)(int,WS(fd_set)*,WS(fd_set)*,WS(fd_set)*,const struct WS(timeval)*);
-#endif
 struct WS(servent)* WINAPI WS(getservbyname)(const char*,const char*);
 struct WS(servent)* WINAPI WS(getservbyport)(int,const char*);
 int WINAPI WS(getsockname)(SOCKET,struct WS(sockaddr)*,int*);
@@ -1042,11 +946,6 @@ int WINAPI WS(setsockopt)(SOCKET,int,int,const char*,int);
 int WINAPI WS(shutdown)(SOCKET,int);
 SOCKET WINAPI WS(socket)(int,int,int);
 
-#if defined(__MINGW32__) || defined (_MSC_VER) || defined(__WINE_USE_MSVCRT)
-/* gethostname is not defined on Unix because of conflicts with unistd.h */
-int WINAPI WS(gethostname)(char*,int);
-#endif
-
 #endif /* !defined(__WINE_WINSOCK2__) || WS_API_PROTOTYPES */
 
 #ifdef __cplusplus
diff --git a/include/ws2tcpip.h b/include/ws2tcpip.h
index 5ba891185b5..19f4ec22941 100644
--- a/include/ws2tcpip.h
+++ b/include/ws2tcpip.h
@@ -58,11 +58,7 @@ typedef struct WS(addrinfoW)
 typedef WINELIB_NAME_AW(ADDRINFO) ADDRINFOT, *PADDRINFOT;
 #endif
 
-#ifdef USE_WS_PREFIX
-typedef int WS_socklen_t;
-#else
-#define socklen_t int  /* avoid conflicts with the system's socklen_t typedef */
-#endif
+typedef int WS(socklen_t);
 
 typedef ADDRINFOA ADDRINFO, *LPADDRINFO;
 
diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/ipconfig.c
index a056771128c..cd9069cd59e 100644
--- a/programs/ipconfig/ipconfig.c
+++ b/programs/ipconfig/ipconfig.c
@@ -22,6 +22,7 @@
 #define NONAMELESSUNION
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <winsock2.h>
 #include <windows.h>
 #include <iphlpapi.h>
-- 
2.30.2




More information about the wine-devel mailing list