winsock.h portability patch causing portability problem

Gerald Pfeifer pfeifer at dbai.tuwien.ac.at
Thu Apr 10 09:55:30 CDT 2003


On Wed, 9 Apr 2003, Alexandre Julliard wrote:
> Unfortunately Microsoft in their infinite wisdom decided to make the
> socket functions WINAPI, so we really need the right prototypes.

Ugh.

> The problem is that they are defined as macros on FreeBSD; we wouldn't
> need to override them in that case since there is no WINAPI issue with
> macros, but of course we don't know before including the file whether
> they will be macros or functions... I think the only solution would be
> to make our implementation use macros too, even though it's not the
> way Microsoft does it.

Thanks for the clear and detailed explanation, Alexandre!

I am not very proud of the patch below, but would that be an alternate
solution you could accept, giving your explanation above?  (I successfully
tested it on FreeBSD, and it shouldn't affect any other platform at all.)

Gerald

ChangeLog:
On FreeBSD, where htonl, htons, ntohl, and ntohs are macros, we won't have
issues with WINAP, so we can use the definitions provided by the system.

Index: include/winsock.h
===================================================================
RCS file: /home/wine/wine/include/winsock.h,v
retrieving revision 1.56
diff -u -3 -p -r1.56 winsock.h
--- include/winsock.h	9 Apr 2003 23:33:50 -0000	1.56
+++ include/winsock.h	10 Apr 2003 14:49:55 -0000
@@ -56,10 +56,16 @@
 #  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
-#  define htonl      Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define htons      Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define ntohl      Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
-#  define ntohs      Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
+/* In FreeBSD we get the following four from /usr/include/sys/types.h, where
+ * they are macros, so there is no issue with WINAPI and we can safely use the
+ * macros.
+ */
+#  ifndef __FreeBSD__
+#   define htonl     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
+#   define htons     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
+#   define ntohl     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
+#   define ntohs     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
+#  endif
 # 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
@@ -68,19 +74,23 @@
 #  define fd_set unix_fd_set
 #  define timeval unix_timeval
 #  define select unix_select
-#  define htonl unix_htonl
-#  define htons unix_htons
-#  define ntohl unix_ntohl
-#  define ntohs unix_ntohs
+#  ifndef __FreeBSD__
+#   define htonl unix_htonl
+#   define htons unix_htons
+#   define ntohl unix_ntohl
+#   define ntohs unix_ntohs
+#  endif
 #  include <sys/types.h>
 #  include <stdlib.h>
 #  undef fd_set
 #  undef timeval
 #  undef select
-#  undef htonl
-#  undef htons
-#  undef ntohl
-#  undef ntohs
+#  ifndef __FreeBSD__
+#   undef htonl
+#   undef htons
+#   undef ntohl
+#   undef ntohs
+#  endif
 #  undef FD_SETSIZE
 #  undef FD_CLR
 #  undef FD_SET
@@ -481,10 +491,12 @@ typedef struct WS(timeval)
 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (WS_fd_set*)(set))
 #endif

+#ifndef __FreeBSD__
 u_long WINAPI WS(htonl)(u_long);
 u_short WINAPI WS(htons)(u_short);
 u_long WINAPI WS(ntohl)(u_long);
 u_short WINAPI WS(ntohs)(u_short);
+#endif

 #endif /* WS_DEFINE_SELECT */




More information about the wine-devel mailing list