FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 /* $Id: tds_sysdep_private.h,v 1.36 2010-12-28 14:37:10 freddy77 Exp $ */
25 
26 #undef TDS_RCSID
27 #if defined(__GNUC__) && __GNUC__ >= 3
28 #define TDS_RCSID(name, id) \
29  static const char rcsid_##name[] __attribute__ ((unused)) = id
30 #else
31 #define TDS_RCSID(name, id) \
32  static const char rcsid_##name[] = id; \
33  static const void *const no_unused_##name##_warn[] = { rcsid_##name, no_unused_##name##_warn }
34 #endif
35 
36 #define TDS_ADDITIONAL_SPACE 16
37 
38 #ifdef MSG_NOSIGNAL
39 # define TDS_NOSIGNAL MSG_NOSIGNAL
40 #else
41 # define TDS_NOSIGNAL 0L
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #if 0
48 }
49 #endif
50 #endif
51 
52 #ifdef __INCvxWorksh
53 #include <ioLib.h> /* for FIONBIO */
54 #endif /* __INCvxWorksh */
55 
56 #if defined(DOS32X)
57 #define READSOCKET(a,b,c) recv((a), (b), (c), TDS_NOSIGNAL)
58 #define WRITESOCKET(a,b,c) send((a), (b), (c), TDS_NOSIGNAL)
59 #define CLOSESOCKET(a) closesocket((a))
60 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (char*)(c))
61 #define SOCKLEN_T int
62 #define select select_s
63 typedef int pid_t;
64 #define strcasecmp stricmp
65 #define strncasecmp strnicmp
66 /* TODO this has nothing to do with ip ... */
67 #define getpid() _gethostid()
68 #endif /* defined(DOS32X) */
69 
70 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
71 #include <winsock2.h>
72 #include <ws2tcpip.h>
73 #include <wspiapi.h>
74 #include <windows.h>
75 #define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
76 #define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
77 #define CLOSESOCKET(a) closesocket((a))
78 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (c))
79 #define SOCKLEN_T int
80 int tds_socket_init(void);
81 #define INITSOCKET() tds_socket_init()
82 void tds_socket_done(void);
83 #define DONESOCKET() tds_socket_done()
84 #define NETDB_REENTRANT 1 /* BSD-style netdb interface is reentrant */
85 
86 #define TDSSOCK_EINTR WSAEINTR
87 #define TDSSOCK_EINPROGRESS WSAEWOULDBLOCK
88 #define TDSSOCK_ETIMEDOUT WSAETIMEDOUT
89 #define TDSSOCK_WOULDBLOCK(e) ((e)==WSAEWOULDBLOCK)
90 #define TDSSOCK_ECONNRESET WSAECONNRESET
91 #define sock_errno WSAGetLastError()
92 #define set_sock_errno(err) WSASetLastError(err)
93 #define sock_strerror(n) tds_prwsaerror(n)
94 #ifndef __MINGW32__
95 typedef DWORD pid_t;
96 #endif
97 #undef strcasecmp
98 #define strcasecmp stricmp
99 #undef strncasecmp
100 #define strncasecmp strnicmp
101 #if defined(HAVE__SNPRINTF) && !defined(HAVE_SNPRINTF)
102 #define snprintf _snprintf
103 #endif
104 
105 #ifndef WIN32
106 #define WIN32 1
107 #endif
108 
109 #if defined(_WIN64) && !defined(WIN64)
110 #define WIN64 1
111 #endif
112 
113 #define TDS_SDIR_SEPARATOR "\\"
114 
115 /* use macros to use new style names */
116 #if defined(__MSVCRT__) || defined(_MSC_VER)
117 /* Use API as always present and not causing problems */
118 #undef getpid
119 #define getpid() GetCurrentProcessId()
120 #define strdup(s) _strdup(s)
121 #define unlink(f) _unlink(f)
122 #define putenv(s) _putenv(s)
123 #undef fileno
124 #define fileno(f) _fileno(f)
125 #define stricmp(s1,s2) _stricmp(s1,s2)
126 #define strnicmp(s1,s2,n) _strnicmp(s1,s2,n)
127 #endif
128 
129 #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) */
130 
131 #ifndef sock_errno
132 #define sock_errno errno
133 #endif
134 
135 #ifndef set_sock_errno
136 #define set_sock_errno(err) do { errno = (err); } while(0)
137 #endif
138 
139 #ifndef sock_strerror
140 #define sock_strerror(n) strerror(n)
141 #endif
142 
143 #ifndef TDSSOCK_EINTR
144 #define TDSSOCK_EINTR EINTR
145 #endif
146 
147 #ifndef TDSSOCK_EINPROGRESS
148 #define TDSSOCK_EINPROGRESS EINPROGRESS
149 #endif
150 
151 #ifndef TDSSOCK_ETIMEDOUT
152 #define TDSSOCK_ETIMEDOUT ETIMEDOUT
153 #endif
154 
155 #ifndef TDSSOCK_WOULDBLOCK
156 # if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
157 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN||(e)==EWOULDBLOCK)
158 # else
159 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN)
160 # endif
161 #endif
162 
163 #ifndef TDSSOCK_ECONNRESET
164 #define TDSSOCK_ECONNRESET ECONNRESET
165 #endif
166 
167 #ifndef INITSOCKET
168 #define INITSOCKET() 0
169 #endif /* !INITSOCKET */
170 
171 #ifndef DONESOCKET
172 #define DONESOCKET() do { } while(0)
173 #endif /* !DONESOCKET */
174 
175 #ifndef READSOCKET
176 # ifdef MSG_NOSIGNAL
177 # define READSOCKET(s,b,l) recv((s), (b), (l), MSG_NOSIGNAL)
178 # else
179 # define READSOCKET(s,b,l) read((s), (b), (l))
180 # endif
181 #endif /* !READSOCKET */
182 
183 #ifndef WRITESOCKET
184 # ifdef MSG_NOSIGNAL
185 # define WRITESOCKET(s,b,l) send((s), (b), (l), MSG_NOSIGNAL)
186 # else
187 # define WRITESOCKET(s,b,l) write((s), (b), (l))
188 # endif
189 #endif /* !WRITESOCKET */
190 
191 #ifndef CLOSESOCKET
192 #define CLOSESOCKET(s) close((s))
193 #endif /* !CLOSESOCKET */
194 
195 #ifndef IOCTLSOCKET
196 #define IOCTLSOCKET(s,b,l) ioctl((s), (b), (l))
197 #endif /* !IOCTLSOCKET */
198 
199 #ifndef SOCKLEN_T
200 # define SOCKLEN_T socklen_t
201 #endif
202 
203 #if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
204 typedef int TDS_SYS_SOCKET;
205 #define INVALID_SOCKET -1
206 #define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
207 #else
208 typedef SOCKET TDS_SYS_SOCKET;
209 #define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
210 #endif
211 
212 #define tds_accept accept
213 #define tds_getpeername getpeername
214 #define tds_getsockopt getsockopt
215 #define tds_getsockname getsockname
216 #define tds_recvfrom recvfrom
217 
218 #if defined(__hpux__) && SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
219 # if HAVE__XPG_ACCEPT
220 # undef tds_accept
221 # define tds_accept _xpg_accept
222 # elif HAVE___ACCEPT
223 # undef tds_accept
224 # define tds_accept __accept
225 # endif
226 # if HAVE__XPG_GETPEERNAME
227 # undef tds_getpeername
228 # define tds_getpeername _xpg_getpeername
229 # elif HAVE___GETPEERNAME
230 # undef tds_getpeername
231 # define tds_getpeername __getpeername
232 # endif
233 # if HAVE__XPG_GETSOCKOPT
234 # undef tds_getsockopt
235 # define tds_getsockopt _xpg_getsockopt
236 # elif HAVE___GETSOCKOPT
237 # undef tds_getsockopt
238 # define tds_getsockopt __getsockopt
239 # endif
240 # if HAVE__XPG_GETSOCKNAME
241 # undef tds_getsockname
242 # define tds_getsockname _xpg_getsockname
243 # elif HAVE___GETSOCKNAME
244 # undef tds_getsockname
245 # define tds_getsockname __getsockname
246 # endif
247 # if HAVE__XPG_RECVFROM
248 # undef tds_recvfrom
249 # define tds_recvfrom _xpg_recvfrom
250 # elif HAVE___RECVFROM
251 # undef tds_recvfrom
252 # define tds_recvfrom __recvfrom
253 # endif
254 #endif
255 
256 #ifndef TDS_SDIR_SEPARATOR
257 #define TDS_SDIR_SEPARATOR "/"
258 #endif /* !TDS_SDIR_SEPARATOR */
259 
260 #ifdef HAVE_INTTYPES_H
261 #include <inttypes.h>
262 #endif
263 
264 #ifndef PRId64
265 #define PRId64 TDS_I64_PREFIX "d"
266 #endif
267 #ifndef PRIu64
268 #define PRIu64 TDS_I64_PREFIX "u"
269 #endif
270 #ifndef PRIx64
271 #define PRIx64 TDS_I64_PREFIX "x"
272 #endif
273 
274 #ifdef __cplusplus
275 #if 0
276 {
277 #endif
278 }
279 #endif
280 
281 #endif /* _tds_sysdep_private_h_ */