winsock.h vs. unistd.h

Francois Gouget fgouget at
Sun Feb 17 15:06:10 CST 2002

   Here's a patch that takes care of the current winsock.h vs. unistd.h
   I am only half happy with it as it means that winsock.h will
include unistd.h if you have not done so already. This is the only way I
see to support both

#include <unistd.h>
#include <windows.h>
#include <windows.h>
#include <unistd.h>

   If the patch is modified to handle only the first case, then
winsock.h does not need to include 'unistd.h'.

Index: include/winsock.h
RCS file: /home/wine/wine/include/winsock.h,v
retrieving revision 1.39
diff -u -r1.39 winsock.h
--- include/winsock.h	2002/01/29 02:55:41	1.39
+++ include/winsock.h	2002/02/17 18:53:38
@@ -63,6 +63,26 @@
 #endif /* __WINE_USE_MSVCRT */

+#ifndef USE_WS_PREFIX
+/* One cannot include both winsock.h and unistd.h because their definition
+ * of gethostname() conflicts. This is normally not a problem in Winelib
+ * applications because unistd.h does not exist on Windows and thus Windows
+ * source code should not use unistd.h.
+ * But there are still situations where one may want to use both so we are
+ * taking some specific steps to avoid problems.
+ */
+# ifdef R_OK
+/* unistd.h has already been defined */
+#  define gethostname You_should_not_include_unistd_h
+# else
+#  define gethostname unix_gethostname
+#  include <unistd.h>
+#  undef gethostname
+# endif /* R_OK */
+#endif /* USE_WS_PREFIX */

@@ -898,7 +918,9 @@
 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);

Francois Gouget         fgouget at
In theory, theory and practice are the same, but in practice they're different.

More information about the wine-devel mailing list