htonl & co conflict on FreeBSD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




   We get conflicts when using winsock.h in a Winelib application on
FreeBSD (and we're not using the msvcrt headers). The reason is that we
include 'sys/types.h' which includes /usr/include/machine/endian.h which
defines prototypes and macros for htonl and friends.
   Two consequences:
 * when the time comes to define our own prototypes the macros get
expanded and wreak havoc
 * if we dodge the macros, we get into trouble because the prototypes
are incompatible (cdecl vs. stdcall)

   We cannot dodge this one like we do for stdlib.h either because of
the macros: #define htonl unix_htonl just causes tons of ugly 'htonl
macros redefined' warnings.

   But in fact we should be able to use the definitions provided by the
FreeBSD headers: they all do the same things anyway. And since macros
are defined, the functions will never get called, so the calling
convention difference should not matter.
   So we include sys/types.h and simply avoid defining htonl and friends
if we notice that the corresponding macros are defined.


Changelog:

 * include/winsock.h
   Avoid conflict with htonl & friends in Winelib on FreeBSD



--
Francois Gouget         fgouget@free.fr        http://fgouget.free.fr/
 Advice is what we ask for when we already know the answer but wish we didn't
                                 -- Eric Jong
Index: include/winsock.h
===================================================================
RCS file: /home/wine/wine/include/winsock.h,v
retrieving revision 1.38
diff -u -r1.38 winsock.h
--- include/winsock.h	2001/12/14 22:48:38	1.38
+++ include/winsock.h	2002/01/27 06:19:02
@@ -42,10 +42,16 @@
  */
 
 #ifndef __WINE_USE_MSVCRT
-/* Get the u_xxx types from the Unix headers. They will do and 
- * doing it this way will avoid redefinitions.
+/* Get the u_xxx types from the Unix headers. They will do and doing it 
+ * this way will avoid redefinitions. But on FreeBSD we may get macros 
+ * and prototypes for htonl & co. This means the functions will not be 
+ * called because of the macros. So this should not harm us too much unless 
+ * we try to define our own prototypes (different calling convention).
  */
 # include <sys/types.h>
+# ifndef htonl
+#  define WS_DEFINE_HTONL
+# endif /* htonl */
 #else
 /* Since we are using the MSVCRT headers, we must define the u_xxx 
  * types ourselves.
@@ -54,6 +60,7 @@
 typedef unsigned char u_short;
 typedef unsigned int  u_int;
 typedef unsigned long u_long;
+# define WS_DEFINE_HTONL
 #endif /* __WINE_USE_MSVCRT */
 
 
@@ -902,14 +909,10 @@
 struct WS(servent)* WINAPI WS(getservbyport)(int,const char*);
 int WINAPI WS(getsockname)(SOCKET,struct WS(sockaddr)*,int*);
 int WINAPI WS(getsockopt)(SOCKET,int,int,char*,int*);
-u_long WINAPI WS(htonl)(u_long);
-u_short WINAPI WS(htons)(u_short);
 unsigned long WINAPI WS(inet_addr)(const char*);
 char* WINAPI WS(inet_ntoa)(struct WS(in_addr));
 int WINAPI WS(ioctlsocket)(SOCKET,long,u_long*);
 int WINAPI WS(listen)(SOCKET,int);
-u_long WINAPI WS(ntohl)(u_long);
-u_short WINAPI WS(ntohs)(u_short);
 int WINAPI WS(recv)(SOCKET,char*,int,int);
 int WINAPI WS(recvfrom)(SOCKET,char*,int,int,struct WS(sockaddr)*,int*);
 int WINAPI WS(send)(SOCKET,const char*,int,int);
@@ -918,6 +921,12 @@
 int WINAPI WS(shutdown)(SOCKET,int);
 SOCKET WINAPI WS(socket)(int,int,int);
 
+#ifdef WS_DEFINE_HTONL
+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
 
 #if defined(__WINE__) || !defined(__WINE_WINSOCK2__)
 /* Stuff specific to winsock.h */

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux