FreeTDS API: include/replacements.h Source File

FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

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