FreeTDS API
sysdep_private.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Brian Bruns
3  * Copyright (C) 2010 Frediano Ziglio
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _tds_sysdep_private_h_
22 #define _tds_sysdep_private_h_
23 
24 #define TDS_ADDITIONAL_SPACE 16
25 
26 #ifdef MSG_NOSIGNAL
27 # define TDS_NOSIGNAL MSG_NOSIGNAL
28 #else
29 # define TDS_NOSIGNAL 0L
30 #endif
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0
36 }
37 #endif
38 #endif
39 
40 #ifdef __INCvxWorksh
41 #include <ioLib.h> /* for FIONBIO */
42 #endif /* __INCvxWorksh */
43 
44 #if defined(DOS32X)
45 #define READSOCKET(a,b,c) recv((a), (b), (c), TDS_NOSIGNAL)
46 #define WRITESOCKET(a,b,c) send((a), (b), (c), TDS_NOSIGNAL)
47 #define CLOSESOCKET(a) closesocket((a))
48 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (char*)(c))
49 #define SOCKLEN_T int
50 #define select select_s
51 typedef int pid_t;
52 #define strcasecmp stricmp
53 #define strncasecmp strnicmp
54 /* TODO this has nothing to do with ip ... */
55 #define getpid() _gethostid()
56 #endif /* defined(DOS32X) */
57 
58 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
59 #include <winsock2.h>
60 #include <ws2tcpip.h>
61 #include <windows.h>
62 #define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
63 #define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
64 #define CLOSESOCKET(a) closesocket((a))
65 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (c))
66 #define SOCKLEN_T int
67 int tds_socket_init(void);
68 #define INITSOCKET() tds_socket_init()
69 void tds_socket_done(void);
70 #define DONESOCKET() tds_socket_done()
71 #define NETDB_REENTRANT 1 /* BSD-style netdb interface is reentrant */
72 
73 #define TDSSOCK_EINTR WSAEINTR
74 #define TDSSOCK_EINPROGRESS WSAEWOULDBLOCK
75 #define TDSSOCK_ETIMEDOUT WSAETIMEDOUT
76 #define TDSSOCK_WOULDBLOCK(e) ((e)==WSAEWOULDBLOCK)
77 #define TDSSOCK_ECONNRESET WSAECONNRESET
78 #define sock_errno WSAGetLastError()
79 #define set_sock_errno(err) WSASetLastError(err)
80 #define sock_strerror(n) tds_prwsaerror(n)
81 #define sock_strerror_free(s) tds_prwsaerror_free(s)
82 #ifndef __MINGW32__
83 typedef DWORD pid_t;
84 #endif
85 #undef strcasecmp
86 #define strcasecmp stricmp
87 #undef strncasecmp
88 #define strncasecmp strnicmp
89 #if defined(HAVE__SNPRINTF) && !defined(HAVE_SNPRINTF)
90 #define snprintf _snprintf
91 #endif
92 
93 #ifndef WIN32
94 #define WIN32 1
95 #endif
96 
97 #if defined(_WIN64) && !defined(WIN64)
98 #define WIN64 1
99 #endif
100 
101 #define TDS_SDIR_SEPARATOR "\\"
102 
103 /* use macros to use new style names */
104 #if defined(__MSVCRT__) || defined(_MSC_VER)
105 /* Use API as always present and not causing problems */
106 #undef getpid
107 #define getpid() GetCurrentProcessId()
108 #define strdup(s) _strdup(s)
109 #define unlink(f) _unlink(f)
110 #define putenv(s) _putenv(s)
111 #undef fileno
112 #define fileno(f) _fileno(f)
113 #undef close
114 #define close(f) _close(f)
115 #undef open
116 #define open(fn,...) _open(fn,__VA_ARGS__)
117 #undef dup2
118 #define dup2(o,n) _dup2(o,n)
119 #define stricmp(s1,s2) _stricmp(s1,s2)
120 #define strnicmp(s1,s2,n) _strnicmp(s1,s2,n)
121 #endif
122 
123 #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) */
124 
125 #ifndef sock_errno
126 #define sock_errno errno
127 #endif
128 
129 #ifndef set_sock_errno
130 #define set_sock_errno(err) do { errno = (err); } while(0)
131 #endif
132 
133 #ifndef sock_strerror
134 #define sock_strerror(n) strerror(n)
135 #define sock_strerror_free(s) do {} while(0)
136 #endif
137 
138 #ifndef TDSSOCK_EINTR
139 #define TDSSOCK_EINTR EINTR
140 #endif
141 
142 #ifndef TDSSOCK_EINPROGRESS
143 #define TDSSOCK_EINPROGRESS EINPROGRESS
144 #endif
145 
146 #ifndef TDSSOCK_ETIMEDOUT
147 #define TDSSOCK_ETIMEDOUT ETIMEDOUT
148 #endif
149 
150 #ifndef TDSSOCK_WOULDBLOCK
151 # if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
152 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN||(e)==EWOULDBLOCK)
153 # else
154 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN)
155 # endif
156 #endif
157 
158 #ifndef TDSSOCK_ECONNRESET
159 #define TDSSOCK_ECONNRESET ECONNRESET
160 #endif
161 
162 #ifndef INITSOCKET
163 #define INITSOCKET() 0
164 #endif /* !INITSOCKET */
165 
166 #ifndef DONESOCKET
167 #define DONESOCKET() do { } while(0)
168 #endif /* !DONESOCKET */
169 
170 #ifndef READSOCKET
171 # ifdef MSG_NOSIGNAL
172 # define READSOCKET(s,b,l) recv((s), (b), (l), MSG_NOSIGNAL)
173 # else
174 # define READSOCKET(s,b,l) read((s), (b), (l))
175 # endif
176 #endif /* !READSOCKET */
177 
178 #ifndef WRITESOCKET
179 # ifdef MSG_NOSIGNAL
180 # define WRITESOCKET(s,b,l) send((s), (b), (l), MSG_NOSIGNAL)
181 # else
182 # define WRITESOCKET(s,b,l) write((s), (b), (l))
183 # endif
184 #endif /* !WRITESOCKET */
185 
186 #ifndef CLOSESOCKET
187 #define CLOSESOCKET(s) close((s))
188 #endif /* !CLOSESOCKET */
189 
190 #ifndef IOCTLSOCKET
191 #define IOCTLSOCKET(s,b,l) ioctl((s), (b), (l))
192 #endif /* !IOCTLSOCKET */
193 
194 #ifndef SOCKLEN_T
195 # define SOCKLEN_T socklen_t
196 #endif
197 
198 #if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
199 typedef int TDS_SYS_SOCKET;
200 #define INVALID_SOCKET -1
201 #define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
202 #else
203 typedef SOCKET TDS_SYS_SOCKET;
204 #define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
205 #endif
206 
207 #define tds_accept accept
208 #define tds_getpeername getpeername
209 #define tds_getsockopt getsockopt
210 #define tds_getsockname getsockname
211 #define tds_recvfrom recvfrom
212 
213 #if defined(__hpux__) && SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
214 # if HAVE__XPG_ACCEPT
215 # undef tds_accept
216 # define tds_accept _xpg_accept
217 # elif HAVE___ACCEPT
218 # undef tds_accept
219 # define tds_accept __accept
220 # endif
221 # if HAVE__XPG_GETPEERNAME
222 # undef tds_getpeername
223 # define tds_getpeername _xpg_getpeername
224 # elif HAVE___GETPEERNAME
225 # undef tds_getpeername
226 # define tds_getpeername __getpeername
227 # endif
228 # if HAVE__XPG_GETSOCKOPT
229 # undef tds_getsockopt
230 # define tds_getsockopt _xpg_getsockopt
231 # elif HAVE___GETSOCKOPT
232 # undef tds_getsockopt
233 # define tds_getsockopt __getsockopt
234 # endif
235 # if HAVE__XPG_GETSOCKNAME
236 # undef tds_getsockname
237 # define tds_getsockname _xpg_getsockname
238 # elif HAVE___GETSOCKNAME
239 # undef tds_getsockname
240 # define tds_getsockname __getsockname
241 # endif
242 # if HAVE__XPG_RECVFROM
243 # undef tds_recvfrom
244 # define tds_recvfrom _xpg_recvfrom
245 # elif HAVE___RECVFROM
246 # undef tds_recvfrom
247 # define tds_recvfrom __recvfrom
248 # endif
249 #endif
250 
251 #ifndef TDS_SDIR_SEPARATOR
252 #define TDS_SDIR_SEPARATOR "/"
253 #endif /* !TDS_SDIR_SEPARATOR */
254 
255 #ifdef HAVE_INTTYPES_H
256 #include <inttypes.h>
257 #endif
258 
259 #ifndef PRId64
260 #define PRId64 TDS_I64_PREFIX "d"
261 #endif
262 #ifndef PRIu64
263 #define PRIu64 TDS_I64_PREFIX "u"
264 #endif
265 #ifndef PRIx64
266 #define PRIx64 TDS_I64_PREFIX "x"
267 #endif
268 
269 #ifdef __cplusplus
270 #if 0
271 {
272 #endif
273 }
274 #endif
275 
276 #endif /* _tds_sysdep_private_h_ */