[PATCH 4/4] include: Require winsock headers to be included before system headers.
Zebediah Figura
zfigura at codeweavers.com
Mon Jan 10 17:31:07 CST 2022
We have already started requiring WINELIB_USE_WINSOCK for this case; let's also
take the opportunity to remove some workarounds.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
include/winsock.h | 73 +++++++++-------------------------------------
include/winsock2.h | 58 ++++--------------------------------
2 files changed, 18 insertions(+), 113 deletions(-)
diff --git a/include/winsock.h b/include/winsock.h
index 4b8242e404d..38186f8c80d 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -32,53 +32,12 @@
#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.
- */
+# if defined(FD_CLR) || defined(RLIM_INFINITY)
+# error Include winsock.h before stdlib.h, time.h, or sys/types.h, or use the MSVCRT library
+# else
# define fd_set unix_fd_set
# define timeval unix_timeval
# define select unix_select
@@ -98,14 +57,13 @@
# 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 */
@@ -406,18 +364,15 @@ 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
-# endif
-# else
-# ifndef WS_FD_SETSIZE
-# define WS_FD_SETSIZE 64
-# endif
+#ifndef USE_WS_PREFIX
+# ifndef FD_SETSIZE
+# define FD_SETSIZE 64
# endif
+#else
+# ifndef WS_FD_SETSIZE
+# define WS_FD_SETSIZE 64
+# endif
+#endif
typedef struct WS(fd_set)
{
@@ -475,8 +430,6 @@ 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
diff --git a/include/winsock2.h b/include/winsock2.h
index 565979a74c0..0e6fa448570 100644
--- a/include/winsock2.h
+++ b/include/winsock2.h
@@ -27,53 +27,12 @@
#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.
- */
+# if defined(FD_CLR) || defined(RLIM_INFINITY)
+# error Include winsock2.h before stdlib.h, time.h, or sys/types.h, or use the MSVCRT library
+# else
# define fd_set unix_fd_set
# define timeval unix_timeval
# define select unix_select
@@ -93,14 +52,13 @@
# 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 */
@@ -562,8 +520,6 @@ typedef struct WS(timeval)
} TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
#endif
-#ifdef WS_DEFINE_SELECT
-
#define __WS_FD_CLR(fd, set, cast) do { \
unsigned int __i; \
for (__i = 0; __i < ((cast*)(set))->fd_count; __i++) \
@@ -626,8 +582,6 @@ typedef struct WS(fd_set)
SOCKET fd_array[WS(FD_SETSIZE)];
} WS(fd_set), FD_SET, *PFD_SET, *LPFD_SET;
-#endif
-
typedef struct /*WS(pollfd)*/
{
SOCKET fd;
@@ -1078,9 +1032,7 @@ typedef int (WINAPI *LPFN_GETHOSTNAME)(char*,int);
typedef int (WINAPI *LPFN_GETPEERNAME)(SOCKET,struct WS(sockaddr)*,int*);
typedef struct WS(protoent)* (WINAPI *LPFN_GETPROTOBYNAME)(const char*);
typedef struct WS(protoent)* (WINAPI *LPFN_GETPROTOBYNUMBER)(int);
-#ifdef WS_DEFINE_SELECT
typedef int (WINAPI* LPFN_SELECT)(int,WS(fd_set)*,WS(fd_set)*,WS(fd_set)*,const struct WS(timeval)*);
-#endif
typedef struct WS(servent)* (WINAPI *LPFN_GETSERVBYNAME)(const char*,const char*);
typedef struct WS(servent)* (WINAPI *LPFN_GETSERVBYPORT)(int,const char*);
typedef int (WINAPI *LPFN_GETSOCKNAME)(SOCKET,struct WS(sockaddr)*,int*);
--
2.34.1
More information about the wine-devel
mailing list