More definitions for systems that don't have them
[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 #ifdef HAVE_STDINT_H
13 #include <stdint.h>
14 #endif
15
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
18 #endif
19
20 /*
21  *      Functions from missing.c
22  */
23
24 #ifndef HAVE_STRNCASECMP
25 extern int strncasecmp(char *s1, char *s2, int n);
26 #endif
27
28 #ifndef HAVE_STRCASECMP
29 extern int strcasecmp(char *s1, char *s2);
30 #endif
31
32 #ifndef HAVE_STRSEP
33 extern char *strsep(char **stringp, const char *delim);
34 #endif
35
36 #ifndef HAVE_LOCALTIME_R
37 struct tm;
38 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
39 #endif
40
41 #ifndef HAVE_CTIME_R
42 char *ctime_r(const time_t *l_clock, char *l_buf);
43 #endif
44
45 #ifdef NEED_DECLARATION_CRYPT
46 char *crypt(char *key, char *salt);
47 #endif
48
49 #ifdef NEED_DECLARATION_STRNCASECMP
50 int strncasecmp(char *s1, char *s2, int n);
51 #endif
52
53 #ifdef NEED_DECLARATION_STRCASECMP
54 int strcasecmp(char *s1, char *s2);
55 #endif
56
57 #ifdef NEED_DECLARATION_INET_ATON
58 struct in_addr;
59 int inet_aton(char *cp, struct in_addr *inp);
60 #endif
61
62 #ifdef NEED_DECLARATION_GETHOSTNAME
63 int gethostname(char *name, int len);
64 #endif
65
66 #ifndef HAVE_SETLINEBUF
67 #ifdef HAVE_SETVBUF
68 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
69 #else
70 #define setlinebuf(x)     0
71 #endif
72 #endif
73
74 #ifdef NEED_DECLARATION_SETLINEBUF
75 #define setlinebuf(x)     0
76 #endif
77
78 #ifdef NEED_DECLARATION_GETUSERSHELL
79 char *getusershell(void);
80 #endif
81
82 #ifdef NEED_DECLARATION_ENDUSERSHELL
83 void endusershell(void);
84 #endif
85
86 #ifndef INADDR_ANY
87 #define INADDR_ANY      ((uint32_t) 0x00000000)
88 #endif
89
90 #ifndef INADDR_LOOPBACK
91 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
92 #endif
93
94 #ifndef INADDR_NONE
95 #define INADDR_NONE     ((uint32_t) 0xffffffff)
96 #endif
97
98 #ifndef INADDRSZ
99 #define INADDRSZ 4
100 #endif
101
102 #ifndef INET_ADDRSTRLEN
103 #define INET_ADDRSTRLEN 16
104 #endif
105
106 #ifndef AF_UNSPEC
107 #define AF_UNSPEC 0
108 #endif
109
110 #ifndef AF_INET6
111 #define AF_INET6 10
112
113 #ifndef HAVE_STRUCT_IN6_ADDR
114 struct in6_addr
115 {
116         union {
117                 uint8_t u6_addr8[16];
118                 uint16_t u6_addr16[8];
119                 uint32_t u6_addr32[4];
120         } in6_u;
121 #define s6_addr                 in6_u.u6_addr8
122 #define s6_addr16               in6_u.u6_addr16
123 #define s6_addr32               in6_u.u6_addr32
124 };
125
126 #ifndef IN6ADDRSZ
127 #define IN6ADDRSZ 16
128 #endif
129
130 #ifndef INET6_ADDRSTRLEN
131 #define INET6_ADDRSTRLEN 46
132 #endif
133
134 #ifndef IN6ADDR_ANY_INIT
135 #define IN6ADDR_ANY_INIT        {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
136 #endif
137
138 #ifndef IN6ADDR_LOOPBACK_INIT
139 #define IN6ADDR_LOOPBACK_INIT   {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
140 #endif
141
142 #ifndef IN6_IS_ADDR_UNSPECIFIED
143 #define IN6_IS_ADDR_UNSPECIFIED(a) \
144         (((__const uint32_t *) (a))[0] == 0                                   \
145          && ((__const uint32_t *) (a))[1] == 0                                \
146          && ((__const uint32_t *) (a))[2] == 0                                \
147          && ((__const uint32_t *) (a))[3] == 0)
148 #endif
149
150 #ifndef IN6_IS_ADDR_LOOPBACK
151 #define IN6_IS_ADDR_LOOPBACK(a) \
152         (((__const uint32_t *) (a))[0] == 0                                   \
153          && ((__const uint32_t *) (a))[1] == 0                                \
154          && ((__const uint32_t *) (a))[2] == 0                                \
155          && ((__const uint32_t *) (a))[3] == htonl (1))
156 #endif
157
158 #ifndef IN6_IS_ADDR_MULTICAST
159 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
160 #endif
161
162 #ifndef IN6_IS_ADDR_LINKLOCAL
163 #define IN6_IS_ADDR_LINKLOCAL(a) \
164         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
165          == htonl (0xfe800000))
166 #endif
167
168 #ifndef IN6_IS_ADDR_SITELOCAL
169 #define IN6_IS_ADDR_SITELOCAL(a) \
170         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
171          == htonl (0xfec00000))
172 #endif
173
174 #ifndef IN6_IS_ADDR_V4MAPPED
175 #define IN6_IS_ADDR_V4MAPPED(a) \
176         ((((__const uint32_t *) (a))[0] == 0)                                 \
177          && (((__const uint32_t *) (a))[1] == 0)                              \
178          && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
179 #endif
180
181 #ifndef IN6_IS_ADDR_V4COMPAT
182 #define IN6_IS_ADDR_V4COMPAT(a) \
183         ((((__const uint32_t *) (a))[0] == 0)                                 \
184          && (((__const uint32_t *) (a))[1] == 0)                              \
185          && (((__const uint32_t *) (a))[2] == 0)                              \
186          && (ntohl (((__const uint32_t *) (a))[3]) > 1))
187 #endif
188
189 #ifndef IN6_ARE_ADDR_EQUAL
190 #define IN6_ARE_ADDR_EQUAL(a,b) \
191         ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
192          && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
193          && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
194          && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
195 #endif
196
197 #endif /* HAVE_STRUCT_IN6_ADDR */
198 #endif
199
200 /*
201  *      Functions from getaddrinfo.c
202  */
203
204 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
205 struct sockaddr_storage
206 {
207     uint16_t ss_family;         /* Address family, etc.  */
208     char ss_padding[128 - (sizeof(uint16_t))];
209 };
210 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
211
212 #ifndef HAVE_STRUCT_ADDRINFO
213
214 /* for old netdb.h */
215 #ifndef EAI_SERVICE
216 #define EAI_MEMORY      2
217 #define EAI_FAMILY      5    /* ai_family not supported */
218 #define EAI_NONAME      8    /* hostname nor servname provided, or not known */
219 #define EAI_SERVICE     9   /* servname not supported for ai_socktype */
220 #endif
221
222 /* dummy value for old netdb.h */
223 #ifndef AI_PASSIVE
224 #define AI_PASSIVE      1
225 #define AI_CANONNAME    2
226 #define AI_NUMERICHOST  4
227 #define NI_NUMERICHOST  2
228 #define NI_NAMEREQD     4
229 #define NI_NUMERICSERV  8
230
231 struct addrinfo
232 {
233   int ai_flags;                 /* Input flags.  */
234   int ai_family;                /* Protocol family for socket.  */
235   int ai_socktype;              /* Socket type.  */
236   int ai_protocol;              /* Protocol for socket.  */
237   socklen_t ai_addrlen;         /* Length of socket address.  */
238   struct sockaddr *ai_addr;     /* Socket address for socket.  */
239   char *ai_canonname;           /* Canonical name for service location.  */
240   struct addrinfo *ai_next;     /* Pointer to next in list.  */
241 };
242
243 #endif /* AI_PASSIVE */
244
245 #endif /* HAVE_STRUCT_ADDRINFO */
246
247 /* Translate name of a service location and/or a service name to set of
248    socket addresses. */
249 #ifndef HAVE_GETADDRINFO
250 extern int getaddrinfo (const char *__name,
251                         const char *__service,
252                         const struct addrinfo *__req,
253                         struct addrinfo **__pai);
254
255 /* Free `addrinfo' structure AI including associated storage.  */
256 extern void freeaddrinfo (struct addrinfo *__ai);
257
258 /* Convert error return from getaddrinfo() to a string.  */
259 extern char *gai_strerror (int __ecode);
260 #endif
261
262 /* Translate a socket address to a location and service name. */
263 #ifndef HAVE_GETNAMEINFO
264 extern int getnameinfo (const struct sockaddr *__sa,
265                         socklen_t __salen, char *__host,
266                         socklen_t __hostlen, char *__serv,
267                         socklen_t __servlen, unsigned int __flags);
268 #endif
269
270 /*
271  *      Functions from snprintf.c
272  */
273
274 #ifndef HAVE_VSNPRINTF
275 #include <stdarg.h>
276 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
277 #endif
278
279 #ifndef HAVE_SNPRINTF
280 extern int snprintf(char *str, size_t count, const char *fmt, ...);
281 #endif
282
283 /*
284  *      Functions from strl{cat,cpy}.c
285  */
286
287 #ifndef HAVE_STRLCPY
288 extern size_t strlcpy(char *dst, const char *src, size_t siz);
289 #endif
290
291 #ifndef HAVE_STRLCAT
292 extern size_t strlcat(char *dst, const char *src, size_t siz);
293 #endif
294
295 #endif /* _FR_MISSING_H */