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