FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 #define strlcpy(d,s,l) tds_strlcpy(d,s,l)
80 #endif
81 
82 #if !HAVE_GETADDRINFO
83 typedef struct tds_addrinfo {
84  int ai_flags;
85  int ai_family;
86  int ai_socktype;
87  int ai_protocol;
88  size_t ai_addrlen;
89  struct sockaddr *ai_addr;
90  char *ai_canonname;
91  struct tds_addrinfo *ai_next;
92 } tds_addrinfo;
93 
94 int tds_getaddrinfo(const char *node, const char *service, const struct tds_addrinfo *hints, struct tds_addrinfo **res);
95 int tds_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
96 void tds_freeaddrinfo(struct tds_addrinfo *addr);
97 #define addrinfo tds_addrinfo
98 #define getaddrinfo(n,s,h,r) tds_getaddrinfo(n,s,h,r)
99 #define getnameinfo(a,b,c,d,e,f,g) tds_getnameinfo(a,b,c,d,e,f,g)
100 #define freeaddrinfo(a) tds_freeaddrinfo(a)
101 #endif
102 
103 #ifndef AI_FQDN
104 #define AI_FQDN 0
105 #endif
106 
107 #if !HAVE_STRLCAT
108 size_t tds_strlcat(char *dest, const char *src, size_t len);
109 #define strlcat(d,s,l) tds_strlcat(d,s,l)
110 #endif
111 
112 #if !HAVE_BASENAME
113 char *tds_basename(char *path);
114 #define basename(path) tds_basename(path)
115 #endif
116 
117 /*
118  * Microsoft's C Runtime library is missing strcasecmp and strncasecmp.
119  * Other Win32 C runtime libraries, notably minwg, may define it.
120  * There is no symbol uniquely defined in Microsoft's header files that
121  * can be used by the preprocessor to know whether we're compiling for
122  * Microsoft's library or not (or which version). Thus there's no
123  * way to automatically decide whether or not to define strcasecmp
124  * in terms of stricmp.
125  *
126  * The Microsoft *compiler* defines _MSC_VER. On the assumption that
127  * anyone using their compiler is also using their library, the below
128  * tests check _MSC_VER as a proxy.
129  */
130 #if defined(_WIN32)
131 # if !defined(strcasecmp) && defined(_MSC_VER)
132 # define strcasecmp(A, B) stricmp((A), (B))
133 # endif
134 # if !defined(strncasecmp) && defined(_MSC_VER)
135 # define strncasecmp(x,y,z) strnicmp((x),(y),(z))
136 # endif
137 
138 #undef gettimeofday
139 int tds_gettimeofday (struct timeval *tv, void *tz);
140 #define gettimeofday tds_gettimeofday
141 
142 /* Older Mingw-w64 versions don't define these flags. */
143 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
144 # define AI_ADDRCONFIG 0x00000400
145 #endif
146 #if defined(__MINGW32__) && !defined(AI_V4MAPPED)
147 # define AI_V4MAPPED 0x00000800
148 #endif
149 
150 #endif
151 
152 #if !HAVE_GETOPT
153 #undef getopt
154 int tds_getopt(int argc, char * const argv[], const char *optstring);
155 #define getopt tds_getopt
156 
157 extern char *optarg;
158 extern int optind, offset, opterr, optreset;
159 #endif
160 
161 #if !HAVE_SOCKETPAIR
162 int tds_socketpair(int domain, int type, int protocol, TDS_SYS_SOCKET sv[2]);
163 #define socketpair(d,t,p,s) tds_socketpair(d,t,p,s)
164 #endif
165 
166 #if !HAVE_DAEMON
167 int tds_daemon(int no_chdir, int no_close);
168 #define daemon(d,c) tds_daemon(d,c)
169 #endif
170 
171 char *tds_getpassarg(char *arg);
172 void tds_sleep_s(unsigned sec);
173 void tds_sleep_ms(unsigned ms);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #include <freetds/popvis.h>
180 
181 #endif
Provide poll call where missing.
Definition: replacements.h:83