diff options
author | Colin Watson <cjwatson@debian.org> | 2013-05-07 11:47:26 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2013-05-07 11:47:26 +0100 |
commit | 2ea3f720daeb1ca9f765365fce3a9546961fe624 (patch) | |
tree | c4fb7d1f51fa51e7677232de806aae150e29e2ac /openbsd-compat | |
parent | f5efcd3450bbf8261915e0c4a6f851229dddaa79 (diff) | |
parent | ecebda56da46a03dafff923d91c382f31faa9eec (diff) |
* New upstream release (http://www.openssh.com/txt/release-6.2).
- Add support for multiple required authentication in SSH protocol 2 via
an AuthenticationMethods option (closes: #195716).
- Fix Sophie Germain formula in moduli(5) (closes: #698612).
- Update ssh-copy-id to Phil Hands' greatly revised version (closes:
#99785, #322228, #620428; LP: #518883, #835901, #1074798).
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.in | 6 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 30 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.h | 10 | ||||
-rw-r--r-- | openbsd-compat/bsd-setres_id.c | 99 | ||||
-rw-r--r-- | openbsd-compat/bsd-setres_id.h | 24 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 11 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.h | 43 | ||||
-rw-r--r-- | openbsd-compat/strtoull.c | 110 | ||||
-rw-r--r-- | openbsd-compat/sys-queue.h | 53 | ||||
-rw-r--r-- | openbsd-compat/sys-tree.h | 114 | ||||
-rw-r--r-- | openbsd-compat/vis.c | 2 | ||||
-rw-r--r-- | openbsd-compat/vis.h | 4 |
12 files changed, 462 insertions, 44 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 196a81d13..e1c3651e8 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.48 2011/11/04 00:25:25 dtucker Exp $ | 1 | # $Id: Makefile.in,v 1.50 2013/02/15 01:13:02 dtucker Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -16,9 +16,9 @@ RANLIB=@RANLIB@ | |||
16 | INSTALL=@INSTALL@ | 16 | INSTALL=@INSTALL@ |
17 | LDFLAGS=-L. @LDFLAGS@ | 17 | LDFLAGS=-L. @LDFLAGS@ |
18 | 18 | ||
19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o timingsafe_bcmp.o vis.o | 19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o | 21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o | 23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o |
24 | 24 | ||
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3ef373f56..d75854e83 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -165,6 +165,17 @@ int nanosleep(const struct timespec *req, struct timespec *rem) | |||
165 | } | 165 | } |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | #if !defined(HAVE_USLEEP) | ||
169 | int usleep(unsigned int useconds) | ||
170 | { | ||
171 | struct timespec ts; | ||
172 | |||
173 | ts.tv_sec = useconds / 1000000; | ||
174 | ts.tv_nsec = (useconds % 1000000) * 1000; | ||
175 | return nanosleep(&ts, NULL); | ||
176 | } | ||
177 | #endif | ||
178 | |||
168 | #ifndef HAVE_TCGETPGRP | 179 | #ifndef HAVE_TCGETPGRP |
169 | pid_t | 180 | pid_t |
170 | tcgetpgrp(int fd) | 181 | tcgetpgrp(int fd) |
@@ -242,8 +253,25 @@ strdup(const char *str) | |||
242 | #endif | 253 | #endif |
243 | 254 | ||
244 | #ifndef HAVE_ISBLANK | 255 | #ifndef HAVE_ISBLANK |
245 | int isblank(int c) | 256 | int |
257 | isblank(int c) | ||
246 | { | 258 | { |
247 | return (c == ' ' || c == '\t'); | 259 | return (c == ' ' || c == '\t'); |
248 | } | 260 | } |
249 | #endif | 261 | #endif |
262 | |||
263 | #ifndef HAVE_GETPGID | ||
264 | pid_t | ||
265 | getpgid(pid_t pid) | ||
266 | { | ||
267 | #if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) | ||
268 | return getpgrp(pid); | ||
269 | #elif defined(HAVE_GETPGRP) | ||
270 | if (pid == 0) | ||
271 | return getpgrp(); | ||
272 | #endif | ||
273 | |||
274 | errno = ESRCH; | ||
275 | return -1; | ||
276 | } | ||
277 | #endif | ||
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index eac5217ca..430066376 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: bsd-misc.h,v 1.21 2012/07/03 22:50:10 dtucker Exp $ */ | 1 | /* $Id: bsd-misc.h,v 1.23 2013/03/14 23:34:27 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> | 4 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> |
@@ -80,6 +80,10 @@ struct timespec { | |||
80 | int nanosleep(const struct timespec *, struct timespec *); | 80 | int nanosleep(const struct timespec *, struct timespec *); |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | #ifndef HAVE_USLEEP | ||
84 | int usleep(unsigned int useconds); | ||
85 | #endif | ||
86 | |||
83 | #ifndef HAVE_TCGETPGRP | 87 | #ifndef HAVE_TCGETPGRP |
84 | pid_t tcgetpgrp(int); | 88 | pid_t tcgetpgrp(int); |
85 | #endif | 89 | #endif |
@@ -102,4 +106,8 @@ mysig_t mysignal(int sig, mysig_t act); | |||
102 | int isblank(int); | 106 | int isblank(int); |
103 | #endif | 107 | #endif |
104 | 108 | ||
109 | #ifndef HAVE_GETPGID | ||
110 | pid_t getpgid(pid_t); | ||
111 | #endif | ||
112 | |||
105 | #endif /* _BSD_MISC_H */ | 113 | #endif /* _BSD_MISC_H */ |
diff --git a/openbsd-compat/bsd-setres_id.c b/openbsd-compat/bsd-setres_id.c new file mode 100644 index 000000000..020b214b8 --- /dev/null +++ b/openbsd-compat/bsd-setres_id.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* $Id: bsd-setres_id.c,v 1.1 2012/11/05 06:04:37 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Darren Tucker (dtucker at zip com au). | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #include <stdarg.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | #include "log.h" | ||
27 | |||
28 | #if !defined(HAVE_SETRESGID) || defined(BROKEN_SETRESGID) | ||
29 | int | ||
30 | setresgid(gid_t rgid, gid_t egid, gid_t sgid) | ||
31 | { | ||
32 | int ret = 0, saved_errno; | ||
33 | |||
34 | if (rgid != sgid) { | ||
35 | errno = ENOSYS; | ||
36 | return -1; | ||
37 | } | ||
38 | #if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID) | ||
39 | if (setregid(rgid, egid) < 0) { | ||
40 | saved_errno = errno; | ||
41 | error("setregid %u: %.100s", rgid, strerror(errno)); | ||
42 | errno = saved_errno; | ||
43 | ret = -1; | ||
44 | } | ||
45 | #else | ||
46 | if (setegid(egid) < 0) { | ||
47 | saved_errno = errno; | ||
48 | error("setegid %u: %.100s", (u_int)egid, strerror(errno)); | ||
49 | errno = saved_errno; | ||
50 | ret = -1; | ||
51 | } | ||
52 | if (setgid(rgid) < 0) { | ||
53 | saved_errno = errno; | ||
54 | error("setgid %u: %.100s", rgid, strerror(errno)); | ||
55 | errno = saved_errno; | ||
56 | ret = -1; | ||
57 | } | ||
58 | #endif | ||
59 | return ret; | ||
60 | } | ||
61 | #endif | ||
62 | |||
63 | #if !defined(HAVE_SETRESUID) || defined(BROKEN_SETRESUID) | ||
64 | int | ||
65 | setresuid(uid_t ruid, uid_t euid, uid_t suid) | ||
66 | { | ||
67 | int ret = 0, saved_errno; | ||
68 | |||
69 | if (ruid != suid) { | ||
70 | errno = ENOSYS; | ||
71 | return -1; | ||
72 | } | ||
73 | #if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID) | ||
74 | if (setreuid(ruid, euid) < 0) { | ||
75 | saved_errno = errno; | ||
76 | error("setreuid %u: %.100s", ruid, strerror(errno)); | ||
77 | errno = saved_errno; | ||
78 | ret = -1; | ||
79 | } | ||
80 | #else | ||
81 | |||
82 | # ifndef SETEUID_BREAKS_SETUID | ||
83 | if (seteuid(euid) < 0) { | ||
84 | saved_errno = errno; | ||
85 | error("seteuid %u: %.100s", euid, strerror(errno)); | ||
86 | errno = saved_errno; | ||
87 | ret = -1; | ||
88 | } | ||
89 | # endif | ||
90 | if (setuid(ruid) < 0) { | ||
91 | saved_errno = errno; | ||
92 | error("setuid %u: %.100s", ruid, strerror(errno)); | ||
93 | errno = saved_errno; | ||
94 | ret = -1; | ||
95 | } | ||
96 | #endif | ||
97 | return ret; | ||
98 | } | ||
99 | #endif | ||
diff --git a/openbsd-compat/bsd-setres_id.h b/openbsd-compat/bsd-setres_id.h new file mode 100644 index 000000000..6c269e0b9 --- /dev/null +++ b/openbsd-compat/bsd-setres_id.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* $Id: bsd-setres_id.h,v 1.1 2012/11/05 06:04:37 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Darren Tucker (dtucker at zip com au). | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #ifndef HAVE_SETRESGID | ||
20 | int setresgid(gid_t, gid_t, gid_t); | ||
21 | #endif | ||
22 | #ifndef HAVE_SETRESUID | ||
23 | int setresuid(uid_t, uid_t, uid_t); | ||
24 | #endif | ||
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 807acf626..a8c579f49 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.52 2011/09/23 01:16:11 djm Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.55 2013/02/15 01:20:42 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. | 4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
@@ -149,6 +149,7 @@ int writev(int, struct iovec *, int); | |||
149 | 149 | ||
150 | /* Home grown routines */ | 150 | /* Home grown routines */ |
151 | #include "bsd-misc.h" | 151 | #include "bsd-misc.h" |
152 | #include "bsd-setres_id.h" | ||
152 | #include "bsd-statvfs.h" | 153 | #include "bsd-statvfs.h" |
153 | #include "bsd-waitpid.h" | 154 | #include "bsd-waitpid.h" |
154 | #include "bsd-poll.h" | 155 | #include "bsd-poll.h" |
@@ -189,6 +190,14 @@ int snprintf(char *, size_t, SNPRINTF_CONST char *, ...); | |||
189 | long long strtoll(const char *, char **, int); | 190 | long long strtoll(const char *, char **, int); |
190 | #endif | 191 | #endif |
191 | 192 | ||
193 | #ifndef HAVE_STRTOUL | ||
194 | unsigned long strtoul(const char *, char **, int); | ||
195 | #endif | ||
196 | |||
197 | #ifndef HAVE_STRTOULL | ||
198 | unsigned long long strtoull(const char *, char **, int); | ||
199 | #endif | ||
200 | |||
192 | #ifndef HAVE_STRTONUM | 201 | #ifndef HAVE_STRTONUM |
193 | long long strtonum(const char *, long long, long long, const char **); | 202 | long long strtonum(const char *, long long, long long, const char **); |
194 | #endif | 203 | #endif |
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h index a151eff38..e7439b4e7 100644 --- a/openbsd-compat/openssl-compat.h +++ b/openbsd-compat/openssl-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.h,v 1.20 2012/01/17 03:03:39 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.h,v 1.24 2013/02/12 00:00:40 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -40,7 +40,7 @@ | |||
40 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | 40 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #if OPENSSL_VERSION_NUMBER < 0x1000000fL | 43 | #if OPENSSL_VERSION_NUMBER < 0x10000001L |
44 | # define LIBCRYPTO_EVP_INL_TYPE unsigned int | 44 | # define LIBCRYPTO_EVP_INL_TYPE unsigned int |
45 | #else | 45 | #else |
46 | # define LIBCRYPTO_EVP_INL_TYPE size_t | 46 | # define LIBCRYPTO_EVP_INL_TYPE size_t |
@@ -59,20 +59,43 @@ | |||
59 | # define EVP_aes_128_cbc evp_rijndael | 59 | # define EVP_aes_128_cbc evp_rijndael |
60 | # define EVP_aes_192_cbc evp_rijndael | 60 | # define EVP_aes_192_cbc evp_rijndael |
61 | # define EVP_aes_256_cbc evp_rijndael | 61 | # define EVP_aes_256_cbc evp_rijndael |
62 | extern const EVP_CIPHER *evp_rijndael(void); | 62 | const EVP_CIPHER *evp_rijndael(void); |
63 | extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); | 63 | void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #if !defined(EVP_CTRL_SET_ACSS_MODE) | 66 | #ifndef OPENSSL_HAVE_EVPCTR |
67 | # if (OPENSSL_VERSION_NUMBER >= 0x00907000L) | 67 | #define EVP_aes_128_ctr evp_aes_128_ctr |
68 | # define USE_CIPHER_ACSS 1 | 68 | #define EVP_aes_192_ctr evp_aes_128_ctr |
69 | extern const EVP_CIPHER *evp_acss(void); | 69 | #define EVP_aes_256_ctr evp_aes_128_ctr |
70 | # define EVP_acss evp_acss | 70 | const EVP_CIPHER *evp_aes_128_ctr(void); |
71 | void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t); | ||
72 | #endif | ||
73 | |||
74 | /* Avoid some #ifdef. Code that uses these is unreachable without GCM */ | ||
75 | #if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED) | ||
76 | # define EVP_CTRL_GCM_SET_IV_FIXED -1 | ||
77 | # define EVP_CTRL_GCM_IV_GEN -1 | ||
78 | # define EVP_CTRL_GCM_SET_TAG -1 | ||
79 | # define EVP_CTRL_GCM_GET_TAG -1 | ||
80 | #endif | ||
81 | |||
82 | /* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */ | ||
83 | #ifndef HAVE_EVP_CIPHER_CTX_CTRL | ||
84 | # ifdef OPENSSL_HAVE_EVPGCM | ||
85 | # error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */ | ||
71 | # else | 86 | # else |
72 | # define EVP_acss NULL | 87 | # define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0) |
73 | # endif | 88 | # endif |
74 | #endif | 89 | #endif |
75 | 90 | ||
91 | #if OPENSSL_VERSION_NUMBER < 0x00907000L | ||
92 | #define EVP_X_STATE(evp) &(evp).c | ||
93 | #define EVP_X_STATE_LEN(evp) sizeof((evp).c) | ||
94 | #else | ||
95 | #define EVP_X_STATE(evp) (evp).cipher_data | ||
96 | #define EVP_X_STATE_LEN(evp) (evp).cipher->ctx_size | ||
97 | #endif | ||
98 | |||
76 | /* OpenSSL 0.9.8e returns cipher key len not context key len */ | 99 | /* OpenSSL 0.9.8e returns cipher key len not context key len */ |
77 | #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) | 100 | #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) |
78 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) | 101 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) |
diff --git a/openbsd-compat/strtoull.c b/openbsd-compat/strtoull.c new file mode 100644 index 000000000..f7c818c52 --- /dev/null +++ b/openbsd-compat/strtoull.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* $OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 1992 The Regents of the University of California. | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * 3. Neither the name of the University nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
28 | * SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | /* OPENBSD ORIGINAL: lib/libc/stdlib/strtoull.c */ | ||
32 | |||
33 | #include "includes.h" | ||
34 | #ifndef HAVE_STRTOULL | ||
35 | |||
36 | #include <sys/types.h> | ||
37 | |||
38 | #include <ctype.h> | ||
39 | #include <errno.h> | ||
40 | #include <limits.h> | ||
41 | #include <stdlib.h> | ||
42 | |||
43 | /* | ||
44 | * Convert a string to an unsigned long long. | ||
45 | * | ||
46 | * Ignores `locale' stuff. Assumes that the upper and lower case | ||
47 | * alphabets and digits are each contiguous. | ||
48 | */ | ||
49 | unsigned long long | ||
50 | strtoull(const char *nptr, char **endptr, int base) | ||
51 | { | ||
52 | const char *s; | ||
53 | unsigned long long acc, cutoff; | ||
54 | int c; | ||
55 | int neg, any, cutlim; | ||
56 | |||
57 | /* | ||
58 | * See strtoq for comments as to the logic used. | ||
59 | */ | ||
60 | s = nptr; | ||
61 | do { | ||
62 | c = (unsigned char) *s++; | ||
63 | } while (isspace(c)); | ||
64 | if (c == '-') { | ||
65 | neg = 1; | ||
66 | c = *s++; | ||
67 | } else { | ||
68 | neg = 0; | ||
69 | if (c == '+') | ||
70 | c = *s++; | ||
71 | } | ||
72 | if ((base == 0 || base == 16) && | ||
73 | c == '0' && (*s == 'x' || *s == 'X')) { | ||
74 | c = s[1]; | ||
75 | s += 2; | ||
76 | base = 16; | ||
77 | } | ||
78 | if (base == 0) | ||
79 | base = c == '0' ? 8 : 10; | ||
80 | |||
81 | cutoff = ULLONG_MAX / (unsigned long long)base; | ||
82 | cutlim = ULLONG_MAX % (unsigned long long)base; | ||
83 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { | ||
84 | if (isdigit(c)) | ||
85 | c -= '0'; | ||
86 | else if (isalpha(c)) | ||
87 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; | ||
88 | else | ||
89 | break; | ||
90 | if (c >= base) | ||
91 | break; | ||
92 | if (any < 0) | ||
93 | continue; | ||
94 | if (acc > cutoff || (acc == cutoff && c > cutlim)) { | ||
95 | any = -1; | ||
96 | acc = ULLONG_MAX; | ||
97 | errno = ERANGE; | ||
98 | } else { | ||
99 | any = 1; | ||
100 | acc *= (unsigned long long)base; | ||
101 | acc += c; | ||
102 | } | ||
103 | } | ||
104 | if (neg && any > 0) | ||
105 | acc = -acc; | ||
106 | if (endptr != 0) | ||
107 | *endptr = (char *) (any ? s - 1 : nptr); | ||
108 | return (acc); | ||
109 | } | ||
110 | #endif /* !HAVE_STRTOULL */ | ||
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h index 5cf0587bd..28aaaa37a 100644 --- a/openbsd-compat/sys-queue.h +++ b/openbsd-compat/sys-queue.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: queue.h,v 1.32 2007/04/30 18:42:34 pedro Exp $ */ | 1 | /* $OpenBSD: queue.h,v 1.36 2012/04/11 13:29:14 naddy Exp $ */ |
2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ | 2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -202,10 +202,10 @@ struct { \ | |||
202 | (var) != SLIST_END(head); \ | 202 | (var) != SLIST_END(head); \ |
203 | (var) = SLIST_NEXT(var, field)) | 203 | (var) = SLIST_NEXT(var, field)) |
204 | 204 | ||
205 | #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ | 205 | #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ |
206 | for ((varp) = &SLIST_FIRST((head)); \ | 206 | for ((var) = SLIST_FIRST(head); \ |
207 | ((var) = *(varp)) != SLIST_END(head); \ | 207 | (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ |
208 | (varp) = &SLIST_NEXT((var), field)) | 208 | (var) = (tvar)) |
209 | 209 | ||
210 | /* | 210 | /* |
211 | * Singly-linked List functions. | 211 | * Singly-linked List functions. |
@@ -224,7 +224,7 @@ struct { \ | |||
224 | (head)->slh_first = (elm); \ | 224 | (head)->slh_first = (elm); \ |
225 | } while (0) | 225 | } while (0) |
226 | 226 | ||
227 | #define SLIST_REMOVE_NEXT(head, elm, field) do { \ | 227 | #define SLIST_REMOVE_AFTER(elm, field) do { \ |
228 | (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ | 228 | (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ |
229 | } while (0) | 229 | } while (0) |
230 | 230 | ||
@@ -276,6 +276,11 @@ struct { \ | |||
276 | (var)!= LIST_END(head); \ | 276 | (var)!= LIST_END(head); \ |
277 | (var) = LIST_NEXT(var, field)) | 277 | (var) = LIST_NEXT(var, field)) |
278 | 278 | ||
279 | #define LIST_FOREACH_SAFE(var, head, field, tvar) \ | ||
280 | for ((var) = LIST_FIRST(head); \ | ||
281 | (var) && ((tvar) = LIST_NEXT(var, field), 1); \ | ||
282 | (var) = (tvar)) | ||
283 | |||
279 | /* | 284 | /* |
280 | * List functions. | 285 | * List functions. |
281 | */ | 286 | */ |
@@ -354,6 +359,11 @@ struct { \ | |||
354 | (var) != SIMPLEQ_END(head); \ | 359 | (var) != SIMPLEQ_END(head); \ |
355 | (var) = SIMPLEQ_NEXT(var, field)) | 360 | (var) = SIMPLEQ_NEXT(var, field)) |
356 | 361 | ||
362 | #define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
363 | for ((var) = SIMPLEQ_FIRST(head); \ | ||
364 | (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ | ||
365 | (var) = (tvar)) | ||
366 | |||
357 | /* | 367 | /* |
358 | * Simple queue functions. | 368 | * Simple queue functions. |
359 | */ | 369 | */ |
@@ -385,6 +395,12 @@ struct { \ | |||
385 | (head)->sqh_last = &(head)->sqh_first; \ | 395 | (head)->sqh_last = &(head)->sqh_first; \ |
386 | } while (0) | 396 | } while (0) |
387 | 397 | ||
398 | #define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ | ||
399 | if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ | ||
400 | == NULL) \ | ||
401 | (head)->sqh_last = &(elm)->field.sqe_next; \ | ||
402 | } while (0) | ||
403 | |||
388 | /* | 404 | /* |
389 | * Tail queue definitions. | 405 | * Tail queue definitions. |
390 | */ | 406 | */ |
@@ -422,11 +438,24 @@ struct { \ | |||
422 | (var) != TAILQ_END(head); \ | 438 | (var) != TAILQ_END(head); \ |
423 | (var) = TAILQ_NEXT(var, field)) | 439 | (var) = TAILQ_NEXT(var, field)) |
424 | 440 | ||
441 | #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
442 | for ((var) = TAILQ_FIRST(head); \ | ||
443 | (var) != TAILQ_END(head) && \ | ||
444 | ((tvar) = TAILQ_NEXT(var, field), 1); \ | ||
445 | (var) = (tvar)) | ||
446 | |||
447 | |||
425 | #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ | 448 | #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ |
426 | for((var) = TAILQ_LAST(head, headname); \ | 449 | for((var) = TAILQ_LAST(head, headname); \ |
427 | (var) != TAILQ_END(head); \ | 450 | (var) != TAILQ_END(head); \ |
428 | (var) = TAILQ_PREV(var, headname, field)) | 451 | (var) = TAILQ_PREV(var, headname, field)) |
429 | 452 | ||
453 | #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ | ||
454 | for ((var) = TAILQ_LAST(head, headname); \ | ||
455 | (var) != TAILQ_END(head) && \ | ||
456 | ((tvar) = TAILQ_PREV(var, headname, field), 1); \ | ||
457 | (var) = (tvar)) | ||
458 | |||
430 | /* | 459 | /* |
431 | * Tail queue functions. | 460 | * Tail queue functions. |
432 | */ | 461 | */ |
@@ -526,11 +555,23 @@ struct { \ | |||
526 | (var) != CIRCLEQ_END(head); \ | 555 | (var) != CIRCLEQ_END(head); \ |
527 | (var) = CIRCLEQ_NEXT(var, field)) | 556 | (var) = CIRCLEQ_NEXT(var, field)) |
528 | 557 | ||
558 | #define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \ | ||
559 | for ((var) = CIRCLEQ_FIRST(head); \ | ||
560 | (var) != CIRCLEQ_END(head) && \ | ||
561 | ((tvar) = CIRCLEQ_NEXT(var, field), 1); \ | ||
562 | (var) = (tvar)) | ||
563 | |||
529 | #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ | 564 | #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ |
530 | for((var) = CIRCLEQ_LAST(head); \ | 565 | for((var) = CIRCLEQ_LAST(head); \ |
531 | (var) != CIRCLEQ_END(head); \ | 566 | (var) != CIRCLEQ_END(head); \ |
532 | (var) = CIRCLEQ_PREV(var, field)) | 567 | (var) = CIRCLEQ_PREV(var, field)) |
533 | 568 | ||
569 | #define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ | ||
570 | for ((var) = CIRCLEQ_LAST(head, headname); \ | ||
571 | (var) != CIRCLEQ_END(head) && \ | ||
572 | ((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \ | ||
573 | (var) = (tvar)) | ||
574 | |||
534 | /* | 575 | /* |
535 | * Circular queue functions. | 576 | * Circular queue functions. |
536 | */ | 577 | */ |
diff --git a/openbsd-compat/sys-tree.h b/openbsd-compat/sys-tree.h index d4949b5e7..7f7546ecd 100644 --- a/openbsd-compat/sys-tree.h +++ b/openbsd-compat/sys-tree.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tree.h,v 1.10 2007/10/29 23:49:41 djm Exp $ */ | 1 | /* $OpenBSD: tree.h,v 1.13 2011/07/09 00:19:45 pirofti Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> | 3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
4 | * All rights reserved. | 4 | * All rights reserved. |
@@ -26,6 +26,11 @@ | |||
26 | 26 | ||
27 | /* OPENBSD ORIGINAL: sys/sys/tree.h */ | 27 | /* OPENBSD ORIGINAL: sys/sys/tree.h */ |
28 | 28 | ||
29 | #include "config.h" | ||
30 | #ifdef NO_ATTRIBUTE_ON_RETURN_TYPE | ||
31 | # define __attribute__(x) | ||
32 | #endif | ||
33 | |||
29 | #ifndef _SYS_TREE_H_ | 34 | #ifndef _SYS_TREE_H_ |
30 | #define _SYS_TREE_H_ | 35 | #define _SYS_TREE_H_ |
31 | 36 | ||
@@ -331,7 +336,7 @@ struct { \ | |||
331 | } while (0) | 336 | } while (0) |
332 | 337 | ||
333 | #ifndef RB_AUGMENT | 338 | #ifndef RB_AUGMENT |
334 | #define RB_AUGMENT(x) | 339 | #define RB_AUGMENT(x) do {} while (0) |
335 | #endif | 340 | #endif |
336 | 341 | ||
337 | #define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ | 342 | #define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ |
@@ -375,21 +380,31 @@ struct { \ | |||
375 | } while (0) | 380 | } while (0) |
376 | 381 | ||
377 | /* Generates prototypes and inline functions */ | 382 | /* Generates prototypes and inline functions */ |
378 | #define RB_PROTOTYPE(name, type, field, cmp) \ | 383 | #define RB_PROTOTYPE(name, type, field, cmp) \ |
379 | void name##_RB_INSERT_COLOR(struct name *, struct type *); \ | 384 | RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) |
380 | void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ | 385 | #define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ |
381 | struct type *name##_RB_REMOVE(struct name *, struct type *); \ | 386 | RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) |
382 | struct type *name##_RB_INSERT(struct name *, struct type *); \ | 387 | #define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ |
383 | struct type *name##_RB_FIND(struct name *, struct type *); \ | 388 | attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ |
384 | struct type *name##_RB_NEXT(struct type *); \ | 389 | attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ |
385 | struct type *name##_RB_MINMAX(struct name *, int); | 390 | attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ |
386 | 391 | attr struct type *name##_RB_INSERT(struct name *, struct type *); \ | |
392 | attr struct type *name##_RB_FIND(struct name *, struct type *); \ | ||
393 | attr struct type *name##_RB_NFIND(struct name *, struct type *); \ | ||
394 | attr struct type *name##_RB_NEXT(struct type *); \ | ||
395 | attr struct type *name##_RB_PREV(struct type *); \ | ||
396 | attr struct type *name##_RB_MINMAX(struct name *, int); \ | ||
397 | \ | ||
387 | 398 | ||
388 | /* Main rb operation. | 399 | /* Main rb operation. |
389 | * Moves node close to the key of elm to top | 400 | * Moves node close to the key of elm to top |
390 | */ | 401 | */ |
391 | #define RB_GENERATE(name, type, field, cmp) \ | 402 | #define RB_GENERATE(name, type, field, cmp) \ |
392 | void \ | 403 | RB_GENERATE_INTERNAL(name, type, field, cmp,) |
404 | #define RB_GENERATE_STATIC(name, type, field, cmp) \ | ||
405 | RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) | ||
406 | #define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ | ||
407 | attr void \ | ||
393 | name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ | 408 | name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ |
394 | { \ | 409 | { \ |
395 | struct type *parent, *gparent, *tmp; \ | 410 | struct type *parent, *gparent, *tmp; \ |
@@ -433,7 +448,7 @@ name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ | |||
433 | RB_COLOR(head->rbh_root, field) = RB_BLACK; \ | 448 | RB_COLOR(head->rbh_root, field) = RB_BLACK; \ |
434 | } \ | 449 | } \ |
435 | \ | 450 | \ |
436 | void \ | 451 | attr void \ |
437 | name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ | 452 | name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ |
438 | { \ | 453 | { \ |
439 | struct type *tmp; \ | 454 | struct type *tmp; \ |
@@ -509,7 +524,7 @@ name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) | |||
509 | RB_COLOR(elm, field) = RB_BLACK; \ | 524 | RB_COLOR(elm, field) = RB_BLACK; \ |
510 | } \ | 525 | } \ |
511 | \ | 526 | \ |
512 | struct type * \ | 527 | attr struct type * \ |
513 | name##_RB_REMOVE(struct name *head, struct type *elm) \ | 528 | name##_RB_REMOVE(struct name *head, struct type *elm) \ |
514 | { \ | 529 | { \ |
515 | struct type *child, *parent, *old = elm; \ | 530 | struct type *child, *parent, *old = elm; \ |
@@ -577,7 +592,7 @@ color: \ | |||
577 | } \ | 592 | } \ |
578 | \ | 593 | \ |
579 | /* Inserts a node into the RB tree */ \ | 594 | /* Inserts a node into the RB tree */ \ |
580 | struct type * \ | 595 | attr struct type * \ |
581 | name##_RB_INSERT(struct name *head, struct type *elm) \ | 596 | name##_RB_INSERT(struct name *head, struct type *elm) \ |
582 | { \ | 597 | { \ |
583 | struct type *tmp; \ | 598 | struct type *tmp; \ |
@@ -608,7 +623,7 @@ name##_RB_INSERT(struct name *head, struct type *elm) \ | |||
608 | } \ | 623 | } \ |
609 | \ | 624 | \ |
610 | /* Finds the node with the same key as elm */ \ | 625 | /* Finds the node with the same key as elm */ \ |
611 | struct type * \ | 626 | attr struct type * \ |
612 | name##_RB_FIND(struct name *head, struct type *elm) \ | 627 | name##_RB_FIND(struct name *head, struct type *elm) \ |
613 | { \ | 628 | { \ |
614 | struct type *tmp = RB_ROOT(head); \ | 629 | struct type *tmp = RB_ROOT(head); \ |
@@ -625,7 +640,29 @@ name##_RB_FIND(struct name *head, struct type *elm) \ | |||
625 | return (NULL); \ | 640 | return (NULL); \ |
626 | } \ | 641 | } \ |
627 | \ | 642 | \ |
628 | struct type * \ | 643 | /* Finds the first node greater than or equal to the search key */ \ |
644 | attr struct type * \ | ||
645 | name##_RB_NFIND(struct name *head, struct type *elm) \ | ||
646 | { \ | ||
647 | struct type *tmp = RB_ROOT(head); \ | ||
648 | struct type *res = NULL; \ | ||
649 | int comp; \ | ||
650 | while (tmp) { \ | ||
651 | comp = cmp(elm, tmp); \ | ||
652 | if (comp < 0) { \ | ||
653 | res = tmp; \ | ||
654 | tmp = RB_LEFT(tmp, field); \ | ||
655 | } \ | ||
656 | else if (comp > 0) \ | ||
657 | tmp = RB_RIGHT(tmp, field); \ | ||
658 | else \ | ||
659 | return (tmp); \ | ||
660 | } \ | ||
661 | return (res); \ | ||
662 | } \ | ||
663 | \ | ||
664 | /* ARGSUSED */ \ | ||
665 | attr struct type * \ | ||
629 | name##_RB_NEXT(struct type *elm) \ | 666 | name##_RB_NEXT(struct type *elm) \ |
630 | { \ | 667 | { \ |
631 | if (RB_RIGHT(elm, field)) { \ | 668 | if (RB_RIGHT(elm, field)) { \ |
@@ -646,7 +683,29 @@ name##_RB_NEXT(struct type *elm) \ | |||
646 | return (elm); \ | 683 | return (elm); \ |
647 | } \ | 684 | } \ |
648 | \ | 685 | \ |
649 | struct type * \ | 686 | /* ARGSUSED */ \ |
687 | attr struct type * \ | ||
688 | name##_RB_PREV(struct type *elm) \ | ||
689 | { \ | ||
690 | if (RB_LEFT(elm, field)) { \ | ||
691 | elm = RB_LEFT(elm, field); \ | ||
692 | while (RB_RIGHT(elm, field)) \ | ||
693 | elm = RB_RIGHT(elm, field); \ | ||
694 | } else { \ | ||
695 | if (RB_PARENT(elm, field) && \ | ||
696 | (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ | ||
697 | elm = RB_PARENT(elm, field); \ | ||
698 | else { \ | ||
699 | while (RB_PARENT(elm, field) && \ | ||
700 | (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ | ||
701 | elm = RB_PARENT(elm, field); \ | ||
702 | elm = RB_PARENT(elm, field); \ | ||
703 | } \ | ||
704 | } \ | ||
705 | return (elm); \ | ||
706 | } \ | ||
707 | \ | ||
708 | attr struct type * \ | ||
650 | name##_RB_MINMAX(struct name *head, int val) \ | 709 | name##_RB_MINMAX(struct name *head, int val) \ |
651 | { \ | 710 | { \ |
652 | struct type *tmp = RB_ROOT(head); \ | 711 | struct type *tmp = RB_ROOT(head); \ |
@@ -667,7 +726,9 @@ name##_RB_MINMAX(struct name *head, int val) \ | |||
667 | #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) | 726 | #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) |
668 | #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) | 727 | #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) |
669 | #define RB_FIND(name, x, y) name##_RB_FIND(x, y) | 728 | #define RB_FIND(name, x, y) name##_RB_FIND(x, y) |
729 | #define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) | ||
670 | #define RB_NEXT(name, x, y) name##_RB_NEXT(y) | 730 | #define RB_NEXT(name, x, y) name##_RB_NEXT(y) |
731 | #define RB_PREV(name, x, y) name##_RB_PREV(y) | ||
671 | #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) | 732 | #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) |
672 | #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) | 733 | #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) |
673 | 734 | ||
@@ -676,4 +737,19 @@ name##_RB_MINMAX(struct name *head, int val) \ | |||
676 | (x) != NULL; \ | 737 | (x) != NULL; \ |
677 | (x) = name##_RB_NEXT(x)) | 738 | (x) = name##_RB_NEXT(x)) |
678 | 739 | ||
740 | #define RB_FOREACH_SAFE(x, name, head, y) \ | ||
741 | for ((x) = RB_MIN(name, head); \ | ||
742 | ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ | ||
743 | (x) = (y)) | ||
744 | |||
745 | #define RB_FOREACH_REVERSE(x, name, head) \ | ||
746 | for ((x) = RB_MAX(name, head); \ | ||
747 | (x) != NULL; \ | ||
748 | (x) = name##_RB_PREV(x)) | ||
749 | |||
750 | #define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ | ||
751 | for ((x) = RB_MAX(name, head); \ | ||
752 | ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ | ||
753 | (x) = (y)) | ||
754 | |||
679 | #endif /* _SYS_TREE_H_ */ | 755 | #endif /* _SYS_TREE_H_ */ |
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c index 3a087b341..f6f5665c1 100644 --- a/openbsd-compat/vis.c +++ b/openbsd-compat/vis.c | |||
@@ -31,7 +31,7 @@ | |||
31 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ | 31 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ |
32 | 32 | ||
33 | #include "includes.h" | 33 | #include "includes.h" |
34 | #if !defined(HAVE_STRNVIS) | 34 | #if !defined(HAVE_STRNVIS) || defined(BROKEN_STRNVIS) |
35 | 35 | ||
36 | #include <ctype.h> | 36 | #include <ctype.h> |
37 | #include <string.h> | 37 | #include <string.h> |
diff --git a/openbsd-compat/vis.h b/openbsd-compat/vis.h index 3898a9e70..d1286c99d 100644 --- a/openbsd-compat/vis.h +++ b/openbsd-compat/vis.h | |||
@@ -35,7 +35,7 @@ | |||
35 | /* OPENBSD ORIGINAL: include/vis.h */ | 35 | /* OPENBSD ORIGINAL: include/vis.h */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | #if !defined(HAVE_STRNVIS) | 38 | #if !defined(HAVE_STRNVIS) || defined(BROKEN_STRNVIS) |
39 | 39 | ||
40 | #ifndef _VIS_H_ | 40 | #ifndef _VIS_H_ |
41 | #define _VIS_H_ | 41 | #define _VIS_H_ |
@@ -92,4 +92,4 @@ ssize_t strnunvis(char *, const char *, size_t) | |||
92 | 92 | ||
93 | #endif /* !_VIS_H_ */ | 93 | #endif /* !_VIS_H_ */ |
94 | 94 | ||
95 | #endif /* !HAVE_STRNVIS */ | 95 | #endif /* !HAVE_STRNVIS || BROKEN_STRNVIS */ |