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