Add a Cygwin check
[freeradius.git] / src / include / missing.h
1 #ifndef _FR_MISSING_H
2 #define _FR_MISSING_H
3
4 /*
5  * missing.h    Replacements for functions that are or can be
6  *              missing on some platforms.
7  *
8  * Version:     $Id$
9  *
10  */
11
12 #include <freeradius-devel/ident.h>
13 RCSIDH(missing_h, "$Id$")
14
15 #include <freeradius-devel/autoconf.h>
16
17 #ifdef HAVE_STDINT_H
18 #include <stdint.h>
19 #endif
20
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24
25 #ifdef HAVE_INTTYPES_H
26 #include <inttypes.h>
27 #endif
28
29 #ifdef HAVE_STRINGS_H
30 #include <strings.h>
31 #endif
32
33 #ifdef HAVE_STRING_H
34 #include <string.h>
35 #endif
36
37 #ifdef HAVE_NETDB_H
38 #include <netdb.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 #include        <netinet/in.h>
43 #endif
44
45 #ifdef HAVE_ARPA_INET_H
46 #include        <arpa/inet.h>
47 #endif
48
49 #ifdef HAVE_SYS_SELECT_H
50 #include <sys/select.h>
51 #endif
52
53 #ifdef HAVE_UNISTD_H
54 #include <unistd.h>
55 #endif
56
57 /*
58  *  Check for inclusion of <time.h>, versus <sys/time.h>
59  *  Taken verbatim from the autoconf manual.
60  */
61 #if TIME_WITH_SYS_TIME
62 # include <sys/time.h>
63 # include <time.h>
64 #else
65 # ifdef HAVE_SYS_TIME_H
66 #  include <sys/time.h>
67 # else
68 #  include <time.h>
69 # endif
70 #endif
71
72 #ifndef CYGWIN
73 #ifdef HAVE_WINSOCK_H
74 #include <winsock.h>
75 #endif
76 #endif
77
78 /*
79  *      Functions from missing.c
80  */
81
82 #ifndef HAVE_STRNCASECMP
83 extern int strncasecmp(char *s1, char *s2, int n);
84 #endif
85
86 #ifndef HAVE_STRCASECMP
87 extern int strcasecmp(char *s1, char *s2);
88 #endif
89
90 #ifndef HAVE_STRSEP
91 extern char *strsep(char **stringp, const char *delim);
92 #endif
93
94 #ifndef HAVE_LOCALTIME_R
95 struct tm;
96 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
97 #endif
98
99 #ifndef HAVE_CTIME_R
100 char *ctime_r(const time_t *l_clock, char *l_buf);
101 #endif
102
103 #ifdef NEED_DECLARATION_CRYPT
104 char *crypt(char *key, char *salt);
105 #endif
106
107 #ifdef NEED_DECLARATION_STRNCASECMP
108 int strncasecmp(char *s1, char *s2, int n);
109 #endif
110
111 #ifdef NEED_DECLARATION_STRCASECMP
112 int strcasecmp(char *s1, char *s2);
113 #endif
114
115 #ifdef NEED_DECLARATION_INET_ATON
116 struct in_addr;
117 int inet_aton(char *cp, struct in_addr *inp);
118 #endif
119
120 #ifndef HAVE_SETLINEBUF
121 #ifdef HAVE_SETVBUF
122 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
123 #else
124 #define setlinebuf(x)     0
125 #endif
126 #endif
127
128 #ifdef NEED_DECLARATION_SETLINEBUF
129 #define setlinebuf(x)     0
130 #endif
131
132 #ifdef NEED_DECLARATION_GETUSERSHELL
133 char *getusershell(void);
134 #endif
135
136 #ifdef NEED_DECLARATION_ENDUSERSHELL
137 void endusershell(void);
138 #endif
139
140 #ifndef INADDR_ANY
141 #define INADDR_ANY      ((uint32_t) 0x00000000)
142 #endif
143
144 #ifndef INADDR_LOOPBACK
145 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
146 #endif
147
148 #ifndef INADDR_NONE
149 #define INADDR_NONE     ((uint32_t) 0xffffffff)
150 #endif
151
152 #ifndef INADDRSZ
153 #define INADDRSZ 4
154 #endif
155
156 #ifndef INET_ADDRSTRLEN
157 #define INET_ADDRSTRLEN 16
158 #endif
159
160 #ifndef AF_UNSPEC
161 #define AF_UNSPEC 0
162 #endif
163
164 #ifndef AF_INET6
165 #define AF_INET6 10
166 #endif
167
168 #ifndef HAVE_STRUCT_IN6_ADDR
169 struct in6_addr
170 {
171         union {
172                 uint8_t u6_addr8[16];
173                 uint16_t u6_addr16[8];
174                 uint32_t u6_addr32[4];
175         } in6_u;
176 #define s6_addr                 in6_u.u6_addr8
177 #define s6_addr16               in6_u.u6_addr16
178 #define s6_addr32               in6_u.u6_addr32
179 };
180
181 #ifndef IN6ADDRSZ
182 #define IN6ADDRSZ 16
183 #endif
184
185 #ifndef INET6_ADDRSTRLEN
186 #define INET6_ADDRSTRLEN 46
187 #endif
188
189 #ifndef IN6ADDR_ANY_INIT
190 #define IN6ADDR_ANY_INIT        {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
191 #endif
192
193 #ifndef IN6ADDR_LOOPBACK_INIT
194 #define IN6ADDR_LOOPBACK_INIT   {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
195 #endif
196
197 #ifndef IN6_IS_ADDR_UNSPECIFIED
198 #define IN6_IS_ADDR_UNSPECIFIED(a) \
199         (((__const uint32_t *) (a))[0] == 0                                   \
200          && ((__const uint32_t *) (a))[1] == 0                                \
201          && ((__const uint32_t *) (a))[2] == 0                                \
202          && ((__const uint32_t *) (a))[3] == 0)
203 #endif
204
205 #ifndef IN6_IS_ADDR_LOOPBACK
206 #define IN6_IS_ADDR_LOOPBACK(a) \
207         (((__const uint32_t *) (a))[0] == 0                                   \
208          && ((__const uint32_t *) (a))[1] == 0                                \
209          && ((__const uint32_t *) (a))[2] == 0                                \
210          && ((__const uint32_t *) (a))[3] == htonl (1))
211 #endif
212
213 #ifndef IN6_IS_ADDR_MULTICAST
214 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
215 #endif
216
217 #ifndef IN6_IS_ADDR_LINKLOCAL
218 #define IN6_IS_ADDR_LINKLOCAL(a) \
219         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
220          == htonl (0xfe800000))
221 #endif
222
223 #ifndef IN6_IS_ADDR_SITELOCAL
224 #define IN6_IS_ADDR_SITELOCAL(a) \
225         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
226          == htonl (0xfec00000))
227 #endif
228
229 #ifndef IN6_IS_ADDR_V4MAPPED
230 #define IN6_IS_ADDR_V4MAPPED(a) \
231         ((((__const uint32_t *) (a))[0] == 0)                                 \
232          && (((__const uint32_t *) (a))[1] == 0)                              \
233          && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
234 #endif
235
236 #ifndef IN6_IS_ADDR_V4COMPAT
237 #define IN6_IS_ADDR_V4COMPAT(a) \
238         ((((__const uint32_t *) (a))[0] == 0)                                 \
239          && (((__const uint32_t *) (a))[1] == 0)                              \
240          && (((__const uint32_t *) (a))[2] == 0)                              \
241          && (ntohl (((__const uint32_t *) (a))[3]) > 1))
242 #endif
243
244 #ifndef IN6_ARE_ADDR_EQUAL
245 #define IN6_ARE_ADDR_EQUAL(a,b) \
246         ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
247          && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
248          && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
249          && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
250 #endif
251
252 #endif /* HAVE_STRUCT_IN6_ADDR */
253
254 /*
255  *      Functions from getaddrinfo.c
256  */
257
258 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
259 struct sockaddr_storage
260 {
261     uint16_t ss_family;         /* Address family, etc.  */
262     char ss_padding[128 - (sizeof(uint16_t))];
263 };
264 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
265
266 #ifndef HAVE_STRUCT_ADDRINFO
267
268 /* for old netdb.h */
269 #ifndef EAI_SERVICE
270 #define EAI_MEMORY      2
271 #define EAI_FAMILY      5    /* ai_family not supported */
272 #define EAI_NONAME      8    /* hostname nor servname provided, or not known */
273 #define EAI_SERVICE     9   /* servname not supported for ai_socktype */
274 #endif
275
276 /* dummy value for old netdb.h */
277 #ifndef AI_PASSIVE
278 #define AI_PASSIVE      1
279 #define AI_CANONNAME    2
280 #define AI_NUMERICHOST  4
281 #define NI_NUMERICHOST  2
282 #define NI_NAMEREQD     4
283 #define NI_NUMERICSERV  8
284
285 struct addrinfo
286 {
287   int ai_flags;                 /* Input flags.  */
288   int ai_family;                /* Protocol family for socket.  */
289   int ai_socktype;              /* Socket type.  */
290   int ai_protocol;              /* Protocol for socket.  */
291   socklen_t ai_addrlen;         /* Length of socket address.  */
292   struct sockaddr *ai_addr;     /* Socket address for socket.  */
293   char *ai_canonname;           /* Canonical name for service location.  */
294   struct addrinfo *ai_next;     /* Pointer to next in list.  */
295 };
296
297 #endif /* AI_PASSIVE */
298
299 #endif /* HAVE_STRUCT_ADDRINFO */
300
301 /* Translate name of a service location and/or a service name to set of
302    socket addresses. */
303 #ifndef HAVE_GETADDRINFO
304 extern int getaddrinfo (const char *__name,
305                         const char *__service,
306                         const struct addrinfo *__req,
307                         struct addrinfo **__pai);
308
309 /* Free `addrinfo' structure AI including associated storage.  */
310 extern void freeaddrinfo (struct addrinfo *__ai);
311
312 /* Convert error return from getaddrinfo() to a string.  */
313 extern char *gai_strerror (int __ecode);
314 #endif
315
316 /* Translate a socket address to a location and service name. */
317 #ifndef HAVE_GETNAMEINFO
318 extern int getnameinfo (const struct sockaddr *__sa,
319                         socklen_t __salen, char *__host,
320                         size_t __hostlen, char *__serv,
321                         size_t __servlen, unsigned int __flags);
322 #endif
323
324 /*
325  *      Functions from snprintf.c
326  */
327
328 #ifndef HAVE_VSNPRINTF
329 #include <stdarg.h>
330 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
331 #endif
332
333 #ifndef HAVE_SNPRINTF
334 extern int snprintf(char *str, size_t count, const char *fmt, ...);
335 #endif
336
337 /*
338  *      Functions from strl{cat,cpy}.c
339  */
340
341 #ifndef HAVE_STRLCPY
342 extern size_t strlcpy(char *dst, const char *src, size_t siz);
343 #endif
344
345 #ifndef HAVE_STRLCAT
346 extern size_t strlcat(char *dst, const char *src, size_t siz);
347 #endif
348
349 #ifndef INT16SZ
350 #define INT16SZ (2)
351 #endif
352
353 #ifndef HAVE_GMTIME_R
354 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
355 #endif
356
357 #ifndef HAVE_GETTIMEOFDAY
358 int gettimeofday (struct timeval *tv, void *tz);
359 #endif
360
361 #ifdef WIN32
362 #undef mkdir
363 #define mkdir(_d, _p) mkdir(_d)
364 #endif
365
366 #endif /* _FR_MISSING_H */