Watt-32 tcp/ip  2.2 dev-rel.10
w32api.h
Go to the documentation of this file.
1 
5 #ifndef __SYS_W32API_H
6 #define __SYS_W32API_H
7 
8 #if !defined(_WATT32_FAKE_WINSOCK_H) && (defined(_WINSOCK_H) || defined(_WINSOCKAPI_))
9  #error Never include the real <winsock.h> in Watt-32 programs.
10  #error Change your include-path so the fake <winsock.h> gets included first.
11  #error E.g. add "-I$(WATT_ROOT)/inc -I-I$(WATT_ROOT)/inc/w32-fakes" to your CFLAGS.
12 #endif
13 
14 #if !defined(_WATT32_FAKE_WINSOCK2_H) && (defined(_WINSOCK2_H) || defined(_WINSOCK2API_))
15  #error Never include the real <winsock2.h> in Watt-32 programs.
16  #error Change your include-path so the fake <winsock2.h> gets included first.
17  #error E.g. add "-I$(WATT_ROOT)/inc -I-I$(WATT_ROOT)/inc/w32-fakes" to your CFLAGS.
18 #endif
19 
20 #if !defined(_WATT32_FAKE_WS2TCPIP_H) && defined(_WS2TCPIP_H)
21  #error Never include the real <ws2tcpip.h> in Watt-32 programs.
22  #error Change your include-path so the fake <ws2tcpip.h> gets included first.
23  #error E.g. add "-I$(WATT_ROOT)/inc -I-I$(WATT_ROOT)/inc/w32-fakes" to your CFLAGS.
24 #endif
25 
26 #if defined(__CYGWIN__)
27  #include <sys/time.h>
28  #if !defined(WIN32) && defined(WATT32_BUILD)
29  /* #error WIN32 should only be defined in wattcp.h or <windows.h> included before this point.
30  */
31  #endif
32 #endif
33 
40 #if defined(WATT32_NO_NAMESPACE)
41  #undef W32_NAMESPACE
42  #define W32_NAMESPACE(x)
43 #else
44  #ifndef W32_NAMESPACE
45  #define W32_NAMESPACE(x) _w32_ ## x
46  #endif
47 #endif
48 
49 
50 /*
51  * Watt-32 should never assume WIN32 (or _WIN32) is set for CygWin.
52  * It is not unless you include <windows.h> first (which we don't for CygWin).
53  */
54 #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && \
55  !defined(__CYGWIN__) /* && defined(WATT32_BUILD) */
56  /* Don't include the real <winsock*.h> */
57  #define _WINSOCKAPI_ /* MSVC/DMC/Watcom header guard names */
58  #define _WINSOCK2API_
59  #define _WINSOCK_H /* MingW header guard names */
60  #define _WINSOCK2_H
61  #ifndef WIN32_LEAN_AND_MEAN
62  #define WIN32_LEAN_AND_MEAN
63  #endif
64  #ifndef WATT32_ON_WINDOWS
65  #define WATT32_ON_WINDOWS
66  #endif
67 
68  /* This should be the only place <windows.h> is included for WIN32 targets. */
69  #include <windows.h>
70 #endif
71 
72 /*
73  * For Windows targets, we export functions and data prefixed with 'W32_FUNC'
74  * or 'W32_DATA'. Unless we use the static library of Watt-32 (./lib/libwatt32.a)
75  * Using the static lib requires the user to define 'WATT32_STATIC' in the CFLAGS.
76  *
77  * For non-Win32 targets the .\util\mkimp program (a small C-preprocessor)
78  * is meant to search all headers for W32_FUNC/W32_DATA prefixes. All
79  * functions with a W32_FUNC prefix will produce an export stub function.
80  * See dj_dxe.mak. Very experimental at the moment.
81  *
82  * \note: only a small subset of the Winsock extensions are implemented in
83  * watt-32.dll (hardly any WSA*() functions yet).
84  *
85  * \note: 'W32_CALL' is something else. It defines calling-convention
86  * Ref. <sys/cdefs.h>.
87  */
88 #if defined(WATT32_ON_WINDOWS) && !defined(WATT32_STATIC)
89  #if defined(WATT32_BUILD)
90  #define W32_FUNC extern __declspec(dllexport)
91  #define W32_DATA extern __declspec(dllexport)
92  #else
93  #define W32_FUNC extern __declspec(dllimport)
94  #define W32_DATA extern __declspec(dllimport)
95  #endif
96 #else
97  #define W32_FUNC extern
98  #define W32_DATA extern
99 #endif
100 
101 /*
102  * W32_CALL is *not* defined to `stdcall' due to a bug in MingW's
103  * linker. This bug prevents a MingW generated Watt-32.dll from
104  * being used by e.g. a MSVC program.
105  * Ref. http://sources.redhat.com/bugzilla/show_bug.cgi?id=351
106  * (last paragraph)
107  */
108 #if defined(WATT32_ON_WINDOWS)
109  #define W32_CALL __cdecl
110 #else
111  #define W32_CALL
112 #endif
113 
114 #endif /* __SYS_W32API_H */
115