FreeTDS API
Loading...
Searching...
No Matches
include
freetds
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 _tdsguard_gbdINUKdHN7rAOavGyKkWw_
22
#define _tdsguard_gbdINUKdHN7rAOavGyKkWw_
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
#define TDS_EXTERN_C extern "C"
34
#else
35
#define TDS_EXTERN_C
36
#endif
37
38
#ifdef __INCvxWorksh
39
#include <ioLib.h>
/* for FIONBIO */
40
#endif
/* __INCvxWorksh */
41
42
#ifdef __MINGW32__
43
/* getpid() is defined as a function in MingW but this conflict with our definition as
44
* macro later in this file, so include unistd.h to get function definition earlier and
45
* avoid errors including unistd.h header later in the code */
46
#include <unistd.h>
47
#endif
48
49
#if defined(DOS32X)
50
#define READSOCKET(a,b,c) recv((a), (b), (c), TDS_NOSIGNAL)
51
#define WRITESOCKET(a,b,c) send((a), (b), (c), TDS_NOSIGNAL)
52
#define CLOSESOCKET(a) closesocket((a))
53
#define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (char*)(c))
54
#define SOCKLEN_T int
55
#define select select_s
56
typedef
int
pid_t;
57
#define strcasecmp stricmp
58
#define strncasecmp strnicmp
59
/* TODO this has nothing to do with ip ... */
60
#define getpid() _gethostid()
61
#endif
/* defined(DOS32X) */
62
63
#ifdef _WIN32
64
#include <freetds/windows.h>
65
#define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
66
#define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
67
#define CLOSESOCKET(a) closesocket((a))
68
#define IOCTLSOCKET(a,b,c) ioctlsocket((a), (b), (c))
69
#define SOCKLEN_T int
70
static
inline
int
71
tds_socket_init(
void
)
72
{
73
WSADATA wsadata;
74
75
return
WSAStartup(MAKEWORD(2, 2), &wsadata);
76
}
77
78
static
inline
void
79
tds_socket_done(
void
)
80
{
81
WSACleanup();
82
}
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_ETIMEDOUT WSAETIMEDOUT
88
#define TDSSOCK_WOULDBLOCK(e) ((e)==WSAEWOULDBLOCK)
89
#define TDSSOCK_ECONNRESET WSAECONNRESET
90
#define sock_errno WSAGetLastError()
91
#define set_sock_errno(err) WSASetLastError(err)
92
#define sock_strerror(n) tds_prwsaerror(n)
93
#define sock_strerror_free(s) tds_prwsaerror_free(s)
94
#ifndef __MINGW32__
95
typedef
DWORD pid_t;
96
#endif
97
#undef strcasecmp
98
#define strcasecmp stricmp
99
#undef strncasecmp
100
#define strncasecmp strnicmp
101
#if defined(HAVE__SNPRINTF) && !defined(HAVE_SNPRINTF)
102
#define snprintf _snprintf
103
#endif
104
105
/* use macros to use new style names */
106
#if defined(__MSVCRT__) || defined(_MSC_VER)
107
/* Use API as always present and not causing problems */
108
#undef getpid
109
#define getpid() GetCurrentProcessId()
110
#define strdup(s) _strdup(s)
111
#define unlink(f) _unlink(f)
112
#define putenv(s) _putenv(s)
113
#undef fileno
114
#define fileno(f) _fileno(f)
115
#undef close
116
#define close(f) _close(f)
117
#undef open
118
#define open(fn,...) _open(fn,__VA_ARGS__)
119
#undef dup2
120
#define dup2(o,n) _dup2(o,n)
121
#define stricmp(s1,s2) _stricmp(s1,s2)
122
#define strnicmp(s1,s2,n) _strnicmp(s1,s2,n)
123
#endif
124
125
#endif
/* defined(_WIN32) */
126
127
#ifndef sock_errno
128
#define sock_errno errno
129
#endif
130
131
#ifndef set_sock_errno
132
#define set_sock_errno(err) do { errno = (err); } while(0)
133
#endif
134
135
#ifndef sock_strerror
136
#define sock_strerror(n) strerror(n)
137
#define sock_strerror_free(s) do {} while(0)
138
#endif
139
140
#ifndef TDSSOCK_EINTR
141
#define TDSSOCK_EINTR EINTR
142
#endif
143
144
#ifndef TDSSOCK_EINPROGRESS
145
#define TDSSOCK_EINPROGRESS EINPROGRESS
146
#endif
147
148
#ifndef TDSSOCK_ETIMEDOUT
149
#define TDSSOCK_ETIMEDOUT ETIMEDOUT
150
#endif
151
152
#ifndef TDSSOCK_WOULDBLOCK
153
# if defined(EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
154
# define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN||(e)==EWOULDBLOCK)
155
# else
156
# define TDSSOCK_WOULDBLOCK(e) ((e)==EAGAIN)
157
# endif
158
#endif
159
160
#ifndef TDSSOCK_ECONNRESET
161
#define TDSSOCK_ECONNRESET ECONNRESET
162
#endif
163
164
#ifndef _WIN32
165
static
inline
int
166
tds_socket_init(
void
)
167
{
168
return
0;
169
}
170
171
static
inline
void
172
tds_socket_done(
void
)
173
{
174
}
175
#endif
176
177
#ifndef READSOCKET
178
# ifdef MSG_NOSIGNAL
179
# define READSOCKET(s,b,l) recv((s), (b), (l), MSG_NOSIGNAL)
180
# else
181
# define READSOCKET(s,b,l) read((s), (b), (l))
182
# endif
183
#endif
/* !READSOCKET */
184
185
#ifndef WRITESOCKET
186
# ifdef MSG_NOSIGNAL
187
# define WRITESOCKET(s,b,l) send((s), (b), (l), MSG_NOSIGNAL)
188
# else
189
# define WRITESOCKET(s,b,l) write((s), (b), (l))
190
# endif
191
#endif
/* !WRITESOCKET */
192
193
#ifndef CLOSESOCKET
194
#define CLOSESOCKET(s) close((s))
195
#endif
/* !CLOSESOCKET */
196
197
#ifndef IOCTLSOCKET
198
#define IOCTLSOCKET(s,b,l) ioctl((s), (b), (l))
199
#endif
/* !IOCTLSOCKET */
200
201
#ifndef SOCKLEN_T
202
# define SOCKLEN_T socklen_t
203
#endif
204
205
#ifndef _WIN32
206
typedef
int
TDS_SYS_SOCKET;
207
#define INVALID_SOCKET -1
208
#define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
209
#else
210
typedef
SOCKET TDS_SYS_SOCKET;
211
#define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
212
#endif
213
214
#define tds_accept accept
215
#define tds_getpeername getpeername
216
#define tds_getsockopt getsockopt
217
#define tds_getsockname getsockname
218
#define tds_recvfrom recvfrom
219
220
#if defined(__hpux__) && SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
221
# if HAVE__XPG_ACCEPT
222
# undef tds_accept
223
# define tds_accept _xpg_accept
224
# elif HAVE___ACCEPT
225
# undef tds_accept
226
# define tds_accept __accept
227
# endif
228
# if HAVE__XPG_GETPEERNAME
229
# undef tds_getpeername
230
# define tds_getpeername _xpg_getpeername
231
# elif HAVE___GETPEERNAME
232
# undef tds_getpeername
233
# define tds_getpeername __getpeername
234
# endif
235
# if HAVE__XPG_GETSOCKOPT
236
# undef tds_getsockopt
237
# define tds_getsockopt _xpg_getsockopt
238
# elif HAVE___GETSOCKOPT
239
# undef tds_getsockopt
240
# define tds_getsockopt __getsockopt
241
# endif
242
# if HAVE__XPG_GETSOCKNAME
243
# undef tds_getsockname
244
# define tds_getsockname _xpg_getsockname
245
# elif HAVE___GETSOCKNAME
246
# undef tds_getsockname
247
# define tds_getsockname __getsockname
248
# endif
249
# if HAVE__XPG_RECVFROM
250
# undef tds_recvfrom
251
# define tds_recvfrom _xpg_recvfrom
252
# elif HAVE___RECVFROM
253
# undef tds_recvfrom
254
# define tds_recvfrom __recvfrom
255
# endif
256
#endif
257
258
#ifdef HAVE_STDINT_H
259
#include <stdint.h>
260
#endif
261
262
#ifdef HAVE_INTTYPES_H
263
#include <inttypes.h>
264
#endif
265
266
#ifndef PRId64
267
#define PRId64 TDS_I64_PREFIX "d"
268
#endif
269
#ifndef PRIu64
270
#define PRIu64 TDS_I64_PREFIX "u"
271
#endif
272
#ifndef PRIx64
273
#define PRIx64 TDS_I64_PREFIX "x"
274
#endif
275
276
#ifndef UINT64_C
277
# if SIZEOF_INT >= 8
278
# define UINT64_C(c) c ## U
279
# define INT64_C(c) c
280
# elif SIZEOF_LONG >= 8
281
# define UINT64_C(c) c ## UL
282
# define INT64_C(c) c ## L
283
# elif SIZEOF_LONG_LONG >= 8
284
# define UINT64_C(c) c ## ULL
285
# define INT64_C(c) c ## LL
286
# elif SIZEOF___INT64 >= 8
287
# define UINT64_C(c) c ## ui64
288
# define INT64_C(c) c ## i64
289
# else
290
# error Unable to understand how to define 64 bit constants
291
# endif
292
#endif
293
294
#include <freetds/sysdep_types.h>
295
296
#endif
/* _tdsguard_gbdINUKdHN7rAOavGyKkWw_ */
Generated by
1.9.8