1 /* $Id: openbsd-compat.h,v 1.51 2010/10/07 10:25:29 djm Exp $ */
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
5 * Copyright (c) 2003 Ben Lindstrom. All rights reserved.
6 * Copyright (c) 2002 Tim Rice. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef NEED_EXPLICIT_BZERO
31 void explicit_bzero(void *p, size_t n);
33 #ifdef NEED_RECALLOCARRAY
34 void *recallocarray(void *, size_t, size_t, size_t);
36 #ifdef NEED_REALLOCARRAY
37 void *reallocarray(void *, size_t, size_t);
40 size_t strlcat(char *dst, const char *src, size_t size);
43 size_t strlcpy(char *dst, const char *src, size_t size);
46 long long strtonum(const char *nptr, long long minval, long long maxval, const char **errstr);
50 pledge(const char *promises, const char *execpromises)
55 #ifdef NEED_INET_NET_PTON
57 inet_net_pton(int af, const char *src, void *dst, size_t size);
62 char * fgetln(FILE *stream, size_t *len);
66 void event_asr_abort(struct event_asr *);
68 /* From OpenNTPD portable */
70 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
71 # define SA_LEN(x) ((x)->sa_len)
73 # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
74 sizeof(struct sockaddr_in6) : \
75 sizeof(struct sockaddr_in))
80 /* From OpenBGPD portable */
82 # if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN)
83 # define SS_LEN(x) ((x)->ss_len)
85 # define SS_LEN(x) SA_LEN((struct sockaddr *)(x))
90 # define STORAGE_LEN(X) ((X).ss_len)
91 # define SET_STORAGE_LEN(X, Y) do { STORAGE_LEN(X) = (Y); } while(0)
92 #elif defined(HAVE___SS_LEN)
93 # define STORAGE_LEN(X) ((X).__ss_len)
94 # define SET_STORAGE_LEN(X, Y) do { STORAGE_LEN(X) = (Y); } while(0)
96 # define STORAGE_LEN(X) (STORAGE_FAMILY(X) == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
97 # define SET_STORAGE_LEN(X, Y) (void) 0
101 #define timespecsub(a, b, result) \
103 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
104 (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
105 if ((result)->tv_nsec < 0) { \
106 --(result)->tv_sec; \
107 (result)->tv_nsec += 1000000000L; \