FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tds_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 0
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 <windows.h>
74 #define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
75 #define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
76 #define CLOSESOCKET(a) closesocket((a))
77 #define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (c))
78 #define SOCKLEN_T int
79 int tds_socket_init(void);
80 #define INITSOCKET() tds_socket_init()
81 void tds_socket_done(void);
82 #define DONESOCKET() tds_socket_done()
83 #define NETDB_REENTRANT 1 /* BSD-style netdb interface is reentrant */
84 
85 #define TDSSOCK_EINTR WSAEINTR
86 #define TDSSOCK_EINPROGRESS WSAEWOULDBLOCK
87 #define TDSSOCK_WOULDBLOCK(e) ((e)==WSAEWOULDBLOCK)
88 #define sock_errno WSAGetLastError()
89 #define sock_strerror(n) tds_prwsaerror(n)
90 #ifndef __MINGW32__
91 typedef DWORD pid_t;
92 #endif
93 #define strcasecmp stricmp
94 #define strncasecmp strnicmp
95 #define atoll _atoi64
96 #define vsnprintf _vsnprintf
97 #define snprintf _snprintf
98 
99 #ifndef WIN32
100 #define WIN32 1
101 #endif
102 
103 #if defined(_WIN64) && !defined(WIN64)
104 #define WIN64 1
105 #endif
106 
107 #define TDS_SDIR_SEPARATOR "\\"
108 
109 /* use macros to use new style names */
110 #if defined(__MSVCRT__) || defined(_MSC_VER)
111 #define getpid() _getpid()
112 #define strdup(s) _strdup(s)
113 #undef fileno
114 #define fileno(f) _fileno(f)
115 #define stricmp(s1,s2) _stricmp(s1,s2)
116 #define strnicmp(s1,s2,n) _strnicmp(s1,s2,n)
117 #endif
118 
119 #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) */
120 
121 #ifndef sock_errno
122 #define sock_errno errno
123 #endif
124 
125 #ifndef sock_strerror
126 #define sock_strerror(n) strerror(n)
127 #endif
128 
129 #ifndef TDSSOCK_EINTR
130 #define TDSSOCK_EINTR EINTR
131 #endif
132 
133 #ifndef TDSSOCK_EINPROGRESS
134 #define TDSSOCK_EINPROGRESS EINPROGRESS
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_FORMAT
244 #endif
245 
246 #ifdef __cplusplus
247 #if 0
248 {
249 #endif
250 }
251 #endif
252 
253 #endif /* _tds_sysdep_private_h_ */