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