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