diff options
author | David <david@xagasoft.com> | 2008-10-27 16:07:50 +0000 |
---|---|---|
committer | David <david@xagasoft.com> | 2008-10-27 16:07:50 +0000 |
commit | 61edfe804eb1a1dbf96fcdf2f1b700ed1cfa7ff9 (patch) | |
tree | 530a0d86ca1043dbc04cd7513bc5dd65768a266d /src/win32_compatibility.cpp | |
parent | f7e8658f2274044bb452492b1af7e2cd5f82082c (diff) | |
download | libbu++-61edfe804eb1a1dbf96fcdf2f1b700ed1cfa7ff9.tar.gz libbu++-61edfe804eb1a1dbf96fcdf2f1b700ed1cfa7ff9.tar.bz2 libbu++-61edfe804eb1a1dbf96fcdf2f1b700ed1cfa7ff9.tar.xz libbu++-61edfe804eb1a1dbf96fcdf2f1b700ed1cfa7ff9.zip |
david - apparently windows prefers to dynamically load winsock and a couple other libraries, so I got it all compiling and working in windows, yay!... I tried to minimize the impact on the code: I made a DYNLOAD macro that evaluates to nothing on everything else, but runs the dynamic code if compiled for windows... also, apparently I had been randomly switching between ifdef and ifndef WIN32: so i made most of them ifdefs so it was less confusing...
Diffstat (limited to 'src/win32_compatibility.cpp')
-rw-r--r-- | src/win32_compatibility.cpp | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/src/win32_compatibility.cpp b/src/win32_compatibility.cpp new file mode 100644 index 0000000..372dd6c --- /dev/null +++ b/src/win32_compatibility.cpp | |||
@@ -0,0 +1,266 @@ | |||
1 | #include "win32_compatibility.h" | ||
2 | |||
3 | #ifdef WIN32 | ||
4 | |||
5 | typedef char * (__cdecl *FNDEF_DYN_inet_ntoa)( struct in_addr ); | ||
6 | void DynamicWinsock2::inet_ntoa( Bu::FString &out, struct in_addr addr_in ) | ||
7 | { | ||
8 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
9 | if( Ws2_32 != NULL ) | ||
10 | { | ||
11 | FNDEF_DYN_inet_ntoa fn = (FNDEF_DYN_inet_ntoa) | ||
12 | GetProcAddress( Ws2_32, "inet_ntoa" ); | ||
13 | if( fn != NULL ) | ||
14 | out = (fn)( addr_in ); | ||
15 | |||
16 | //We will let windows clean up our dll imports on exit | ||
17 | //FreeLibrary( Ws2_32 ); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | typedef unsigned long (__cdecl *FNDEF_DYN_inet_addr)( const char * ); | ||
22 | unsigned long DynamicWinsock2::inet_addr( const char *s_in ) | ||
23 | { | ||
24 | unsigned long out = 0; | ||
25 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
26 | if( Ws2_32 != NULL ) | ||
27 | { | ||
28 | FNDEF_DYN_inet_addr fn = (FNDEF_DYN_inet_addr) | ||
29 | GetProcAddress( Ws2_32, "inet_addr" ); | ||
30 | if( fn != NULL ) | ||
31 | out = (fn)( s_in ); | ||
32 | } | ||
33 | return out; | ||
34 | } | ||
35 | |||
36 | typedef int (__cdecl *FNDEF_DYN_select)( | ||
37 | int nfds,fd_set*,fd_set*,fd_set*,const struct timeval*); | ||
38 | int DynamicWinsock2::select(int nfds, fd_set *readfds, fd_set *writefds, | ||
39 | fd_set *exceptfds, const struct timeval *timeout) | ||
40 | { | ||
41 | int out = 0; | ||
42 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
43 | if( Ws2_32 != NULL ) | ||
44 | { | ||
45 | FNDEF_DYN_select fn = (FNDEF_DYN_select) | ||
46 | GetProcAddress( Ws2_32, "select" ); | ||
47 | if( fn != NULL ) | ||
48 | out = (fn)( nfds, readfds, writefds, exceptfds, timeout ); | ||
49 | } | ||
50 | return out; | ||
51 | } | ||
52 | |||
53 | typedef SOCKET (__cdecl *FNDEF_DYN_socket)(int,int,int); | ||
54 | SOCKET DynamicWinsock2::socket(int domain, int type, int protocol) | ||
55 | { | ||
56 | SOCKET out = 0; | ||
57 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
58 | if( Ws2_32 != NULL ) | ||
59 | { | ||
60 | FNDEF_DYN_socket fn = (FNDEF_DYN_socket) | ||
61 | GetProcAddress( Ws2_32, "socket" ); | ||
62 | if( fn != NULL ) | ||
63 | out = (fn)( domain, type, protocol ); | ||
64 | } | ||
65 | return out; | ||
66 | } | ||
67 | |||
68 | typedef int (__cdecl *FNDEF_DYN_ioctlsocket)(SOCKET,long,u_long *); | ||
69 | int DynamicWinsock2::ioctlsocket(SOCKET s, long cmd, u_long *argp) | ||
70 | { | ||
71 | int out = 0; | ||
72 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
73 | if( Ws2_32 != NULL ) | ||
74 | { | ||
75 | FNDEF_DYN_ioctlsocket fn = (FNDEF_DYN_ioctlsocket) | ||
76 | GetProcAddress( Ws2_32, "ioctlsocket" ); | ||
77 | if( fn != NULL ) | ||
78 | out = (fn)( s, cmd, argp ); | ||
79 | } | ||
80 | return out; | ||
81 | } | ||
82 | |||
83 | typedef u_short (__cdecl *FNDEF_DYN_htons)(u_short); | ||
84 | u_short DynamicWinsock2::htons(u_short in) | ||
85 | { | ||
86 | u_short out = 0; | ||
87 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
88 | if( Ws2_32 != NULL ) | ||
89 | { | ||
90 | FNDEF_DYN_htons fn = (FNDEF_DYN_htons) | ||
91 | GetProcAddress( Ws2_32, "htons" ); | ||
92 | if( fn != NULL ) | ||
93 | out = (fn)( in ); | ||
94 | } | ||
95 | return out; | ||
96 | } | ||
97 | |||
98 | typedef u_long (__cdecl *FNDEF_DYN_htonl)(u_long); | ||
99 | u_long DynamicWinsock2::htonl(u_long in) | ||
100 | { | ||
101 | u_long out = 0; | ||
102 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
103 | if( Ws2_32 != NULL ) | ||
104 | { | ||
105 | FNDEF_DYN_htonl fn = (FNDEF_DYN_htonl) | ||
106 | GetProcAddress( Ws2_32, "htonl" ); | ||
107 | if( fn != NULL ) | ||
108 | out = (fn)( in ); | ||
109 | } | ||
110 | return out; | ||
111 | } | ||
112 | |||
113 | typedef struct hostent * (__cdecl *FNDEF_DYN_gethostbyname)(const char *); | ||
114 | struct hostent *DynamicWinsock2::gethostbyname(const char *name) | ||
115 | { | ||
116 | hostent *out = NULL; | ||
117 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
118 | if( Ws2_32 != NULL ) | ||
119 | { | ||
120 | FNDEF_DYN_gethostbyname fn = (FNDEF_DYN_gethostbyname) | ||
121 | GetProcAddress( Ws2_32, "gethostbyname" ); | ||
122 | if( fn != NULL ) | ||
123 | out = (fn)( name ); | ||
124 | } | ||
125 | return out; | ||
126 | } | ||
127 | |||
128 | typedef int (__cdecl *FNDEF_DYN_connect)(SOCKET,const struct sockaddr*,int); | ||
129 | int DynamicWinsock2::connect( | ||
130 | SOCKET s, const struct sockaddr *serv_addr, int addrlen) | ||
131 | { | ||
132 | int out = 0; | ||
133 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
134 | if( Ws2_32 != NULL ) | ||
135 | { | ||
136 | FNDEF_DYN_connect fn = (FNDEF_DYN_connect) | ||
137 | GetProcAddress( Ws2_32, "connect" ); | ||
138 | if( fn != NULL ) | ||
139 | out = (fn)( s, serv_addr, addrlen ); | ||
140 | } | ||
141 | return out; | ||
142 | } | ||
143 | |||
144 | typedef int (__cdecl *FNDEF_DYN_getpeername)(SOCKET,struct sockaddr*,int*); | ||
145 | int DynamicWinsock2::getpeername(SOCKET s, struct sockaddr *name, int *namelen) | ||
146 | { | ||
147 | int out = 0; | ||
148 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
149 | if( Ws2_32 != NULL ) | ||
150 | { | ||
151 | FNDEF_DYN_getpeername fn = (FNDEF_DYN_getpeername) | ||
152 | GetProcAddress( Ws2_32, "getpeername" ); | ||
153 | if( fn != NULL ) | ||
154 | out = (fn)( s, name, namelen ); | ||
155 | } | ||
156 | return out; | ||
157 | } | ||
158 | |||
159 | typedef int (__cdecl *FNDEF_DYN_setsockopt)(SOCKET,int,int,const char*,int); | ||
160 | int DynamicWinsock2::setsockopt(SOCKET s, int level, int optname, | ||
161 | const char *optval, int optlen) | ||
162 | { | ||
163 | int out = 0; | ||
164 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
165 | if( Ws2_32 != NULL ) | ||
166 | { | ||
167 | FNDEF_DYN_setsockopt fn = (FNDEF_DYN_setsockopt) | ||
168 | GetProcAddress( Ws2_32, "setsockopt" ); | ||
169 | if( fn != NULL ) | ||
170 | out = (fn)( s, level, optname, optval, optlen ); | ||
171 | } | ||
172 | return out; | ||
173 | } | ||
174 | |||
175 | typedef int (__cdecl *FNDEF_DYN_bind)(SOCKET,const struct sockaddr*,int); | ||
176 | int DynamicWinsock2::bind(SOCKET s, const struct sockaddr *my_addr, int addrlen) | ||
177 | { | ||
178 | int out = 0; | ||
179 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
180 | if( Ws2_32 != NULL ) | ||
181 | { | ||
182 | FNDEF_DYN_bind fn = (FNDEF_DYN_bind) | ||
183 | GetProcAddress( Ws2_32, "bind" ); | ||
184 | if( fn != NULL ) | ||
185 | out = (fn)( s, my_addr, addrlen ); | ||
186 | } | ||
187 | return out; | ||
188 | } | ||
189 | |||
190 | typedef int (__cdecl *FNDEF_DYN_listen)(SOCKET,int); | ||
191 | int DynamicWinsock2::listen(SOCKET s, int backlog) | ||
192 | { | ||
193 | int out = 0; | ||
194 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
195 | if( Ws2_32 != NULL ) | ||
196 | { | ||
197 | FNDEF_DYN_listen fn = (FNDEF_DYN_listen) | ||
198 | GetProcAddress( Ws2_32, "listen" ); | ||
199 | if( fn != NULL ) | ||
200 | out = (fn)( s, backlog ); | ||
201 | } | ||
202 | return out; | ||
203 | } | ||
204 | |||
205 | typedef SOCKET (__cdecl *FNDEF_DYN_accept)(SOCKET,struct sockaddr*,int*); | ||
206 | SOCKET DynamicWinsock2::accept(SOCKET s, struct sockaddr *addr, int *addrlen) | ||
207 | { | ||
208 | SOCKET out = 0; | ||
209 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
210 | if( Ws2_32 != NULL ) | ||
211 | { | ||
212 | FNDEF_DYN_accept fn = (FNDEF_DYN_accept) | ||
213 | GetProcAddress( Ws2_32, "accept" ); | ||
214 | if( fn != NULL ) | ||
215 | out = (fn)( s, addr, addrlen ); | ||
216 | } | ||
217 | return out; | ||
218 | } | ||
219 | |||
220 | typedef int (__cdecl *FNDEF_DYN_recv)(SOCKET,char*,int,int); | ||
221 | int DynamicWinsock2::recv( SOCKET s, char *buf, int len, int flags ) | ||
222 | { | ||
223 | int out = 0; | ||
224 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
225 | if( Ws2_32 != NULL ) | ||
226 | { | ||
227 | FNDEF_DYN_recv fn = (FNDEF_DYN_recv) | ||
228 | GetProcAddress( Ws2_32, "recv" ); | ||
229 | if( fn != NULL ) | ||
230 | out = (fn)( s, buf, len, flags ); | ||
231 | } | ||
232 | return out; | ||
233 | } | ||
234 | |||
235 | typedef int (__cdecl *FNDEF_DYN_send)(SOCKET,const char*,int,int); | ||
236 | int DynamicWinsock2::send( SOCKET s, const char *buf, int len, int flags ) | ||
237 | { | ||
238 | int out = 0; | ||
239 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
240 | if( Ws2_32 != NULL ) | ||
241 | { | ||
242 | FNDEF_DYN_send fn = (FNDEF_DYN_send) | ||
243 | GetProcAddress( Ws2_32, "send" ); | ||
244 | if( fn != NULL ) | ||
245 | out = (fn)( s, buf, len, flags ); | ||
246 | } | ||
247 | return out; | ||
248 | } | ||
249 | |||
250 | typedef int (__cdecl *FNDEF_DYN__WSAFDIsSet)(SOCKET,fd_set*); | ||
251 | int DynamicWinsock2::DYN_FD_ISSET(SOCKET s, fd_set *set) | ||
252 | { | ||
253 | int out = 0; | ||
254 | HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); | ||
255 | if( Ws2_32 != NULL ) | ||
256 | { | ||
257 | FNDEF_DYN__WSAFDIsSet fn = (FNDEF_DYN__WSAFDIsSet) | ||
258 | GetProcAddress( Ws2_32, "__WSAFDIsSet" ); | ||
259 | if( fn != NULL ) | ||
260 | out = (fn)( s, set ); | ||
261 | } | ||
262 | return out; | ||
263 | } | ||
264 | |||
265 | #endif | ||
266 | |||