Blob


1 /* $Id: openbsd-compat.h,v 1.51 2010/10/07 10:25:29 djm Exp $ */
3 /*
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.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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.
27 */
28 #include <stdlib.h>
30 #ifdef NEED_EXPLICIT_BZERO
31 void explicit_bzero(void *p, size_t n);
32 #endif
33 #ifdef NEED_RECALLOCARRAY
34 void *recallocarray(void *, size_t, size_t, size_t);
35 #endif
36 #ifdef NEED_REALLOCARRAY
37 void *reallocarray(void *, size_t, size_t);
38 #endif
39 #ifdef NEED_STRLCAT
40 size_t strlcat(char *dst, const char *src, size_t size);
41 #endif
42 #ifdef NEED_STRLCPY
43 size_t strlcpy(char *dst, const char *src, size_t size);
44 #endif
45 #ifdef NEED_STRTONUM
46 long long strtonum(const char *nptr, long long minval, long long maxval, const char **errstr);
47 #endif
48 #ifdef NEED_PLEDGE
49 static inline int
50 pledge(const char *promises, const char *execpromises)
51 {
52 return 0;
53 }
54 #endif
55 #ifdef NEED_INET_NET_PTON
56 int
57 inet_net_pton(int af, const char *src, void *dst, size_t size);
58 #endif
59 #ifdef NEED_FGETLN
60 #include <stdio.h>
61 #include <string.h>
62 char * fgetln(FILE *stream, size_t *len);
63 #endif
64 #ifdef NEED_LIBASR
65 struct event_asr;
66 void event_asr_abort(struct event_asr *);
68 /* From OpenNTPD portable */
69 #if !defined(SA_LEN)
70 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
71 # define SA_LEN(x) ((x)->sa_len)
72 # else
73 # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
74 sizeof(struct sockaddr_in6) : \
75 sizeof(struct sockaddr_in))
76 # endif
77 #endif
78 #endif
80 /* From OpenBGPD portable */
81 #if !defined(SS_LEN)
82 # if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN)
83 # define SS_LEN(x) ((x)->ss_len)
84 # else
85 # define SS_LEN(x) SA_LEN((struct sockaddr *)(x))
86 # endif
87 #endif
89 #ifdef HAVE_SS_LEN
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)
95 #else
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
98 #endif
100 #ifndef timespecsub
101 #define timespecsub(a, b, result) \
102 do { \
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; \
108 } \
109 } while (0)
110 #endif