FreeTDS API: include/freetds/sysdep_private.h Source File

FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

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 #define vsnprintf _vsnprintf
67 /* TODO this has nothing to do with ip ... */
68 #define getpid() _gethostid()
69 #endif /* defined(DOS32X) */
70
71 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
72 #include <winsock2.h>
73 #include <ws2tcpip.h>
74 #include <wspiapi.h>
75 #include <windows.h>
76 #define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
77 #define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
78 #define CLOSESOCKET(a) closesocket((a))
79 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (c))
80 #define SOCKLEN_T int
81 int tds_socket_init(void);
82 #define INITSOCKET() tds_socket_init()
83 void tds_socket_done(void);
84 #define DONESOCKET() tds_socket_done()
85 #define NETDB_REENTRANT 1 /* BSD-style netdb interface is reentrant */
86
87 #define TDSSOCK_EINTR WSAEINTR
88 #define TDSSOCK_EINPROGRESS WSAEWOULDBLOCK
89 #define TDSSOCK_ETIMEDOUT WSAETIMEDOUT
90 #define TDSSOCK_WOULDBLOCK(e) ((e)==WSAEWOULDBLOCK)
91 #define sock_errno WSAGetLastError()
92 #define sock_strerror(n) tds_prwsaerror(n)
93 #ifndef __MINGW32__
94 typedef DWORD pid_t;
95 #endif
96 #undef strcasecmp
97 #define strcasecmp stricmp
98 #undef strncasecmp
99 #define strncasecmp strnicmp
100 #define vsnprintf _vsnprintf
101 #define snprintf _snprintf
102
103 #ifndef WIN32
104 #define WIN32 1
105 #endif
106
107 #if defined(_WIN64) && !defined(WIN64)
108 #define WIN64 1
109 #endif
110
111 #define TDS_SDIR_SEPARATOR "\\"
112
113 /* use macros to use new style names */
114 #if defined(__MSVCRT__) || defined(_MSC_VER)
115 /* Use API as always present and not causing problems */
116 #undef getpid
117 #define getpid() GetCurrentProcessId()
118 #define strdup(s) _strdup(s)
119 #define unlink(f) _unlink(f)
120 #define putenv(s) _putenv(s)
121 #undef fileno
122 #define fileno(f) _fileno(f)
123 #define stricmp(s1,s2) _stricmp(s1,s2)
124 #define strnicmp(s1,s2,n) _strnicmp(s1,s2,n)
125 #endif
126
127 #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) */
128
129 #ifndef sock_errno
130 #define sock_errno errno
131 #endif
132
133 #ifndef sock_strerror
134 #define sock_strerror(n) strerror(n)
135 #endif
136
137 #ifndef TDSSOCK_EINTR
138 #define TDSSOCK_EINTR EINTR
139 #endif
140
141 #ifndef TDSSOCK_EINPROGRESS
142 #define TDSSOCK_EINPROGRESS EINPROGRESS
143 #endif
144
145 #ifndef TDSSOCK_ETIMEDOUT
146 #define TDSSOCK_ETIMEDOUT ETIMEDOUT
147 #endif
148
149 #ifndef TDSSOCK_WOULDBLOCK
150 # if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
151 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN||(e)==EWOULDBLOCK)
152 # else
153 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN)
154 # endif
155 #endif
156
157 #ifndef INITSOCKET
158 #define INITSOCKET() 0
159 #endif /* !INITSOCKET */
160
161 #ifndef DONESOCKET
162 #define DONESOCKET() do { } while(0)
163 #endif /* !DONESOCKET */
164
165 #ifndef READSOCKET
166 # ifdef MSG_NOSIGNAL
167 # define READSOCKET(s,b,l) recv((s), (b), (l), MSG_NOSIGNAL)
168 # else
169 # define READSOCKET(s,b,l) read((s), (b), (l))
170 # endif
171 #endif /* !READSOCKET */
172
173 #ifndef WRITESOCKET
174 # ifdef MSG_NOSIGNAL
175 # define WRITESOCKET(s,b,l) send((s), (b), (l), MSG_NOSIGNAL)
176 # else
177 # define WRITESOCKET(s,b,l) write((s), (b), (l))
178 # endif
179 #endif /* !WRITESOCKET */
180
181 #ifndef CLOSESOCKET
182 #define CLOSESOCKET(s) close((s))
183 #endif /* !CLOSESOCKET */
184
185 #ifndef IOCTLSOCKET
186 #define IOCTLSOCKET(s,b,l) ioctl((s), (b), (l))
187 #endif /* !IOCTLSOCKET */
188
189 #ifndef SOCKLEN_T
190 # define SOCKLEN_T socklen_t
191 #endif
192
193 #if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
194 typedef int TDS_SYS_SOCKET;
195 #define INVALID_SOCKET -1
196 #define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
197 #else
198 typedef SOCKET TDS_SYS_SOCKET;
199 #define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
200 #endif
201
202 #define tds_accept accept
203 #define tds_getpeername getpeername
204 #define tds_getsockopt getsockopt
205 #define tds_getsockname getsockname
206 #define tds_recvfrom recvfrom
207
208 #if defined(__hpux__) && SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
209 # if HAVE__XPG_ACCEPT
210 # undef tds_accept
211 # define tds_accept _xpg_accept
212 # elif HAVE___ACCEPT
213 # undef tds_accept
214 # define tds_accept __accept
215 # endif
216 # if HAVE__XPG_GETPEERNAME
217 # undef tds_getpeername
218 # define tds_getpeername _xpg_getpeername
219 # elif HAVE___GETPEERNAME
220 # undef tds_getpeername
221 # define tds_getpeername __getpeername
222 # endif
223 # if HAVE__XPG_GETSOCKOPT
224 # undef tds_getsockopt
225 # define tds_getsockopt _xpg_getsockopt
226 # elif HAVE___GETSOCKOPT
227 # undef tds_getsockopt
228 # define tds_getsockopt __getsockopt
229 # endif
230 # if HAVE__XPG_GETSOCKNAME
231 # undef tds_getsockname
232 # define tds_getsockname _xpg_getsockname
233 # elif HAVE___GETSOCKNAME
234 # undef tds_getsockname
235 # define tds_getsockname __getsockname
236 # endif
237 # if HAVE__XPG_RECVFROM
238 # undef tds_recvfrom
239 # define tds_recvfrom _xpg_recvfrom
240 # elif HAVE___RECVFROM
241 # undef tds_recvfrom
242 # define tds_recvfrom __recvfrom
243 # endif
244 #endif
245
246 #ifndef TDS_SDIR_SEPARATOR
247 #define TDS_SDIR_SEPARATOR "/"
248 #endif /* !TDS_SDIR_SEPARATOR */
249
250 #ifdef HAVE_INTTYPES_H
251 #include <inttypes.h>
252 #endif
253
254 #ifndef PRId64
255 #define PRId64 TDS_I64_PREFIX "d"
256 #endif
257 #ifndef PRIu64
258 #define PRIu64 TDS_I64_PREFIX "u"
259 #endif
260 #ifndef PRIx64
261 #define PRIx64 TDS_I64_PREFIX "x"
262 #endif
263
264 #ifdef __cplusplus
265 #if 0
266 {
267 #endif
268 }
269 #endif
270
271 #endif /* _tds_sysdep_private_h_ */