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 /* $Id: replacements.h,v 1.31 2011-09-01 07:52:44 freddy77 Exp $ */
24 
25 #include <stdarg.h>
26 #include "tds_sysdep_public.h"
27 #include <freetds/sysdep_private.h>
28 
29 #include <replacements/readpassphrase.h>
30 
31 /* these headers are needed for basename */
32 #ifdef HAVE_STRING_H
33 # include <string.h>
34 #endif
35 #ifdef HAVE_LIBGEN_H
36 # include <libgen.h>
37 #endif
38 
39 #if !HAVE_POLL
40 #include <replacements/poll.h>
41 #endif /* !HAVE_POLL */
42 
43 #include <freetds/pushvis.h>
44 
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #endif
49 
50 #if !HAVE_VSNPRINTF
51 #if HAVE__VSNPRINTF
52 #undef vsnprintf
53 #define vsnprintf _vsnprintf
54 #else
55 int vsnprintf(char *ret, size_t max, const char *fmt, va_list ap);
56 #endif /* !HAVE__VSNPRINTF */
57 #endif /* HAVE_VSNPRINTF */
58 
59 #if !HAVE_ASPRINTF
60 #undef asprintf
61 int tds_asprintf(char **ret, const char *fmt, ...);
62 #define asprintf tds_asprintf
63 #endif /* !HAVE_ASPRINTF */
64 
65 #if !HAVE_VASPRINTF
66 #undef vasprintf
67 int tds_vasprintf(char **ret, const char *fmt, va_list ap);
68 #define vasprintf tds_vasprintf
69 #endif /* !HAVE_VASPRINTF */
70 
71 #if !HAVE_STRTOK_R
72 /* Some MingW define strtok_r macro thread-safe but not reentrant but we
73  need both so avoid using the macro */
74 #undef strtok_r
75 char *tds_strtok_r(char *str, const char *sep, char **lasts);
76 #define strtok_r tds_strtok_r
77 #endif /* !HAVE_STRTOK_R */
78 
79 #if !HAVE_STRSEP
80 #undef strsep
81 char *tds_strsep(char **stringp, const char *delim);
82 #define strsep tds_strsep
83 #endif /* !HAVE_STRSEP */
84 
85 #if !HAVE_STRLCPY
86 size_t tds_strlcpy(char *dest, const char *src, size_t len);
87 #define strlcpy(d,s,l) tds_strlcpy(d,s,l)
88 #endif
89 
90 #if !HAVE_GETADDRINFO
91 typedef struct tds_addrinfo {
92  int ai_flags;
93  int ai_family;
94  int ai_socktype;
95  int ai_protocol;
96  size_t ai_addrlen;
97  struct sockaddr *ai_addr;
98  char *ai_canonname;
99  struct tds_addrinfo *ai_next;
100 } tds_addrinfo;
101 
102 int tds_getaddrinfo(const char *node, const char *service, const struct tds_addrinfo *hints, struct tds_addrinfo **res);
103 int tds_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
104 void tds_freeaddrinfo(struct tds_addrinfo *addr);
105 #define addrinfo tds_addrinfo
106 #define getaddrinfo(n,s,h,r) tds_getaddrinfo(n,s,h,r)
107 #define getnameinfo(a,b,c,d,e,f,g) tds_getnameinfo(a,b,c,d,e,f,g)
108 #define freeaddrinfo(a) tds_freeaddrinfo(a)
109 #endif
110 
111 #ifndef AI_FQDN
112 #define AI_FQDN 0
113 #endif
114 
115 #if !HAVE_STRLCAT
116 size_t tds_strlcat(char *dest, const char *src, size_t len);
117 #define strlcat(d,s,l) tds_strlcat(d,s,l)
118 #endif
119 
120 #if !HAVE_BASENAME
121 char *tds_basename(char *path);
122 #define basename(path) tds_basename(path)
123 #endif
124 
125 /*
126  * Microsoft's C Runtime library is missing strcasecmp and strncasecmp.
127  * Other Win32 C runtime libraries, notably minwg, may define it.
128  * There is no symbol uniquely defined in Microsoft's header files that
129  * can be used by the preprocessor to know whether we're compiling for
130  * Microsoft's library or not (or which version). Thus there's no
131  * way to automatically decide whether or not to define strcasecmp
132  * in terms of stricmp.
133  *
134  * The Microsoft *compiler* defines _MSC_VER. On the assumption that
135  * anyone using their compiler is also using their library, the below
136  * tests check _MSC_VER as a proxy.
137  */
138 #if defined(_WIN32)
139 # if !defined(strcasecmp) && defined(_MSC_VER)
140 # define strcasecmp(A, B) stricmp((A), (B))
141 # endif
142 # if !defined(strncasecmp) && defined(_MSC_VER)
143 # define strncasecmp(x,y,z) strnicmp((x),(y),(z))
144 # endif
145 
146 #undef gettimeofday
147 int tds_gettimeofday (struct timeval *tv, void *tz);
148 #define gettimeofday tds_gettimeofday
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 char *tds_getpassarg(char *arg);
167 void tds_sleep_s(unsigned sec);
168 void tds_sleep_ms(unsigned ms);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #include <freetds/popvis.h>
175 
176 #endif
Definition: replacements.h:91
Provide poll call where missing.