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