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 _tdsguard_fELDB9J1dGrLHROMPkGfXj_
21 #define _tdsguard_fELDB9J1dGrLHROMPkGfXj_
22 
23 #ifndef _freetds_config_h_
24 #error should include config.h before
25 #endif
26 
27 #include <stdarg.h>
28 #include "tds_sysdep_public.h"
29 #include <freetds/sysdep_private.h>
30 
31 #include <freetds/replacements/readpassphrase.h>
32 
33 /* these headers are needed for basename */
34 #ifdef HAVE_STRING_H
35 # include <string.h>
36 #endif
37 #ifdef HAVE_LIBGEN_H
38 # include <libgen.h>
39 #endif
40 #ifdef HAVE_GETOPT_H
41 # include <getopt.h>
42 #endif
43 
44 #if !HAVE_POLL
46 #elif HAVE_POLL_H
47 #include <poll.h>
48 #endif /* !HAVE_POLL */
49 
50 #include <freetds/pushvis.h>
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 #if !HAVE_ASPRINTF
58 #undef asprintf
59 int tds_asprintf(char **ret, const char *fmt, ...);
60 #define asprintf tds_asprintf
61 #endif /* !HAVE_ASPRINTF */
62 
63 #if !HAVE_VASPRINTF
64 #undef vasprintf
65 int tds_vasprintf(char **ret, const char *fmt, va_list ap);
66 #define vasprintf tds_vasprintf
67 #endif /* !HAVE_VASPRINTF */
68 
69 #if !HAVE_STRTOK_R
70 /* Some MinGW define strtok_r macro thread-safe but not reentrant but we
71  need both so avoid using the macro */
72 #undef strtok_r
73 #if defined(_WIN32) && HAVE_STRTOK_S
74 #define strtok_r strtok_s
75 #else
76 char *tds_strtok_r(char *str, const char *sep, char **lasts);
77 #define strtok_r tds_strtok_r
78 #endif
79 #endif /* !HAVE_STRTOK_R */
80 
81 #if !HAVE_STRSEP
82 #undef strsep
83 char *tds_strsep(char **stringp, const char *delim);
84 #define strsep tds_strsep
85 #endif /* !HAVE_STRSEP */
86 
87 #if !HAVE_STRLCPY
88 size_t tds_strlcpy(char *dest, const char *src, size_t len);
89 #undef strlcpy
90 #define strlcpy(d,s,l) tds_strlcpy(d,s,l)
91 #endif
92 
93 #if !HAVE_GETADDRINFO
94 typedef struct tds_addrinfo {
95  int ai_flags;
96  int ai_family;
97  int ai_socktype;
98  int ai_protocol;
99  size_t ai_addrlen;
100  struct sockaddr *ai_addr;
101  char *ai_canonname;
102  struct tds_addrinfo *ai_next;
103 } tds_addrinfo;
104 
105 int tds_getaddrinfo(const char *node, const char *service, const struct tds_addrinfo *hints, struct tds_addrinfo **res);
106 int tds_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
107 void tds_freeaddrinfo(struct tds_addrinfo *addr);
108 #define addrinfo tds_addrinfo
109 #define getaddrinfo(n,s,h,r) tds_getaddrinfo(n,s,h,r)
110 #define getnameinfo(a,b,c,d,e,f,g) tds_getnameinfo(a,b,c,d,e,f,g)
111 #define freeaddrinfo(a) tds_freeaddrinfo(a)
112 #endif
113 
114 #ifndef AI_FQDN
115 #define AI_FQDN 0
116 #endif
117 
118 #if !HAVE_STRLCAT
119 size_t tds_strlcat(char *dest, const char *src, size_t len);
120 #undef strlcat
121 #define strlcat(d,s,l) tds_strlcat(d,s,l)
122 #endif
123 
124 #if !HAVE_BASENAME
125 char *tds_basename(char *path);
126 #define basename(path) tds_basename(path)
127 #endif
128 
129 /*
130  * Microsoft's C Runtime library is missing strcasecmp and strncasecmp.
131  * Other Win32 C runtime libraries, notably MinGW, may define it.
132  * There is no symbol uniquely defined in Microsoft's header files that
133  * can be used by the preprocessor to know whether we're compiling for
134  * Microsoft's library or not (or which version). Thus there's no
135  * way to automatically decide whether or not to define strcasecmp
136  * in terms of stricmp.
137  *
138  * The Microsoft *compiler* defines _MSC_VER. On the assumption that
139  * anyone using their compiler is also using their library, the below
140  * tests check _MSC_VER as a proxy.
141  */
142 #if defined(_WIN32)
143 # if !defined(strcasecmp) && defined(_MSC_VER)
144 # define strcasecmp(A, B) stricmp((A), (B))
145 # endif
146 # if !defined(strncasecmp) && defined(_MSC_VER)
147 # define strncasecmp(x,y,z) strnicmp((x),(y),(z))
148 # endif
149 
150 #undef gettimeofday
151 int tds_gettimeofday (struct timeval *tv, void *tz);
152 #define gettimeofday tds_gettimeofday
153 
154 /* Older MinGW-w64 versions don't define these flags. */
155 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
156 # define AI_ADDRCONFIG 0x00000400
157 #endif
158 #if defined(__MINGW32__) && !defined(AI_V4MAPPED)
159 # define AI_V4MAPPED 0x00000800
160 #endif
161 
162 #endif
163 
164 #if defined(_WIN32) && defined(_MSC_VER)
165 #define tds_strtoll _strtoi64
166 #else
167 #define tds_strtoll strtoll
168 #endif
169 
170 #if !HAVE_GETOPT
171 #undef getopt
172 int tds_getopt(int argc, char * const argv[], const char *optstring);
173 #define getopt tds_getopt
174 
175 extern char *optarg;
176 extern int optind, offset, opterr, optreset;
177 #endif
178 
179 #if !HAVE_SOCKETPAIR
180 int tds_socketpair(int domain, int type, int protocol, TDS_SYS_SOCKET sv[2]);
181 #define socketpair(d,t,p,s) tds_socketpair(d,t,p,s)
182 #endif
183 
184 #if !HAVE_DAEMON
185 int tds_daemon(int no_chdir, int no_close);
186 #define daemon(d,c) tds_daemon(d,c)
187 #endif
188 
189 #if !HAVE_SETENV
190 int tds_setenv(const char *name, const char *value, int overwrite);
191 #define setenv(n,v,o) tds_setenv(n,v,o)
192 int tds_unsetenv(const char *name);
193 #define unsetenv(n) tds_unsetenv(n)
194 #endif
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #include <freetds/popvis.h>
201 
202 #endif
Provide poll call where missing.
Definition: replacements.h:94