5 * missing.h Replacements for functions that are or can be
6 * missing on some platforms.
7 * HAVE_* and WITH_* defines are substituted at
8 * build time by make with values from autoconf.h.
13 RCSIDH(missing_h, "$Id$")
23 #ifdef HAVE_SYS_TYPES_H
24 # include <sys/types.h>
27 #ifdef HAVE_INTTYPES_H
28 # include <inttypes.h>
43 #ifdef HAVE_NETINET_IN_H
44 # include <netinet/in.h>
47 #ifdef HAVE_ARPA_INET_H
48 # include <arpa/inet.h>
51 #ifdef HAVE_SYS_SELECT_H
52 # include <sys/select.h>
55 #ifdef HAVE_SYS_SOCKET_H
56 # include <sys/socket.h>
63 #ifndef HAVE_VSNPRINTF
72 * Check for inclusion of <time.h>, versus <sys/time.h>
73 * Taken verbatim from the autoconf manual.
75 #ifdef TIME_WITH_SYS_TIME
76 # include <sys/time.h>
80 # include <sys/time.h>
87 * Don't look for winsock.h if we're on cygwin.
89 #if !defined(__CYGWIN__) && defined(HAVE_WINSOCK_H)
103 * Functions from missing.c
105 #ifndef HAVE_STRNCASECMP
106 int strncasecmp(char *s1, char *s2, int n);
109 #ifndef HAVE_STRCASECMP
110 int strcasecmp(char *s1, char *s2);
114 char *strsep(char **stringp, char const *delim);
117 #ifndef HAVE_LOCALTIME_R
119 struct tm *localtime_r(time_t const *l_clock, struct tm *result);
123 char *ctime_r(time_t const *l_clock, char *l_buf);
126 #ifndef HAVE_INET_PTON
127 int inet_pton(int af, char const *src, void *dst);
129 #ifndef HAVE_INET_NTOP
130 char const *inet_ntop(int af, void const *src, char *dst, size_t cnt);
132 #ifndef HAVE_CLOSEFROM
133 int closefrom(int fd);
136 #ifndef HAVE_SETLINEBUF
138 # define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
140 # define setlinebuf(x) 0
145 # define INADDR_ANY ((uint32_t) 0x00000000)
148 #ifndef INADDR_LOOPBACK
149 # define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
153 # define INADDR_NONE ((uint32_t) 0xffffffff)
160 #ifndef INET_ADDRSTRLEN
161 # define INET_ADDRSTRLEN 16
172 #ifndef HAVE_STRUCT_IN6_ADDR
176 uint8_t u6_addr8[16];
177 uint16_t u6_addr16[8];
178 uint32_t u6_addr32[4];
180 # define s6_addr in6_u.u6_addr8
181 # define s6_addr16 in6_u.u6_addr16
182 # define s6_addr32 in6_u.u6_addr32
186 # define IN6ADDRSZ 16
189 # ifndef INET6_ADDRSTRLEN
190 # define INET6_ADDRSTRLEN 46
193 # ifndef IN6ADDR_ANY_INIT
194 # define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
197 # ifndef IN6ADDR_LOOPBACK_INIT
198 # define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
201 # ifndef IN6_IS_ADDR_UNSPECIFIED
202 # define IN6_IS_ADDR_UNSPECIFIED(a) \
203 (((__const uint32_t *) (a))[0] == 0 \
204 && ((__const uint32_t *) (a))[1] == 0 \
205 && ((__const uint32_t *) (a))[2] == 0 \
206 && ((__const uint32_t *) (a))[3] == 0)
209 # ifndef IN6_IS_ADDR_LOOPBACK
210 # define IN6_IS_ADDR_LOOPBACK(a) \
211 (((__const uint32_t *) (a))[0] == 0 \
212 && ((__const uint32_t *) (a))[1] == 0 \
213 && ((__const uint32_t *) (a))[2] == 0 \
214 && ((__const uint32_t *) (a))[3] == htonl (1))
217 # ifndef IN6_IS_ADDR_MULTICAST
218 # define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
221 # ifndef IN6_IS_ADDR_LINKLOCAL
222 # define IN6_IS_ADDR_LINKLOCAL(a) \
223 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
224 == htonl (0xfe800000))
227 # ifndef IN6_IS_ADDR_SITELOCAL
228 # define IN6_IS_ADDR_SITELOCAL(a) \
229 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
230 == htonl (0xfec00000))
233 # ifndef IN6_IS_ADDR_V4MAPPED
234 # define IN6_IS_ADDR_V4MAPPED(a) \
235 ((((__const uint32_t *) (a))[0] == 0) \
236 && (((__const uint32_t *) (a))[1] == 0) \
237 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
240 # ifndef IN6_IS_ADDR_V4COMPAT
241 # define IN6_IS_ADDR_V4COMPAT(a) \
242 ((((__const uint32_t *) (a))[0] == 0) \
243 && (((__const uint32_t *) (a))[1] == 0) \
244 && (((__const uint32_t *) (a))[2] == 0) \
245 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
248 # ifndef IN6_ARE_ADDR_EQUAL
249 # define IN6_ARE_ADDR_EQUAL(a,b) \
250 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
251 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
252 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
253 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
255 #endif /* HAVE_STRUCT_IN6_ADDR */
258 * Functions from getaddrinfo.c
261 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
262 struct sockaddr_storage
264 uint16_t ss_family; /* Address family, etc. */
265 char ss_padding[128 - (sizeof(uint16_t))];
269 #ifndef HAVE_STRUCT_ADDRINFO
270 /* for old netdb.h */
272 # define EAI_MEMORY 2
273 # define EAI_FAMILY 5 /* ai_family not supported */
274 # define EAI_NONAME 8 /* hostname nor servname provided, or not known */
275 # define EAI_SERVICE 9 /* servname not supported for ai_socktype */
278 /* dummy value for old netdb.h */
280 # define AI_PASSIVE 1
281 # define AI_CANONNAME 2
282 # define AI_NUMERICHOST 4
283 # define NI_NUMERICHOST 2
284 # define NI_NAMEREQD 4
285 # define NI_NUMERICSERV 8
289 int ai_flags; /* Input flags. */
290 int ai_family; /* Protocol family for socket. */
291 int ai_socktype; /* Socket type. */
292 int ai_protocol; /* Protocol for socket. */
293 socklen_t ai_addrlen; /* Length of socket address. */
294 struct sockaddr *ai_addr; /* Socket address for socket. */
295 char *ai_canonname; /* Canonical name for service location. */
296 struct addrinfo *ai_next; /* Pointer to next in list. */
299 # endif /* AI_PASSIVE */
300 #endif /* HAVE_STRUCT_ADDRINFO */
302 /* Translate name of a service location and/or a service name to set of
304 #ifndef HAVE_GETADDRINFO
305 int getaddrinfo(char const *__name, char const *__service,
306 struct addrinfo const *__req,
307 struct addrinfo **__pai);
309 /* Free `addrinfo' structure AI including associated storage. */
310 void freeaddrinfo (struct addrinfo *__ai);
312 /* Convert error return from getaddrinfo() to a string. */
313 char const *gai_strerror (int __ecode);
316 /* Translate a socket address to a location and service name. */
317 #ifndef HAVE_GETNAMEINFO
318 int getnameinfo(struct sockaddr const *__sa,
319 socklen_t __salen, char *__host,
320 size_t __hostlen, char *__serv,
321 size_t __servlen, unsigned int __flags);
325 * Functions from snprintf.c
327 #ifndef HAVE_VSNPRINTF
328 int vsnprintf(char *str, size_t count, char const *fmt, va_list arg);
331 #ifndef HAVE_SNPRINTF
332 int snprintf(char *str, size_t count, char const *fmt, ...);
336 * Functions from strl{cat,cpy}.c
339 size_t strlcpy(char *dst, char const *src, size_t siz);
343 size_t strlcat(char *dst, char const *src, size_t siz);
350 #ifndef HAVE_GMTIME_R
351 struct tm *gmtime_r(time_t const *l_clock, struct tm *result);
354 #ifndef HAVE_GETTIMEOFDAY
355 int gettimeofday (struct timeval *tv, void *tz);
359 * Work around different ctime_r styles
361 #if defined(CTIMERSTYLE) && (CTIMERSTYLE == SOLARISSTYLE)
362 # define CTIME_R(a,b,c) ctime_r(a,b,c)
363 # define ASCTIME_R(a,b,c) asctime_r(a,b,c)
365 # define CTIME_R(a,b,c) ctime_r(a,b)
366 # define ASCTIME_R(a,b,c) asctime_r(a,b)
372 # define mkdir(_d, _p) mkdir(_d)
373 # define FR_DIR_SEP '\\'
374 # define FR_DIR_IS_RELATIVE(p) ((*p && (p[1] != ':')) || ((*p != '\\') && (*p != '\\')))
376 # define FR_DIR_SEP '/'
377 # define FR_DIR_IS_RELATIVE(p) ((*p) != '/')
381 # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
384 void timeval2ntp(struct timeval const *tv, uint8_t *ntp);
385 void ntp2timeval(struct timeval *tv, char const *ntp);
388 * This is really hacky. Any code needing to perform operations on 128bit integers,
389 * or return 128BIT integers should check for HAVE_128BIT_INTEGERS.
391 #ifndef HAVE_UINT128_T
392 # ifdef HAVE___UINT128_T
393 # define HAVE_128BIT_INTEGERS
394 # define uint128_t __uint128_t
395 # define int128_t __int128_t
397 typedef struct uint128_t { uint8_t v[16]; } uint128_t;
398 typedef struct int128_t { uint8_t v[16]; } int128_t;
401 # define HAVE_128BIT_INTEGERS
404 /* abcd efgh -> dcba hgfe -> hgfe dcba */
406 # ifdef FR_LITTLE_ENDIAN
407 # ifdef HAVE_BUILTIN_BSWAP64
408 # define ntohll(x) __builtin_bswap64(x)
410 # define ntohll(x) (((uint64_t)ntohl((uint32_t)(x >> 32))) | (((uint64_t)ntohl(((uint32_t) x)) << 32)))
413 # define ntohll(x) (x)
415 # define htonll(x) ntohll(x)
419 # ifdef FR_LITTLE_ENDIAN
420 # ifdef HAVE_128BIT_INTEGERS
421 # define ntohlll(x) (((uint128_t)ntohll((uint64_t)(x >> 64))) | (((uint128_t)ntohll(((uint64_t) x)) << 64)))
423 uint128_t ntohlll(uint128_t num);
426 # define ntohlll(x) (x)
428 # define htonlll(x) htohlll(x)
432 typedef void(*sig_t)(int);
440 * Not really missing, but may be submitted as patches
441 * to the talloc project at some point in the future.
443 char *talloc_typed_strdup(const void *t, const char *p);
444 char *talloc_typed_asprintf(const void *t, const char *fmt, ...) CC_HINT(format (printf, 2, 3));
445 char *talloc_bstrndup(const void *t, char const *in, size_t inlen);
446 #endif /* _FR_MISSING_H */