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 
37 #if !HAVE_POLL
38 #include <replacements/poll.h>
39 #endif /* !HAVE_POLL */
40 
41 #include <freetds/pushvis.h>
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 #if !HAVE_ASPRINTF
49 #undef asprintf
50 int tds_asprintf(char **ret, const char *fmt, ...);
51 #define asprintf tds_asprintf
52 #endif /* !HAVE_ASPRINTF */
53 
54 #if !HAVE_VASPRINTF
55 #undef vasprintf
56 int tds_vasprintf(char **ret, const char *fmt, va_list ap);
57 #define vasprintf tds_vasprintf
58 #endif /* !HAVE_VASPRINTF */
59 
60 #if !HAVE_STRTOK_R
61 /* Some MingW define strtok_r macro thread-safe but not reentrant but we
62  need both so avoid using the macro */
63 #undef strtok_r
64 char *tds_strtok_r(char *str, const char *sep, char **lasts);
65 #define strtok_r tds_strtok_r
66 #endif /* !HAVE_STRTOK_R */
67 
68 #if !HAVE_STRSEP
69 #undef strsep
70 char *tds_strsep(char **stringp, const char *delim);
71 #define strsep tds_strsep
72 #endif /* !HAVE_STRSEP */
73 
74 #if !HAVE_STRLCPY
75 size_t tds_strlcpy(char *dest, const char *src, size_t len);
76 #define strlcpy(d,s,l) tds_strlcpy(d,s,l)
77 #endif
78 
79 #if !HAVE_GETADDRINFO
80 typedef struct tds_addrinfo {
81  int ai_flags;
82  int ai_family;
83  int ai_socktype;
84  int ai_protocol;
85  size_t ai_addrlen;
86  struct sockaddr *ai_addr;
87  char *ai_canonname;
88  struct tds_addrinfo *ai_next;
89 } tds_addrinfo;
90 
91 int tds_getaddrinfo(const char *node, const char *service, const struct tds_addrinfo *hints, struct tds_addrinfo **res);
92 int tds_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
93 void tds_freeaddrinfo(struct tds_addrinfo *addr);
94 #define addrinfo tds_addrinfo
95 #define getaddrinfo(n,s,h,r) tds_getaddrinfo(n,s,h,r)
96 #define getnameinfo(a,b,c,d,e,f,g) tds_getnameinfo(a,b,c,d,e,f,g)
97 #define freeaddrinfo(a) tds_freeaddrinfo(a)
98 #endif
99 
100 #ifndef AI_FQDN
101 #define AI_FQDN 0
102 #endif
103 
104 #if !HAVE_STRLCAT
105 size_t tds_strlcat(char *dest, const char *src, size_t len);
106 #define strlcat(d,s,l) tds_strlcat(d,s,l)
107 #endif
108 
109 #if !HAVE_BASENAME
110 char *tds_basename(char *path);
111 #define basename(path) tds_basename(path)
112 #endif
113 
114 /*
115  * Microsoft's C Runtime library is missing strcasecmp and strncasecmp.
116  * Other Win32 C runtime libraries, notably minwg, may define it.
117  * There is no symbol uniquely defined in Microsoft's header files that
118  * can be used by the preprocessor to know whether we're compiling for
119  * Microsoft's library or not (or which version). Thus there's no
120  * way to automatically decide whether or not to define strcasecmp
121  * in terms of stricmp.
122  *
123  * The Microsoft *compiler* defines _MSC_VER. On the assumption that
124  * anyone using their compiler is also using their library, the below
125  * tests check _MSC_VER as a proxy.
126  */
127 #if defined(_WIN32)
128 # if !defined(strcasecmp) && defined(_MSC_VER)
129 # define strcasecmp(A, B) stricmp((A), (B))
130 # endif
131 # if !defined(strncasecmp) && defined(_MSC_VER)
132 # define strncasecmp(x,y,z) strnicmp((x),(y),(z))
133 # endif
134 
135 #undef gettimeofday
136 int tds_gettimeofday (struct timeval *tv, void *tz);
137 #define gettimeofday tds_gettimeofday
138 
139 #endif
140 
141 #if !HAVE_GETOPT
142 #undef getopt
143 int tds_getopt(int argc, char * const argv[], const char *optstring);
144 #define getopt tds_getopt
145 
146 extern char *optarg;
147 extern int optind, offset, opterr, optreset;
148 #endif
149 
150 #if !HAVE_SOCKETPAIR
151 int tds_socketpair(int domain, int type, int protocol, TDS_SYS_SOCKET sv[2]);
152 #define socketpair(d,t,p,s) tds_socketpair(d,t,p,s)
153 #endif
154 
155 char *tds_getpassarg(char *arg);
156 void tds_sleep_s(unsigned sec);
157 void tds_sleep_ms(unsigned ms);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #include <freetds/popvis.h>
164 
165 #endif
Provide poll call where missing.
Definition: replacements.h:80