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