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 <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 sock_errno WSAGetLastError()
78 #define sock_strerror(n) tds_prwsaerror(n)
79 #define sock_strerror_free(s) tds_prwsaerror_free(s)
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 #define sock_strerror_free(s) do {} while(0)
124 #endif
125 
126 #ifndef TDSSOCK_EINTR
127 #define TDSSOCK_EINTR EINTR
128 #endif
129 
130 #ifndef TDSSOCK_EINPROGRESS
131 #define TDSSOCK_EINPROGRESS EINPROGRESS
132 #endif
133 
134 #ifndef TDSSOCK_ETIMEDOUT
135 #define TDSSOCK_ETIMEDOUT ETIMEDOUT
136 #endif
137 
138 #ifndef TDSSOCK_WOULDBLOCK
139 # if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
140 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN||(e)==EWOULDBLOCK)
141 # else
142 # define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN)
143 # endif
144 #endif
145 
146 #ifndef INITSOCKET
147 #define INITSOCKET() 0
148 #endif /* !INITSOCKET */
149 
150 #ifndef DONESOCKET
151 #define DONESOCKET() do { } while(0)
152 #endif /* !DONESOCKET */
153 
154 #ifndef READSOCKET
155 # ifdef MSG_NOSIGNAL
156 # define READSOCKET(s,b,l) recv((s), (b), (l), MSG_NOSIGNAL)
157 # else
158 # define READSOCKET(s,b,l) read((s), (b), (l))
159 # endif
160 #endif /* !READSOCKET */
161 
162 #ifndef WRITESOCKET
163 # ifdef MSG_NOSIGNAL
164 # define WRITESOCKET(s,b,l) send((s), (b), (l), MSG_NOSIGNAL)
165 # else
166 # define WRITESOCKET(s,b,l) write((s), (b), (l))
167 # endif
168 #endif /* !WRITESOCKET */
169 
170 #ifndef CLOSESOCKET
171 #define CLOSESOCKET(s) close((s))
172 #endif /* !CLOSESOCKET */
173 
174 #ifndef IOCTLSOCKET
175 #define IOCTLSOCKET(s,b,l) ioctl((s), (b), (l))
176 #endif /* !IOCTLSOCKET */
177 
178 #ifndef SOCKLEN_T
179 # define SOCKLEN_T socklen_t
180 #endif
181 
182 #if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
183 typedef int TDS_SYS_SOCKET;
184 #define INVALID_SOCKET -1
185 #define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
186 #else
187 typedef SOCKET TDS_SYS_SOCKET;
188 #define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
189 #endif
190 
191 #define tds_accept accept
192 #define tds_getpeername getpeername
193 #define tds_getsockopt getsockopt
194 #define tds_getsockname getsockname
195 #define tds_recvfrom recvfrom
196 
197 #if defined(__hpux__) && SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
198 # if HAVE__XPG_ACCEPT
199 # undef tds_accept
200 # define tds_accept _xpg_accept
201 # elif HAVE___ACCEPT
202 # undef tds_accept
203 # define tds_accept __accept
204 # endif
205 # if HAVE__XPG_GETPEERNAME
206 # undef tds_getpeername
207 # define tds_getpeername _xpg_getpeername
208 # elif HAVE___GETPEERNAME
209 # undef tds_getpeername
210 # define tds_getpeername __getpeername
211 # endif
212 # if HAVE__XPG_GETSOCKOPT
213 # undef tds_getsockopt
214 # define tds_getsockopt _xpg_getsockopt
215 # elif HAVE___GETSOCKOPT
216 # undef tds_getsockopt
217 # define tds_getsockopt __getsockopt
218 # endif
219 # if HAVE__XPG_GETSOCKNAME
220 # undef tds_getsockname
221 # define tds_getsockname _xpg_getsockname
222 # elif HAVE___GETSOCKNAME
223 # undef tds_getsockname
224 # define tds_getsockname __getsockname
225 # endif
226 # if HAVE__XPG_RECVFROM
227 # undef tds_recvfrom
228 # define tds_recvfrom _xpg_recvfrom
229 # elif HAVE___RECVFROM
230 # undef tds_recvfrom
231 # define tds_recvfrom __recvfrom
232 # endif
233 #endif
234 
235 #ifndef TDS_SDIR_SEPARATOR
236 #define TDS_SDIR_SEPARATOR "/"
237 #endif /* !TDS_SDIR_SEPARATOR */
238 
239 #ifdef HAVE_INTTYPES_H
240 #include <inttypes.h>
241 #endif
242 
243 #ifndef PRId64
244 #define PRId64 TDS_I64_PREFIX "d"
245 #endif
246 #ifndef PRIu64
247 #define PRIu64 TDS_I64_PREFIX "u"
248 #endif
249 #ifndef PRIx64
250 #define PRIx64 TDS_I64_PREFIX "x"
251 #endif
252 
253 #ifdef __cplusplus
254 #if 0
255 {
256 #endif
257 }
258 #endif
259 
260 #endif /* _tds_sysdep_private_h_ */