FreeTDS API: include/replacements.h Source File

FreeTDS API

replacements.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 1998-1999 Brian Bruns
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef _replacements_h_
21 #define _replacements_h_
22
23 #include <stdarg.h>
24 #include "tds_sysdep_public.h"
25 #include <freetds/sysdep_private.h>
26
27 #include <replacements/readpassphrase.h>
28
29 /* these headers are needed for basename */
30 #ifdef HAVE_STRING_H
31 # include <string.h>
32 #endif
33 #ifdef HAVE_LIBGEN_H
34 # include <libgen.h>
35 #endif
36 #ifdef HAVE_GETOPT_H
37 # include <getopt.h>
38 #endif
39
40 #if !HAVE_POLL
41 #include <replacements/poll.h>
42 #endif /* !HAVE_POLL */
43
44 #include <freetds/pushvis.h>
45
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50
51 #if !HAVE_ASPRINTF
52 #undef asprintf
53 int tds_asprintf(char **ret, const char *fmt, ...);
54 #define asprintf tds_asprintf
55 #endif /* !HAVE_ASPRINTF */
56
57 #if !HAVE_VASPRINTF
58 #undef vasprintf
59 int tds_vasprintf(char **ret, const char *fmt, va_list ap);
60 #define vasprintf tds_vasprintf
61 #endif /* !HAVE_VASPRINTF */
62
63 #if !HAVE_STRTOK_R
64 /* Some MingW define strtok_r macro thread-safe but not reentrant but we
65 need both so avoid using the macro */
66 #undef strtok_r
67 char *tds_strtok_r(char *str, const char *sep, char **lasts);
68 #define strtok_r tds_strtok_r
69 #endif /* !HAVE_STRTOK_R */
70
71 #if !HAVE_STRSEP
72 #undef strsep
73 char *tds_strsep(char **stringp, const char *delim);
74 #define strsep tds_strsep
75 #endif /* !HAVE_STRSEP */
76
77 #if !HAVE_STRLCPY
78 size_t tds_strlcpy(char *dest, const char *src, size_t len);
79 #undef strlcpy
80 #define strlcpy(d,s,l) tds_strlcpy(d,s,l)
81 #endif
82
83 #if !HAVE_GETADDRINFO
84 typedef struct tds_addrinfo {
85 int ai_flags;
86 int ai_family;
87 int ai_socktype;
88 int ai_protocol;
89 size_t ai_addrlen;
90 struct sockaddr *ai_addr;
91 char *ai_canonname;
92 struct tds_addrinfo *ai_next;
93 } tds_addrinfo;
94
95 int tds_getaddrinfo(const char *node, const char *service, const struct tds_addrinfo *hints, struct tds_addrinfo **res);
96 int tds_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
97 void tds_freeaddrinfo(struct tds_addrinfo *addr);
98 #define addrinfo tds_addrinfo
99 #define getaddrinfo(n,s,h,r) tds_getaddrinfo(n,s,h,r)
100 #define getnameinfo(a,b,c,d,e,f,g) tds_getnameinfo(a,b,c,d,e,f,g)
101 #define freeaddrinfo(a) tds_freeaddrinfo(a)
102 #endif
103
104 #ifndef AI_FQDN
105 #define AI_FQDN 0
106 #endif
107
108 #if !HAVE_STRLCAT
109 size_t tds_strlcat(char *dest, const char *src, size_t len);
110 #undef strlcat
111 #define strlcat(d,s,l) tds_strlcat(d,s,l)
112 #endif
113
114 #if !HAVE_BASENAME
115 char *tds_basename(char *path);
116 #define basename(path) tds_basename(path)
117 #endif
118
119 /*
120 * Microsoft's C Runtime library is missing strcasecmp and strncasecmp.
121 * Other Win32 C runtime libraries, notably minwg, may define it.
122 * There is no symbol uniquely defined in Microsoft's header files that
123 * can be used by the preprocessor to know whether we're compiling for
124 * Microsoft's library or not (or which version). Thus there's no
125 * way to automatically decide whether or not to define strcasecmp
126 * in terms of stricmp.
127 *
128 * The Microsoft *compiler* defines _MSC_VER. On the assumption that
129 * anyone using their compiler is also using their library, the below
130 * tests check _MSC_VER as a proxy.
131 */
132 #if defined(_WIN32)
133 # if !defined(strcasecmp) && defined(_MSC_VER)
134 # define strcasecmp(A, B) stricmp((A), (B))
135 # endif
136 # if !defined(strncasecmp) && defined(_MSC_VER)
137 # define strncasecmp(x,y,z) strnicmp((x),(y),(z))
138 # endif
139
140 #undef gettimeofday
141 int tds_gettimeofday (struct timeval *tv, void *tz);
142 #define gettimeofday tds_gettimeofday
143
144 /* Older Mingw-w64 versions don't define these flags. */
145 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
146 # define AI_ADDRCONFIG 0x00000400
147 #endif
148 #if defined(__MINGW32__) && !defined(AI_V4MAPPED)
149 # define AI_V4MAPPED 0x00000800
150 #endif
151
152 #endif
153
154 #if !HAVE_GETOPT
155 #undef getopt
156 int tds_getopt(int argc, char * const argv[], const char *optstring);
157 #define getopt tds_getopt
158
159 extern char *optarg;
160 extern int optind, offset, opterr, optreset;
161 #endif
162
163 #if !HAVE_SOCKETPAIR
164 int tds_socketpair(int domain, int type, int protocol, TDS_SYS_SOCKET sv[2]);
165 #define socketpair(d,t,p,s) tds_socketpair(d,t,p,s)
166 #endif
167
168 #if !HAVE_DAEMON
169 int tds_daemon(int no_chdir, int no_close);
170 #define daemon(d,c) tds_daemon(d,c)
171 #endif
172
173 char *tds_getpassarg(char *arg);
174 void tds_sleep_s(unsigned sec);
175 void tds_sleep_ms(unsigned ms);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #include <freetds/popvis.h>
182
183 #endif
poll.h
Provide poll call where missing.
tds_addrinfo
Definition: replacements.h:84