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