mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-08-24 09:27:46 +02:00
Compare commits
294 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
22fddb16f8 | ||
![]() |
abe3c8c332 | ||
![]() |
1d711a2ced | ||
![]() |
aff40cae08 | ||
![]() |
04a24db27a | ||
![]() |
b62f36f305 | ||
![]() |
2a3d521318 | ||
![]() |
149aafe198 | ||
![]() |
435825784f | ||
![]() |
31e9396bf2 | ||
![]() |
3b8416acab | ||
![]() |
94d0fb3c53 | ||
![]() |
e848f5aa29 | ||
![]() |
ee63bca525 | ||
![]() |
9cbd935d92 | ||
![]() |
70f49a7028 | ||
![]() |
b6ccd03201 | ||
![]() |
08188f3c13 | ||
![]() |
644062da40 | ||
![]() |
32d18dcf47 | ||
![]() |
605614d642 | ||
![]() |
ec7f5ee984 | ||
![]() |
5392f0c1a4 | ||
![]() |
be4aced4c5 | ||
![]() |
27503a1066 | ||
![]() |
99739877be | ||
![]() |
0bdbc0787e | ||
![]() |
de124dcafa | ||
![]() |
1d28729514 | ||
![]() |
a81d0b7113 | ||
![]() |
c8e5338a7c | ||
![]() |
b6d6da4cd4 | ||
![]() |
f8cb9d8b28 | ||
![]() |
154624ab45 | ||
![]() |
9fab225f26 | ||
![]() |
461f10ac57 | ||
![]() |
f050160976 | ||
![]() |
19e06407eb | ||
![]() |
10920c3084 | ||
![]() |
97b0fe84b8 | ||
![]() |
e87ae3be19 | ||
![]() |
9275d134e5 | ||
![]() |
304a1f831c | ||
![]() |
edddd806df | ||
![]() |
dd0bdb58e0 | ||
![]() |
0813f3786f | ||
![]() |
df116b5597 | ||
![]() |
ecb44e1655 | ||
![]() |
459b7f7d24 | ||
![]() |
a44f885cd4 | ||
![]() |
3f5ca0aae4 | ||
![]() |
9d3e59a01d | ||
![]() |
f02562d64a | ||
![]() |
b7367c9ced | ||
![]() |
6777eb62b8 | ||
![]() |
d4e0cdc916 | ||
![]() |
f41d6c12aa | ||
![]() |
30b48ed9ea | ||
![]() |
d0d8d0197f | ||
![]() |
cf61ebb845 | ||
![]() |
73b25a8f87 | ||
![]() |
5434ba169b | ||
![]() |
dc1bd1a2cb | ||
![]() |
edc746ea7b | ||
![]() |
8f998d1d20 | ||
![]() |
d08163b4fe | ||
![]() |
1186cf8822 | ||
![]() |
6385ccc977 | ||
![]() |
c12068179c | ||
![]() |
9fa06763a1 | ||
![]() |
92337b15a2 | ||
![]() |
90b7f3aeba | ||
![]() |
426bf45278 | ||
![]() |
21d12b0211 | ||
![]() |
bc65806ce2 | ||
![]() |
8b7a4d9d3b | ||
![]() |
ccbfd1c241 | ||
![]() |
e0976d7e90 | ||
![]() |
49c7dd1ca4 | ||
![]() |
8622767a8a | ||
![]() |
8f61036467 | ||
![]() |
ae7942ba6d | ||
![]() |
a5faf17090 | ||
![]() |
06e8a1b29b | ||
![]() |
44824aca3c | ||
![]() |
1fb6c3f4ce | ||
![]() |
fe16f3863e | ||
![]() |
7c652a94ea | ||
![]() |
ed2eb31da9 | ||
![]() |
0f8bcdfd92 | ||
![]() |
07192b31e3 | ||
![]() |
ca3db5e134 | ||
![]() |
ff46386fcb | ||
![]() |
4c6da577a1 | ||
![]() |
830dd88a98 | ||
![]() |
257800a03c | ||
![]() |
536a7d42fd | ||
![]() |
7ed5de0158 | ||
![]() |
05a802a2c1 | ||
![]() |
5962e03c2d | ||
![]() |
59a21c7fb8 | ||
![]() |
7b4ebd6521 | ||
![]() |
0dfbe7699e | ||
![]() |
dec783dce5 | ||
![]() |
fe21244b05 | ||
![]() |
ec88b7bbbc | ||
![]() |
23377191e8 | ||
![]() |
5dea9da38d | ||
![]() |
b9bf42ddc3 | ||
![]() |
e57c07875c | ||
![]() |
80f1927dcd | ||
![]() |
b7a8bc22c9 | ||
![]() |
e50896286c | ||
![]() |
00b538ffa3 | ||
![]() |
5cfa39e5cd | ||
![]() |
084911ce87 | ||
![]() |
3538d38fe7 | ||
![]() |
03fccd1505 | ||
![]() |
6b6e686b23 | ||
![]() |
da1f45ac71 | ||
![]() |
2f9eddc277 | ||
![]() |
28298ac037 | ||
![]() |
ef981f930b | ||
![]() |
6928d7895e | ||
![]() |
d5865759f8 | ||
![]() |
be327c6ebe | ||
![]() |
a14612d968 | ||
![]() |
f4baceb82c | ||
![]() |
f35c545847 | ||
![]() |
b466b14afb | ||
![]() |
1f6a48b209 | ||
![]() |
873639ebb5 | ||
![]() |
c9c78fdfd0 | ||
![]() |
5f21307570 | ||
![]() |
84acf21568 | ||
![]() |
15200ec7ac | ||
![]() |
f7465b93ec | ||
![]() |
e5ed5fdd62 | ||
![]() |
abb1a6b1a7 | ||
![]() |
c9ff83687c | ||
![]() |
62e67bb49e | ||
![]() |
87b1307040 | ||
![]() |
ba3c46b30f | ||
![]() |
091097e062 | ||
![]() |
5f9608c775 | ||
![]() |
eef07993c9 | ||
![]() |
c6d589bc71 | ||
![]() |
2975d809a0 | ||
![]() |
f11ab67223 | ||
![]() |
54796231c7 | ||
![]() |
7aed0edf73 | ||
![]() |
fafcc397ac | ||
![]() |
48107fc8c4 | ||
![]() |
e7cf8c5785 | ||
![]() |
25d35625eb | ||
![]() |
500b3080a2 | ||
![]() |
1eba406021 | ||
![]() |
8ad7570c20 | ||
![]() |
43a8270317 | ||
![]() |
6a71b24b63 | ||
![]() |
7389fe8d24 | ||
![]() |
2716dfd0b7 | ||
![]() |
54f8745657 | ||
![]() |
428be9e030 | ||
![]() |
c7a5d780ae | ||
![]() |
1808d64b77 | ||
![]() |
beafad2657 | ||
![]() |
6145b56178 | ||
![]() |
731b0a7739 | ||
![]() |
50b50a4330 | ||
![]() |
25e88f6479 | ||
![]() |
04a8fb2469 | ||
![]() |
4f68a88f55 | ||
![]() |
8f59221c4f | ||
![]() |
72a82ee262 | ||
![]() |
3c305f2873 | ||
![]() |
25278891d8 | ||
![]() |
e35d9141dc | ||
![]() |
4feda87049 | ||
![]() |
d563a17430 | ||
![]() |
785cf9d1e9 | ||
![]() |
15bd284b29 | ||
![]() |
a9fc285988 | ||
![]() |
c0d86a6412 | ||
![]() |
1fb25b7dca | ||
![]() |
31f034e386 | ||
![]() |
2374f409de | ||
![]() |
a4e0db2b97 | ||
![]() |
43d34c9d3b | ||
![]() |
1c3ff61699 | ||
![]() |
edea268ce9 | ||
![]() |
e832b7687e | ||
![]() |
c4fca5bb4f | ||
![]() |
a1f79978e8 | ||
![]() |
4676026286 | ||
![]() |
25f9b30678 | ||
![]() |
18ebabf223 | ||
![]() |
4ab11c7f48 | ||
![]() |
766c883e30 | ||
![]() |
a4de4d95a6 | ||
![]() |
233cab9d64 | ||
![]() |
2462cd8888 | ||
![]() |
d54ceb37ce | ||
![]() |
847e682f8d | ||
![]() |
68f980c90d | ||
![]() |
37a9b56c05 | ||
![]() |
45dd5229ea | ||
![]() |
01f0d1ea1e | ||
![]() |
9c85d828a1 | ||
![]() |
eac4ce0c67 | ||
![]() |
5ecff0c903 | ||
![]() |
8c5a83d678 | ||
![]() |
d5b04ab19c | ||
![]() |
cfeafeabad | ||
![]() |
3d6b6ead64 | ||
![]() |
eb445425ff | ||
![]() |
59f6a95609 | ||
![]() |
3548c5f6bf | ||
![]() |
a11c98a6b5 | ||
![]() |
5745ca0362 | ||
![]() |
9628798d7d | ||
![]() |
f34a5f71d9 | ||
![]() |
72c68868c8 | ||
![]() |
a4323f2b16 | ||
![]() |
4997efa59a | ||
![]() |
96202c6c14 | ||
![]() |
61d378f5e9 | ||
![]() |
9d917aad37 | ||
![]() |
18662cadfc | ||
![]() |
ce53f7c25f | ||
![]() |
24d1f4dd34 | ||
![]() |
e9529d9b4a | ||
![]() |
3aaedb1208 | ||
![]() |
2c754f435b | ||
![]() |
ee4d24970a | ||
![]() |
8d2afa3a9f | ||
![]() |
e9f6faf3aa | ||
![]() |
99320b9168 | ||
![]() |
71c710e9a8 | ||
![]() |
21f4052c5b | ||
![]() |
1899e2c5ab | ||
![]() |
4803340802 | ||
![]() |
f99b8ea527 | ||
![]() |
4bed48398f | ||
![]() |
2e071c3cc1 | ||
![]() |
890699a78b | ||
![]() |
b0ebb0d4c2 | ||
![]() |
73aea4f808 | ||
![]() |
7cfa2d4530 | ||
![]() |
574c7a1365 | ||
![]() |
c2d9d84088 | ||
![]() |
2ebe6d5a02 | ||
![]() |
aeea1f4083 | ||
![]() |
0500a1bd08 | ||
![]() |
3d9c6c08ed | ||
![]() |
b9dee9f69a | ||
![]() |
81c3c3e405 | ||
![]() |
5e0998fa4f | ||
![]() |
8e2d55047c | ||
![]() |
13c32916b4 | ||
![]() |
8e834cd068 | ||
![]() |
e354f9b1d0 | ||
![]() |
4c5e9b478e | ||
![]() |
005b509061 | ||
![]() |
a8531ad051 | ||
![]() |
c4b0fd2c9f | ||
![]() |
1ca09c18f7 | ||
![]() |
e4e15ed286 | ||
![]() |
bf697b900c | ||
![]() |
f1966385b3 | ||
![]() |
e007233cf0 | ||
![]() |
3cabf46bb0 | ||
![]() |
6eebc1f264 | ||
![]() |
a1730c1063 | ||
![]() |
6f68c93076 | ||
![]() |
e13b1a337a | ||
![]() |
ef5faeb575 | ||
![]() |
2d7de186e9 | ||
![]() |
3efad64155 | ||
![]() |
a6f407ab0d | ||
![]() |
21edbb4f22 | ||
![]() |
e3979d1a7c | ||
![]() |
facbddb652 | ||
![]() |
3d88c999b4 | ||
![]() |
e42381dc51 | ||
![]() |
993828d84e | ||
![]() |
30b4d50754 | ||
![]() |
f6ed7c278b | ||
![]() |
1f8a3f7bcc | ||
![]() |
b20272f5a9 | ||
![]() |
11ec8f1e5d | ||
![]() |
5ba8c5bab0 | ||
![]() |
0093ca2b0e | ||
![]() |
0b65d43963 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
ChangeLog
|
ChangeLog
|
||||||
|
*~
|
||||||
*.pc
|
*.pc
|
||||||
*.la
|
*.la
|
||||||
*.lo
|
*.lo
|
||||||
@ -7,6 +8,10 @@ ChangeLog
|
|||||||
*.a
|
*.a
|
||||||
*.log
|
*.log
|
||||||
*.trs
|
*.trs
|
||||||
|
*.gcda
|
||||||
|
*.gcno
|
||||||
|
*.sym
|
||||||
|
*.map
|
||||||
.dirstamp
|
.dirstamp
|
||||||
.deps/
|
.deps/
|
||||||
.libs/
|
.libs/
|
||||||
@ -17,6 +22,6 @@ autom4te.cache/
|
|||||||
build-aux/
|
build-aux/
|
||||||
configure
|
configure
|
||||||
config.*
|
config.*
|
||||||
|
format.ld
|
||||||
libtool
|
libtool
|
||||||
m4/
|
|
||||||
stamp-h1
|
stamp-h1
|
||||||
|
54
.gitlab-ci.yml
Normal file
54
.gitlab-ci.yml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
.vpath-tests:
|
||||||
|
script:
|
||||||
|
- ./autogen
|
||||||
|
- mkdir -p build-tree
|
||||||
|
- cd build-tree
|
||||||
|
- ../configure
|
||||||
|
- make check
|
||||||
|
|
||||||
|
.unit-tests:
|
||||||
|
script:
|
||||||
|
- ./autogen && ./configure
|
||||||
|
- make check
|
||||||
|
|
||||||
|
.unit-tests-asan:
|
||||||
|
script:
|
||||||
|
- ./autogen && ./configure --enable-sanitize
|
||||||
|
- make check
|
||||||
|
|
||||||
|
.coverage:
|
||||||
|
script:
|
||||||
|
- ./autogen && ./configure --disable-static
|
||||||
|
- make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
|
||||||
|
- gcovr -s -e test/
|
||||||
|
coverage: /^TOTAL.*\s+(\d+\%)$/
|
||||||
|
|
||||||
|
.debian:
|
||||||
|
image: debian:latest
|
||||||
|
stage: test
|
||||||
|
before_script:
|
||||||
|
- apt-get update -qq
|
||||||
|
- apt-get install -qq -y --no-install-recommends
|
||||||
|
git gcc make autoconf automake libtool libmd-dev gcovr
|
||||||
|
|
||||||
|
.alpine:
|
||||||
|
image: alpine:latest
|
||||||
|
stage: test
|
||||||
|
before_script:
|
||||||
|
- apk add --no-cache git gcc make autoconf automake libtool
|
||||||
|
bsd-compat-headers linux-headers libmd-dev musl-dev gcovr
|
||||||
|
|
||||||
|
vpath-tests:debian:
|
||||||
|
extends: [.debian, .vpath-tests]
|
||||||
|
|
||||||
|
unit-tests:debian:
|
||||||
|
extends: [.debian, .unit-tests-asan]
|
||||||
|
|
||||||
|
coverage:debian:
|
||||||
|
extends: [.debian, .coverage]
|
||||||
|
|
||||||
|
unit-tests:alpine:
|
||||||
|
extends: [.alpine, .unit-tests]
|
||||||
|
|
||||||
|
coverage:alpine:
|
||||||
|
extends: [.alpine, .coverage]
|
313
COPYING
313
COPYING
@ -3,87 +3,24 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
|||||||
Files:
|
Files:
|
||||||
*
|
*
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 2004-2006, 2008-2017 Guillem Jover <guillem@hadrons.org>
|
Copyright © 2004-2024 Guillem Jover <guillem@hadrons.org>
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
|
|
||||||
Files:
|
|
||||||
man/arc4random.3bsd
|
|
||||||
man/tree.3bsd
|
|
||||||
Copyright:
|
|
||||||
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
|
||||||
All rights reserved.
|
|
||||||
License: BSD-4-clause-Niels-Provos
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. All advertising materials mentioning features or use of this software
|
|
||||||
must display the following acknowledgement:
|
|
||||||
This product includes software developed by Niels Provos.
|
|
||||||
4. The name of the author may not be used to endorse or promote products
|
|
||||||
derived from this software without specific prior written permission.
|
|
||||||
.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
|
||||||
man/getprogname.3bsd
|
|
||||||
Copyright:
|
|
||||||
Copyright © 2001 Christopher G. Demetriou
|
|
||||||
All rights reserved.
|
|
||||||
License: BSD-4-clause-Christopher-G-Demetriou
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. All advertising materials mentioning features or use of this software
|
|
||||||
must display the following acknowledgement:
|
|
||||||
This product includes software developed for the
|
|
||||||
NetBSD Project. See http://www.netbsd.org/ for
|
|
||||||
information about NetBSD.
|
|
||||||
4. The name of the author may not be used to endorse or promote products
|
|
||||||
derived from this software without specific prior written permission.
|
|
||||||
.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
include/bsd/err.h
|
include/bsd/err.h
|
||||||
include/bsd/stdlib.h
|
include/bsd/stdlib.h
|
||||||
|
include/bsd/sys/param.h
|
||||||
include/bsd/unistd.h
|
include/bsd/unistd.h
|
||||||
src/bsd_getopt.c
|
src/bsd_getopt.c
|
||||||
src/err.c
|
src/err.c
|
||||||
src/fgetln.c
|
src/fgetln.c
|
||||||
src/progname.c
|
src/progname.c
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 2005, 2008-2012 Guillem Jover <guillem@hadrons.org>
|
Copyright © 2005, 2008-2012, 2019 Guillem Jover <guillem@hadrons.org>
|
||||||
Copyright © 2005 Hector Garcia Alvarez
|
Copyright © 2005 Hector Garcia Alvarez
|
||||||
Copyright © 2005 Aurelien Jarno
|
Copyright © 2005 Aurelien Jarno
|
||||||
Copyright © 2006 Robert Millan
|
Copyright © 2006 Robert Millan
|
||||||
|
Copyright © 2018 Facebook, Inc.
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
@ -103,6 +40,7 @@ Files:
|
|||||||
man/getbsize.3bsd
|
man/getbsize.3bsd
|
||||||
man/heapsort.3bsd
|
man/heapsort.3bsd
|
||||||
man/nlist.3bsd
|
man/nlist.3bsd
|
||||||
|
man/pwcache.3bsd
|
||||||
man/queue.3bsd
|
man/queue.3bsd
|
||||||
man/radixsort.3bsd
|
man/radixsort.3bsd
|
||||||
man/reallocarray.3bsd
|
man/reallocarray.3bsd
|
||||||
@ -110,6 +48,8 @@ Files:
|
|||||||
man/setmode.3bsd
|
man/setmode.3bsd
|
||||||
man/strmode.3bsd
|
man/strmode.3bsd
|
||||||
man/strnstr.3bsd
|
man/strnstr.3bsd
|
||||||
|
man/strtoi.3bsd
|
||||||
|
man/strtou.3bsd
|
||||||
man/unvis.3bsd
|
man/unvis.3bsd
|
||||||
man/vis.3bsd
|
man/vis.3bsd
|
||||||
man/wcslcpy.3bsd
|
man/wcslcpy.3bsd
|
||||||
@ -117,15 +57,18 @@ Files:
|
|||||||
src/heapsort.c
|
src/heapsort.c
|
||||||
src/merge.c
|
src/merge.c
|
||||||
src/nlist.c
|
src/nlist.c
|
||||||
|
src/pwcache.c
|
||||||
src/radixsort.c
|
src/radixsort.c
|
||||||
src/setmode.c
|
src/setmode.c
|
||||||
src/strmode.c
|
src/strmode.c
|
||||||
src/strnstr.c
|
src/strnstr.c
|
||||||
|
src/strtoi.c
|
||||||
|
src/strtou.c
|
||||||
src/unvis.c
|
src/unvis.c
|
||||||
src/vis.c
|
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 1980, 1982, 1986, 1989-1994
|
Copyright © 1980, 1982, 1986, 1989-1994
|
||||||
The Regents of the University of California. All rights reserved.
|
The Regents of the University of California. All rights reserved.
|
||||||
|
Copyright © 1992 Keith Muller.
|
||||||
Copyright © 2001 Mike Barcroft <mike@FreeBSD.org>
|
Copyright © 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||||
.
|
.
|
||||||
Some code is derived from software contributed to Berkeley by
|
Some code is derived from software contributed to Berkeley by
|
||||||
@ -153,29 +96,16 @@ Copyright:
|
|||||||
Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||||
the permission of UNIX System Laboratories, Inc.
|
the permission of UNIX System Laboratories, Inc.
|
||||||
License: BSD-3-clause-Regents
|
License: BSD-3-clause-Regents
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
Files:
|
||||||
are met:
|
src/vis.c
|
||||||
1. Redistributions of source code must retain the above copyright
|
Copyright:
|
||||||
notice, this list of conditions and the following disclaimer.
|
Copyright © 1989, 1993
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
The Regents of the University of California. All rights reserved.
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. Neither the name of the University nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software
|
|
||||||
without specific prior written permission.
|
|
||||||
.
|
.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
Copyright © 1999, 2005 The NetBSD Foundation, Inc.
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
All rights reserved.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
License: BSD-3-clause-Regents and BSD-2-clause-NetBSD
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
include/bsd/libutil.h
|
include/bsd/libutil.h
|
||||||
@ -184,30 +114,7 @@ Copyright:
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
Copyright © 2002 Networks Associates Technology, Inc.
|
Copyright © 2002 Networks Associates Technology, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
License: BSD-3-clause-Peter-Wemm
|
License: BSD-3-clause-author
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, is permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. The name of the author may not be used to endorse or promote
|
|
||||||
products derived from this software without specific prior written
|
|
||||||
permission.
|
|
||||||
.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
man/timeradd.3bsd
|
man/timeradd.3bsd
|
||||||
@ -264,6 +171,7 @@ License: BSD-5-clause-Peter-Wemm
|
|||||||
|
|
||||||
Files:
|
Files:
|
||||||
include/bsd/stringlist.h
|
include/bsd/stringlist.h
|
||||||
|
man/arc4random.3bsd
|
||||||
man/fmtcheck.3bsd
|
man/fmtcheck.3bsd
|
||||||
man/humanize_number.3bsd
|
man/humanize_number.3bsd
|
||||||
man/stringlist.3bsd
|
man/stringlist.3bsd
|
||||||
@ -271,10 +179,19 @@ Files:
|
|||||||
src/fmtcheck.c
|
src/fmtcheck.c
|
||||||
src/humanize_number.c
|
src/humanize_number.c
|
||||||
src/stringlist.c
|
src/stringlist.c
|
||||||
|
src/strtonum.c
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 1994, 1997-2000, 2002, 2008, 2010 The NetBSD Foundation, Inc.
|
Copyright © 1994, 1997-2000, 2002, 2008, 2010, 2014
|
||||||
|
The NetBSD Foundation, Inc.
|
||||||
|
Copyright © 2013 John-Mark Gurney <jmg@FreeBSD.org>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
.
|
.
|
||||||
|
Copyright © 2014 The NetBSD Foundation, Inc.
|
||||||
|
All rights reserved.
|
||||||
|
.
|
||||||
|
Some code was derived from software contributed to The NetBSD Foundation
|
||||||
|
by Taylor R. Campbell.
|
||||||
|
.
|
||||||
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
||||||
.
|
.
|
||||||
Some code was contributed to The NetBSD Foundation by Luke Mewburn.
|
Some code was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||||
@ -293,26 +210,6 @@ Copyright:
|
|||||||
Some code is derived from software contributed to The NetBSD Foundation
|
Some code is derived from software contributed to The NetBSD Foundation
|
||||||
by Jukka Ruohonen.
|
by Jukka Ruohonen.
|
||||||
License: BSD-2-clause-NetBSD
|
License: BSD-2-clause-NetBSD
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
||||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
||||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
include/bsd/sys/endian.h
|
include/bsd/sys/endian.h
|
||||||
@ -323,8 +220,6 @@ Files:
|
|||||||
man/getpeereid.3bsd
|
man/getpeereid.3bsd
|
||||||
man/pidfile.3bsd
|
man/pidfile.3bsd
|
||||||
src/expand_number.c
|
src/expand_number.c
|
||||||
src/hash/sha512.h
|
|
||||||
src/hash/sha512c.c
|
|
||||||
src/pidfile.c
|
src/pidfile.c
|
||||||
src/reallocf.c
|
src/reallocf.c
|
||||||
src/timeconv.c
|
src/timeconv.c
|
||||||
@ -358,7 +253,6 @@ Copyright:
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
.
|
.
|
||||||
Copyright © 2009 Advanced Computing Technologies LLC
|
Copyright © 2009 Advanced Computing Technologies LLC
|
||||||
Written by: John H. Baldwin <jhb@FreeBSD.org>
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
.
|
.
|
||||||
Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
@ -367,7 +261,7 @@ License: BSD-2-clause
|
|||||||
Files:
|
Files:
|
||||||
src/flopen.c
|
src/flopen.c
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
Copyright © 2007-2009 Dag-Erling Coïdan Smørgrav
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
License: BSD-2-clause-verbatim
|
License: BSD-2-clause-verbatim
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -395,6 +289,7 @@ License: BSD-2-clause-verbatim
|
|||||||
Files:
|
Files:
|
||||||
include/bsd/sys/tree.h
|
include/bsd/sys/tree.h
|
||||||
man/fparseln.3bsd
|
man/fparseln.3bsd
|
||||||
|
man/tree.3bsd
|
||||||
src/fparseln.c
|
src/fparseln.c
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 1997 Christos Zoulas.
|
Copyright © 1997 Christos Zoulas.
|
||||||
@ -403,25 +298,6 @@ Copyright:
|
|||||||
Copyright © 2002 Niels Provos <provos@citi.umich.edu>
|
Copyright © 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
License: BSD-2-clause-author
|
License: BSD-2-clause-author
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
include/bsd/readpassphrase.h
|
include/bsd/readpassphrase.h
|
||||||
@ -429,10 +305,12 @@ Files:
|
|||||||
man/strlcpy.3bsd
|
man/strlcpy.3bsd
|
||||||
man/strtonum.3bsd
|
man/strtonum.3bsd
|
||||||
src/arc4random.c
|
src/arc4random.c
|
||||||
src/arc4random_openbsd.h
|
src/arc4random_linux.h
|
||||||
src/arc4random_uniform.c
|
src/arc4random_uniform.c
|
||||||
src/arc4random_unix.h
|
src/arc4random_unix.h
|
||||||
|
src/arc4random_win.h
|
||||||
src/closefrom.c
|
src/closefrom.c
|
||||||
|
src/freezero.c
|
||||||
src/getentropy_aix.c
|
src/getentropy_aix.c
|
||||||
src/getentropy_bsd.c
|
src/getentropy_bsd.c
|
||||||
src/getentropy_hpux.c
|
src/getentropy_hpux.c
|
||||||
@ -440,11 +318,14 @@ Files:
|
|||||||
src/getentropy_linux.c
|
src/getentropy_linux.c
|
||||||
src/getentropy_osx.c
|
src/getentropy_osx.c
|
||||||
src/getentropy_solaris.c
|
src/getentropy_solaris.c
|
||||||
|
src/getentropy_win.c
|
||||||
src/readpassphrase.c
|
src/readpassphrase.c
|
||||||
src/reallocarray.c
|
src/reallocarray.c
|
||||||
|
src/recallocarray.c
|
||||||
src/strlcat.c
|
src/strlcat.c
|
||||||
src/strlcpy.c
|
src/strlcpy.c
|
||||||
src/strtonum.c
|
test/explicit_bzero.c
|
||||||
|
test/strtonum.c
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 2004 Ted Unangst and Todd Miller
|
Copyright © 2004 Ted Unangst and Todd Miller
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
@ -453,15 +334,17 @@ Copyright:
|
|||||||
Copyright © 1998, 2000-2002, 2004-2005, 2007, 2010, 2012-2015
|
Copyright © 1998, 2000-2002, 2004-2005, 2007, 2010, 2012-2015
|
||||||
Todd C. Miller <Todd.Miller@courtesan.com>
|
Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
Copyright © 2004 Ted Unangst
|
Copyright © 2004 Ted Unangst
|
||||||
|
Copyright © 2004 Otto Moerbeek <otto@drijf.net>
|
||||||
Copyright © 2008 Damien Miller <djm@openbsd.org>
|
Copyright © 2008 Damien Miller <djm@openbsd.org>
|
||||||
Copyright © 2008 Otto Moerbeek <otto@drijf.net>
|
Copyright © 2008, 2010-2011, 2016-2017 Otto Moerbeek <otto@drijf.net>
|
||||||
Copyright © 2013 Markus Friedl <markus@openbsd.org>
|
Copyright © 2013 Markus Friedl <markus@openbsd.org>
|
||||||
Copyright © 2014 Bob Beck <beck@obtuse.com>
|
Copyright © 2014 Bob Beck <beck@obtuse.com>
|
||||||
Copyright © 2014 Brent Cook <bcook@openbsd.org>
|
Copyright © 2014 Brent Cook <bcook@openbsd.org>
|
||||||
Copyright © 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
Copyright © 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
Copyright © 2014 Theo de Raadt <deraadt@openbsd.org>
|
Copyright © 2014 Theo de Raadt <deraadt@openbsd.org>
|
||||||
|
Copyright © 2014 Google Inc.
|
||||||
Copyright © 2015 Michael Felt <aixtools@gmail.com>
|
Copyright © 2015 Michael Felt <aixtools@gmail.com>
|
||||||
Copyright © 2015 Guillem Jover <guillem@hadrons.org>
|
Copyright © 2015, 2022 Guillem Jover <guillem@hadrons.org>
|
||||||
License: ISC
|
License: ISC
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
@ -518,17 +401,6 @@ License: Expat
|
|||||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
Files:
|
|
||||||
include/bsd/md5.h
|
|
||||||
src/hash/md5.c
|
|
||||||
Copyright:
|
|
||||||
None
|
|
||||||
License: public-domain-Colin-Plumb
|
|
||||||
This code implements the MD5 message-digest algorithm.
|
|
||||||
The algorithm is due to Ron Rivest. This code was
|
|
||||||
written by Colin Plumb in 1993, no copyright is claimed.
|
|
||||||
This code is in the public domain; do with it what you wish.
|
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
src/explicit_bzero.c
|
src/explicit_bzero.c
|
||||||
src/chacha_private.h
|
src/chacha_private.h
|
||||||
@ -539,8 +411,6 @@ License: public-domain
|
|||||||
|
|
||||||
Files:
|
Files:
|
||||||
man/mdX.3bsd
|
man/mdX.3bsd
|
||||||
src/hash/md5hl.c
|
|
||||||
src/hash/helper.c
|
|
||||||
Copyright:
|
Copyright:
|
||||||
None
|
None
|
||||||
License: Beerware
|
License: Beerware
|
||||||
@ -549,6 +419,56 @@ License: Beerware
|
|||||||
can do whatever you want with this stuff. If we meet some day, and you think
|
can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||||
|
|
||||||
|
License: BSD-3-clause-Regents
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. Neither the name of the University nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
.
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
License: BSD-3-clause-author
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, is permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
.
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -572,6 +492,49 @@ License: BSD-3-clause
|
|||||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
License: BSD-2-clause-NetBSD
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
.
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
License: BSD-2-clause-author
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
.
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
License: BSD-2-clause
|
License: BSD-2-clause
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
SUBDIRS = include man src test
|
SUBDIRS = \
|
||||||
|
include \
|
||||||
|
man \
|
||||||
|
src \
|
||||||
|
test \
|
||||||
|
# EOL
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
autogen \
|
autogen \
|
||||||
get-version \
|
get-version \
|
||||||
$(nil)
|
# EOL
|
||||||
|
|
||||||
dist-hook:
|
dist-hook:
|
||||||
echo $(VERSION) >$(distdir)/.dist-version
|
echo $(VERSION) >$(distdir)/.dist-version
|
||||||
|
44
README
44
README
@ -5,6 +5,10 @@ and lacking on others like GNU systems, thus making it easier to port
|
|||||||
projects with strong BSD origins, without needing to embed the same
|
projects with strong BSD origins, without needing to embed the same
|
||||||
code over and over again on each project.
|
code over and over again on each project.
|
||||||
|
|
||||||
|
A BSD compatible message-digest library is required, on systems where
|
||||||
|
this is not provided by its libc or libmd libraries, the canonical
|
||||||
|
implementation to use is <https://www.hadrons.org/software/libmd/>.
|
||||||
|
|
||||||
|
|
||||||
Releases
|
Releases
|
||||||
--------
|
--------
|
||||||
@ -27,10 +31,44 @@ The mail address is:
|
|||||||
Source Repository
|
Source Repository
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
The master repository can be browsed at:
|
The primary repository can be browsed at:
|
||||||
|
|
||||||
<https://cgit.freedesktop.org/libbsd>
|
<https://gitlab.freedesktop.org/libbsd/libbsd>
|
||||||
|
|
||||||
and cloned from:
|
and cloned from:
|
||||||
|
|
||||||
<https://anongit.freedesktop.org/git/libbsd>
|
<https://gitlab.freedesktop.org/libbsd/libbsd.git>
|
||||||
|
|
||||||
|
|
||||||
|
Building from git source
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
To prepare the libbsd source tree from git before starting the build process
|
||||||
|
some required software needs to be installed:
|
||||||
|
|
||||||
|
GNU autoconf >= 2.67
|
||||||
|
GNU automake >= 1.9
|
||||||
|
GNU libtool >= 2.0
|
||||||
|
|
||||||
|
After installing the needed software, and running the following command on
|
||||||
|
the git tree:
|
||||||
|
|
||||||
|
$ ./autogen
|
||||||
|
|
||||||
|
the source should be roughly equivalent to the distributed tar source.
|
||||||
|
|
||||||
|
|
||||||
|
Building from tar source
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
The minimum software required to configure and build dpkg from a tarball is:
|
||||||
|
|
||||||
|
C89 compiler
|
||||||
|
make
|
||||||
|
|
||||||
|
The following software might be required depending on the system:
|
||||||
|
|
||||||
|
libmd (whenever the libc does not provide the needed digest functions)
|
||||||
|
|
||||||
|
The build process is done by running the usual «./configure; make». To
|
||||||
|
see all available configuration options please run «./configure --help».
|
||||||
|
2
TODO
2
TODO
@ -1,3 +1,4 @@
|
|||||||
|
* Migrate portable functions from GNU/kFreeBSD's libfreebsd.
|
||||||
* Add more functions used by ported packages (check openssh).
|
* Add more functions used by ported packages (check openssh).
|
||||||
* Add more unit tests.
|
* Add more unit tests.
|
||||||
* Add missing man pages.
|
* Add missing man pages.
|
||||||
@ -5,7 +6,6 @@
|
|||||||
- timeconv?
|
- timeconv?
|
||||||
* Add a README.import file.
|
* Add a README.import file.
|
||||||
* Update man pages:
|
* Update man pages:
|
||||||
- Fix references to a.out(5) and inline needed struct definitions.
|
|
||||||
- Document when each interface was added on every BSD, and libbsd.
|
- Document when each interface was added on every BSD, and libbsd.
|
||||||
* Handle LFS properly. By default the library emits LFS objects, but might
|
* Handle LFS properly. By default the library emits LFS objects, but might
|
||||||
be used by non-LFS objects. We should either provide foo and foo64
|
be used by non-LFS objects. We should either provide foo and foo64
|
||||||
|
661
configure.ac
661
configure.ac
@ -6,17 +6,22 @@ AC_CONFIG_SRCDIR([src/strlcpy.c])
|
|||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([1.9 foreign nostdinc subdir-objects no-dist-gzip dist-xz])
|
AM_INIT_AUTOMAKE(
|
||||||
|
[1.11]
|
||||||
|
[-Wall]
|
||||||
|
[foreign]
|
||||||
|
[nostdinc]
|
||||||
|
[subdir-objects]
|
||||||
|
[no-dist-gzip dist-xz]
|
||||||
|
)
|
||||||
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
SOVERSION_MAJOR=0
|
||||||
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
SOVERSION_MINOR=12
|
||||||
|
SOVERSION_PATCH=2
|
||||||
|
|
||||||
LIBBSD_ABI_MAJOR=0
|
SOVERSION="$SOVERSION_MAJOR:$SOVERSION_MINOR:$SOVERSION_PATCH"
|
||||||
LIBBSD_ABI_MINOR=8
|
AC_SUBST([SOVERSION])
|
||||||
LIBBSD_ABI_PATCH=7
|
|
||||||
|
|
||||||
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
|
||||||
AC_SUBST([LIBBSD_ABI])
|
|
||||||
|
|
||||||
# Check and store if we got user supplied variables
|
# Check and store if we got user supplied variables
|
||||||
user_CFLAGS=${CFLAGS-unset}
|
user_CFLAGS=${CFLAGS-unset}
|
||||||
@ -24,42 +29,480 @@ user_CFLAGS=${CFLAGS-unset}
|
|||||||
# Checks for operating system services and capabilities.
|
# Checks for operating system services and capabilities.
|
||||||
AC_USE_SYSTEM_EXTENSIONS
|
AC_USE_SYSTEM_EXTENSIONS
|
||||||
AC_SYS_LARGEFILE
|
AC_SYS_LARGEFILE
|
||||||
|
LIBBSD_SYS_TIME64
|
||||||
|
|
||||||
|
AM_PROG_AR
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
LIBBSD_LINKER_VERSION_SCRIPT
|
||||||
|
|
||||||
|
## Select library ABI to expose.
|
||||||
|
#
|
||||||
|
# The systems have DROP comments for interfaces that could be dropped on
|
||||||
|
# the next SOVERSION bump.
|
||||||
|
|
||||||
|
is_windows=no
|
||||||
|
|
||||||
|
api_time_macros=unknown
|
||||||
|
|
||||||
|
abi_accmode=unknown
|
||||||
|
abi_arc4random=unknown
|
||||||
|
abi_arc4random_stir=unknown
|
||||||
|
abi_asprintf=unknown
|
||||||
|
abi_bsd_getopt=unknown
|
||||||
|
abi_closefrom=unknown
|
||||||
|
abi_err=unknown
|
||||||
|
abi_errc=unknown
|
||||||
|
abi_expand_number=unknown
|
||||||
|
abi_explicit_bzero=unknown
|
||||||
|
abi_fgetln=unknown
|
||||||
|
abi_flopen=unknown
|
||||||
|
abi_fmtcheck=unknown
|
||||||
|
abi_fpurge=unknown
|
||||||
|
abi_freezero=unknown
|
||||||
|
abi_funopen=unknown
|
||||||
|
abi_getbsize=unknown
|
||||||
|
abi_getpeereid=unknown
|
||||||
|
abi_humanize_number=unknown
|
||||||
|
abi_id_from_name=unknown
|
||||||
|
abi_inet_net_pton=unknown
|
||||||
|
abi_md5=unknown
|
||||||
|
abi_name_from_id=unknown
|
||||||
|
abi_nlist=unknown
|
||||||
|
abi_pidfile=unknown
|
||||||
|
abi_proctitle=unknown
|
||||||
|
abi_progname=unknown
|
||||||
|
abi_readpassphrase=unknown
|
||||||
|
abi_reallocarray=unknown
|
||||||
|
abi_reallocf=unknown
|
||||||
|
abi_recallocarray=unknown
|
||||||
|
abi_stringlist=unknown
|
||||||
|
abi_sort=unknown
|
||||||
|
abi_strl=unknown
|
||||||
|
abi_strmode=unknown
|
||||||
|
abi_strnstr=unknown
|
||||||
|
abi_strtonum=unknown
|
||||||
|
abi_strtox=unknown
|
||||||
|
abi_timeconv=unknown
|
||||||
|
abi_vis=unknown
|
||||||
|
abi_wcsl=unknown
|
||||||
|
|
||||||
|
AS_CASE([$host_os],
|
||||||
|
[*-gnu* | gnu*], [
|
||||||
|
api_time_macros=no
|
||||||
|
|
||||||
|
abi_accmode=yes
|
||||||
|
# DROP: On glibc >= 2.36.
|
||||||
|
#abi_arc4random=no
|
||||||
|
abi_arc4random=yes
|
||||||
|
abi_arc4random_stir=yes
|
||||||
|
abi_asprintf=no
|
||||||
|
abi_bsd_getopt=yes
|
||||||
|
# DROP: On glibc >= 2.34.
|
||||||
|
#abi_closefrom=no
|
||||||
|
abi_closefrom=yes
|
||||||
|
abi_err=no
|
||||||
|
abi_errc=yes
|
||||||
|
abi_expand_number=yes
|
||||||
|
# DROP: On glibc >= 2.25.
|
||||||
|
#abi_explicit_bzero=no
|
||||||
|
abi_explicit_bzero=yes
|
||||||
|
abi_fgetln=yes
|
||||||
|
abi_flopen=yes
|
||||||
|
abi_fmtcheck=yes
|
||||||
|
abi_fpurge=yes
|
||||||
|
abi_freezero=yes
|
||||||
|
abi_funopen=yes
|
||||||
|
abi_getbsize=yes
|
||||||
|
abi_getpeereid=yes
|
||||||
|
abi_humanize_number=yes
|
||||||
|
abi_id_from_name=yes
|
||||||
|
# DROP: On glibc.
|
||||||
|
#abi_inet_net_pton=no
|
||||||
|
abi_inet_net_pton=yes
|
||||||
|
# DROP: On libmd.
|
||||||
|
#abi_md5=no
|
||||||
|
abi_md5=yes
|
||||||
|
abi_name_from_id=yes
|
||||||
|
abi_nlist=yes
|
||||||
|
abi_pidfile=yes
|
||||||
|
abi_proctitle=yes
|
||||||
|
abi_progname=yes
|
||||||
|
abi_readpassphrase=yes
|
||||||
|
# DROP: On glibc >= 2.26.
|
||||||
|
#abi_reallocarray=no
|
||||||
|
abi_reallocarray=yes
|
||||||
|
abi_reallocf=yes
|
||||||
|
abi_recallocarray=yes
|
||||||
|
abi_stringlist=yes
|
||||||
|
abi_sort=yes
|
||||||
|
# DROP: On glibc >= 2.38.
|
||||||
|
#abi_strl=no
|
||||||
|
abi_strl=yes
|
||||||
|
abi_strmode=yes
|
||||||
|
abi_strnstr=yes
|
||||||
|
abi_strtonum=yes
|
||||||
|
abi_strtox=yes
|
||||||
|
abi_timeconv=yes
|
||||||
|
# DROP: On libmd.
|
||||||
|
abi_transparent_libmd=yes
|
||||||
|
abi_vis=yes
|
||||||
|
abi_wcsl=yes
|
||||||
|
],
|
||||||
|
[*-musl*], [
|
||||||
|
api_time_macros=no
|
||||||
|
|
||||||
|
abi_accmode=yes
|
||||||
|
abi_arc4random=yes
|
||||||
|
abi_arc4random_stir=yes
|
||||||
|
abi_asprintf=no
|
||||||
|
# DROP: On musl >= 0.9.7, optreset got implemented.
|
||||||
|
#abi_bsd_getopt=no
|
||||||
|
abi_bsd_getopt=yes
|
||||||
|
abi_closefrom=yes
|
||||||
|
abi_err=no
|
||||||
|
abi_errc=yes
|
||||||
|
abi_expand_number=yes
|
||||||
|
# DROP: On musl >= 1.1.20.
|
||||||
|
#abi_explicit_bzero=no
|
||||||
|
abi_explicit_bzero=yes
|
||||||
|
# DROP: On musl >= 0.9.4.
|
||||||
|
#abi_fgetln=no
|
||||||
|
abi_fgetln=yes
|
||||||
|
abi_flopen=yes
|
||||||
|
abi_fmtcheck=yes
|
||||||
|
abi_fpurge=yes
|
||||||
|
abi_freezero=yes
|
||||||
|
# On musl >= 1.1.19, fopencookie() got implemented, and because we were
|
||||||
|
# checking for its presence to decide whether to build funopen(), it got
|
||||||
|
# included in builds even when previously it had not been included, which
|
||||||
|
# is partially an ABI issue, but given that disabling it now would be
|
||||||
|
# worse, we'll ignore this as this is only a problem with downgrades. And
|
||||||
|
# enable it explicitly
|
||||||
|
#abi_funopen=no
|
||||||
|
abi_funopen=yes
|
||||||
|
abi_getbsize=yes
|
||||||
|
abi_getpeereid=yes
|
||||||
|
abi_humanize_number=yes
|
||||||
|
abi_id_from_name=yes
|
||||||
|
abi_inet_net_pton=yes
|
||||||
|
# DROP: On libmd.
|
||||||
|
#abi_md5=no
|
||||||
|
abi_md5=yes
|
||||||
|
abi_name_from_id=yes
|
||||||
|
abi_nlist=yes
|
||||||
|
abi_pidfile=yes
|
||||||
|
abi_proctitle=yes
|
||||||
|
abi_progname=yes
|
||||||
|
abi_readpassphrase=yes
|
||||||
|
# DROP: On musl >= 1.2.2.
|
||||||
|
#abi_reallocarray=no
|
||||||
|
abi_reallocarray=yes
|
||||||
|
abi_reallocf=ues
|
||||||
|
abi_recallocarray=yes
|
||||||
|
abi_stringlist=yes
|
||||||
|
abi_sort=yes
|
||||||
|
# DROP: On musl >= 0.5.0, strlcpy() and strlcat() were already implemented.
|
||||||
|
#abi_strl=no
|
||||||
|
abi_strl=yes
|
||||||
|
abi_strmode=yes
|
||||||
|
abi_strnstr=yes
|
||||||
|
abi_strtonum=yes
|
||||||
|
abi_strtox=yes
|
||||||
|
abi_timeconv=yes
|
||||||
|
# DROP: On libmd.
|
||||||
|
abi_transparent_libmd=yes
|
||||||
|
abi_vis=yes
|
||||||
|
abi_wcsl=yes
|
||||||
|
],
|
||||||
|
[darwin*], [
|
||||||
|
api_time_macros=no
|
||||||
|
|
||||||
|
abi_accmode=no
|
||||||
|
abi_arc4random=no
|
||||||
|
abi_arc4random_stir=no
|
||||||
|
abi_asprintf=no
|
||||||
|
abi_bsd_getopt=no
|
||||||
|
abi_closefrom=yes
|
||||||
|
abi_err=no
|
||||||
|
abi_errc=no
|
||||||
|
abi_expand_number=yes
|
||||||
|
abi_explicit_bzero=yes
|
||||||
|
abi_fgetln=no
|
||||||
|
abi_flopen=yes
|
||||||
|
abi_fmtcheck=no
|
||||||
|
abi_fpurge=no
|
||||||
|
abi_freezero=yes
|
||||||
|
abi_funopen=no
|
||||||
|
abi_getbsize=yes
|
||||||
|
abi_getpeereid=no
|
||||||
|
abi_humanize_number=yes
|
||||||
|
abi_id_from_name=yes
|
||||||
|
abi_inet_net_pton=no
|
||||||
|
# On libmd.
|
||||||
|
abi_md5=no
|
||||||
|
abi_name_from_id=no
|
||||||
|
abi_nlist=no
|
||||||
|
abi_pidfile=yes
|
||||||
|
abi_proctitle=yes
|
||||||
|
abi_progname=no
|
||||||
|
abi_readpassphrase=no
|
||||||
|
abi_reallocarray=yes
|
||||||
|
abi_reallocf=no
|
||||||
|
abi_recallocarray=yes
|
||||||
|
abi_stringlist=no
|
||||||
|
abi_sort=no
|
||||||
|
abi_strl=no
|
||||||
|
abi_strmode=no
|
||||||
|
abi_strnstr=no
|
||||||
|
abi_strtonum=no
|
||||||
|
abi_strtox=yes
|
||||||
|
abi_timeconv=no
|
||||||
|
# On libmd.
|
||||||
|
abi_transparent_libmd=no
|
||||||
|
abi_vis=no
|
||||||
|
abi_wcsl=no
|
||||||
|
],
|
||||||
|
[solaris2*], [
|
||||||
|
api_time_macros=yes
|
||||||
|
|
||||||
|
abi_accmode=yes
|
||||||
|
abi_arc4random=no
|
||||||
|
abi_arc4random_stir=no
|
||||||
|
abi_asprintf=no
|
||||||
|
abi_bsd_getopt=yes
|
||||||
|
abi_closefrom=no
|
||||||
|
abi_err=no
|
||||||
|
abi_errc=yes
|
||||||
|
abi_expand_number=yes
|
||||||
|
abi_explicit_bzero=yes
|
||||||
|
abi_fgetln=yes
|
||||||
|
abi_flopen=yes
|
||||||
|
abi_fmtcheck=no
|
||||||
|
abi_fpurge=yes
|
||||||
|
abi_freezero=yes
|
||||||
|
abi_funopen=no
|
||||||
|
abi_getbsize=yes
|
||||||
|
abi_getpeereid=yes
|
||||||
|
abi_humanize_number=yes
|
||||||
|
abi_id_from_name=yes
|
||||||
|
abi_inet_net_pton=yes
|
||||||
|
# On libmd.
|
||||||
|
abi_md5=no
|
||||||
|
abi_name_from_id=yes
|
||||||
|
abi_nlist=no
|
||||||
|
abi_pidfile=yes
|
||||||
|
abi_proctitle=yes
|
||||||
|
abi_progname=no
|
||||||
|
abi_readpassphrase=yes
|
||||||
|
abi_reallocarray=yes
|
||||||
|
abi_reallocf=no
|
||||||
|
abi_recallocarray=yes
|
||||||
|
abi_stringlist=yes
|
||||||
|
abi_sort=yes
|
||||||
|
abi_strl=no
|
||||||
|
abi_strmode=yes
|
||||||
|
abi_strnstr=no
|
||||||
|
abi_strtonum=no
|
||||||
|
abi_strtox=yes
|
||||||
|
abi_timeconv=yes
|
||||||
|
# On libmd.
|
||||||
|
abi_transparent_libmd=no
|
||||||
|
abi_vis=yes
|
||||||
|
abi_wcsl=yes
|
||||||
|
],
|
||||||
|
[aix*], [
|
||||||
|
api_time_macros=yes
|
||||||
|
|
||||||
|
abi_accmode=yes
|
||||||
|
abi_arc4random=yes
|
||||||
|
abi_arc4random_stir=yes
|
||||||
|
abi_asprintf=yes
|
||||||
|
abi_bsd_getopt=yes
|
||||||
|
abi_closefrom=yes
|
||||||
|
abi_err=yes
|
||||||
|
abi_errc=yes
|
||||||
|
abi_expand_number=yes
|
||||||
|
abi_explicit_bzero=yes
|
||||||
|
abi_fgetln=yes
|
||||||
|
abi_flopen=yes
|
||||||
|
abi_fmtcheck=yes
|
||||||
|
abi_fpurge=no
|
||||||
|
abi_freezero=yes
|
||||||
|
abi_funopen=no
|
||||||
|
abi_getbsize=yes
|
||||||
|
abi_getpeereid=yes
|
||||||
|
abi_humanize_number=yes
|
||||||
|
abi_id_from_name=yes
|
||||||
|
abi_inet_net_pton=no
|
||||||
|
# On libmd.
|
||||||
|
abi_md5=no
|
||||||
|
abi_name_from_id=yes
|
||||||
|
abi_nlist=no
|
||||||
|
abi_pidfile=yes
|
||||||
|
abi_proctitle=yes
|
||||||
|
abi_progname=yes
|
||||||
|
abi_readpassphrase=yes
|
||||||
|
abi_reallocarray=yes
|
||||||
|
abi_reallocf=yes
|
||||||
|
abi_recallocarray=yes
|
||||||
|
abi_stringlist=yes
|
||||||
|
abi_sort=yes
|
||||||
|
abi_strl=yes
|
||||||
|
abi_strmode=yes
|
||||||
|
abi_strnstr=yes
|
||||||
|
abi_strtonum=yes
|
||||||
|
abi_strtox=yes
|
||||||
|
abi_timeconv=yes
|
||||||
|
# On libmd.
|
||||||
|
abi_transparent_libmd=no
|
||||||
|
abi_vis=yes
|
||||||
|
abi_wcsl=yes
|
||||||
|
],
|
||||||
|
[mingw*], [
|
||||||
|
is_windows=yes
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Handle artificial ABI selections that are combinations of others.
|
||||||
|
AS_IF([test "$abi_name_from_id" = "yes" || test "$abi_id_from_name" = "yes"], [
|
||||||
|
abi_pwcache=yes
|
||||||
|
], [
|
||||||
|
abi_pwcache=no
|
||||||
|
])
|
||||||
|
AS_IF([test "$abi_err" = "yes" || test "$abi_errc" = "yes"], [
|
||||||
|
abi_err_h=yes
|
||||||
|
], [
|
||||||
|
abi_err_h=no
|
||||||
|
])
|
||||||
|
|
||||||
|
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
|
||||||
|
|
||||||
# Checks for programs.
|
# Checks for programs.
|
||||||
|
AC_CHECK_TOOL([OBJDUMP], [objdump])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
AC_PROG_SED
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
AC_PROG_LN_S
|
AC_PROG_LN_S
|
||||||
|
|
||||||
# Set default compiler variables
|
# Set default compiler variables
|
||||||
if test "$user_CFLAGS" = unset && test "$GCC" = yes; then
|
AS_IF([test "$user_CFLAGS" = unset], [
|
||||||
CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter"
|
LIBBSD_CHECK_COMPILER_FLAG([-Wall])
|
||||||
fi
|
LIBBSD_CHECK_COMPILER_FLAG([-Wextra])
|
||||||
|
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wbad-function-cast])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wc99-c11-compat])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wcast-align])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wdeclaration-after-statement])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wdocumentation])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wduplicated-branches])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wduplicated-cond])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wformat -Wformat-security])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wformat=2])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Winit-self])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wlogical-not-parentheses])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wlogical-op])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-declarations])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-format-attribute])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-prototypes])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wnested-externs])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wno-missing-field-initializers])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wno-nonnull-compare])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wno-tautological-constant-out-of-range-compare])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wno-unused-parameter])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wnull-dereference])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wold-style-definition])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wpointer-arith])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wregister])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wrestrict])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wshadow])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wshift-negative-value])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wsizeof-array-argument])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wstrict-prototypes])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wswitch-bool])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wvla])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings])
|
||||||
|
|
||||||
|
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||||
|
|
||||||
|
AC_ARG_ENABLE([sanitize],
|
||||||
|
[AS_HELP_STRING([--enable-sanitize], [enable compiler sanitizer support])],
|
||||||
|
[
|
||||||
|
LIBBSD_COMPILER_FLAGS=''
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=address])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=leak])
|
||||||
|
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=undefined])
|
||||||
|
|
||||||
|
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||||
|
LDFLAGS="$LDFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
|
AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
|
||||||
[TESTU01_LIBS="-ltestu01"])
|
[TESTU01_LIBS="-ltestu01"])
|
||||||
AC_SUBST([TESTU01_LIBS])
|
AC_SUBST([TESTU01_LIBS])
|
||||||
AM_CONDITIONAL([HAVE_LIBTESTU01],
|
AM_CONDITIONAL([HAVE_LIBTESTU01],
|
||||||
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
|
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
|
||||||
|
|
||||||
|
saved_LIBS="$LIBS"
|
||||||
|
AS_IF([test "$abi_md5" = "yes"], [
|
||||||
|
AC_SEARCH_LIBS([MD5Update], [md], [
|
||||||
|
AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
|
||||||
|
MD5_LIBS="$MD5_LIBS $ac_cv_search_MD5Update"
|
||||||
|
abi_transparent_libmd=yes
|
||||||
|
])
|
||||||
|
], [
|
||||||
|
AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
AS_IF([test "$abi_arc4random" = "yes"], [
|
||||||
|
AC_CHECK_FUNCS([getentropy])
|
||||||
|
|
||||||
|
AS_IF([test "$ac_cv_func_getentropy" != "yes"], [
|
||||||
|
AC_SEARCH_LIBS([SHA512Update], [md], [
|
||||||
|
AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
|
||||||
|
LIBBSD_LIBS="$SHA512_LIBS $ac_cv_search_SHA512Update"
|
||||||
|
])
|
||||||
|
], [
|
||||||
|
AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
LIBS="$saved_LIBS"
|
||||||
|
|
||||||
AS_CASE([$host_os],
|
AS_CASE([$host_os],
|
||||||
[*-gnu*], [
|
[*-gnu*], [
|
||||||
# In old glibc versions (< 2.17) clock_gettime() is in librt.
|
# In old glibc versions (< 2.17) clock_gettime() is in librt.
|
||||||
saved_LIBS="$LIBS"
|
saved_LIBS="$LIBS"
|
||||||
AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"])
|
AC_SEARCH_LIBS([clock_gettime], [rt], [
|
||||||
AC_SUBST([CLOCK_GETTIME_LIBS])
|
AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
|
||||||
|
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_clock_gettime"
|
||||||
|
])
|
||||||
|
])
|
||||||
LIBS="$saved_LIBS"
|
LIBS="$saved_LIBS"
|
||||||
],
|
],
|
||||||
[*-musl*], [
|
[aix*], [
|
||||||
# Upstream refuses to define this, we will do it ourselves then.
|
saved_LIBS="$LIBS"
|
||||||
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
|
AC_SEARCH_LIBS([perfstat_cpu_total], [perfstat], [
|
||||||
|
AS_IF([test "x$ac_cv_search_perfstat_cpu_total" != "xnone required"], [
|
||||||
|
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_perfstat_cpu_total"
|
||||||
|
])
|
||||||
|
])
|
||||||
|
LIBS="$saved_LIBS"
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h])
|
AC_CHECK_HEADERS([\
|
||||||
|
sys/ndir.h \
|
||||||
|
sys/dir.h \
|
||||||
|
ndir.h \
|
||||||
|
dirent.h \
|
||||||
|
pwd.h \
|
||||||
|
grp.h \
|
||||||
|
stdio_ext.h \
|
||||||
|
procinfo.h \
|
||||||
|
])
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_C_INLINE
|
AC_C_INLINE
|
||||||
@ -72,89 +515,115 @@ AC_TYPE_UID_T
|
|||||||
AC_TYPE_SIZE_T
|
AC_TYPE_SIZE_T
|
||||||
AC_TYPE_SSIZE_T
|
AC_TYPE_SSIZE_T
|
||||||
|
|
||||||
AC_CHECK_DECL([F_CLOSEM],
|
AC_CHECK_DECL([F_CLOSEM], [
|
||||||
[AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
||||||
[Define to 1 if you have fcntl(F_CLOSEM)])],
|
[Define to 1 if you have fcntl(F_CLOSEM)])
|
||||||
[],
|
], [], [[
|
||||||
[#include <limits.h>
|
#include <limits.h>
|
||||||
#include <fcntl.h>])
|
#include <fcntl.h>
|
||||||
|
]])
|
||||||
|
|
||||||
AC_CACHE_CHECK(
|
AC_CHECK_DECLS([environ], [], [], [[
|
||||||
[for GNU .init_array section support],
|
#include <unistd.h>
|
||||||
[libbsd_cv_gnu_init_array_support],
|
]])
|
||||||
[AC_RUN_IFELSE(
|
|
||||||
[AC_LANG_SOURCE(
|
LIBBSD_HAS_GNU_INIT_ARRAY
|
||||||
[[
|
|
||||||
static int rc = 1;
|
|
||||||
static void init(int argc) { if (argc == 1) rc = 0; }
|
|
||||||
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
|
|
||||||
int main() { return rc; }
|
|
||||||
]]
|
|
||||||
)],
|
|
||||||
[libbsd_cv_gnu_init_array_support=yes],
|
|
||||||
[libbsd_cv_gnu_init_array_support=no],
|
|
||||||
[AC_PREPROC_IFELSE(
|
|
||||||
[AC_LANG_SOURCE(
|
|
||||||
[[
|
|
||||||
/* Look for a known libc that supports .init_array with the GNU extension
|
|
||||||
* to pass main() arguments to the init functions. */
|
|
||||||
#include <stdlib.h>
|
|
||||||
#if defined __GLIBC_PREREQ
|
|
||||||
# if __GLIBC_PREREQ(2, 4)
|
|
||||||
/* glibc supports GNU .init_array since 2.4. */
|
|
||||||
# else
|
|
||||||
# error glibc does not support GNU .init_array
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
|
||||||
* - Bionic since its inception.
|
|
||||||
* - uClibc since 0.9.29.
|
|
||||||
*/
|
|
||||||
# error unknown whether libc supports GNU .init_array
|
|
||||||
#endif
|
|
||||||
]]
|
|
||||||
)],
|
|
||||||
[libbsd_cv_gnu_init_array_support=yes],
|
|
||||||
[libbsd_cv_gnu_init_array_support=no])
|
|
||||||
]
|
|
||||||
)]
|
|
||||||
)
|
|
||||||
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
|
|
||||||
[test "$libbsd_cv_gnu_init_array_support" = yes])
|
|
||||||
|
|
||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
AC_MSG_CHECKING([for program_invocation_short_name])
|
LIBBSD_CHECK_PROGNAME
|
||||||
AC_LINK_IFELSE(
|
LIBBSD_CHECK_REGISTER_ATFORK
|
||||||
[AC_LANG_PROGRAM([[#include <errno.h>]],
|
|
||||||
[[const char *p = program_invocation_short_name;]])],
|
|
||||||
[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
|
||||||
[Define to 1 if you have program_invocation_short_name])
|
|
||||||
AC_MSG_RESULT([yes])],
|
|
||||||
[AC_MSG_RESULT([no])])
|
|
||||||
|
|
||||||
AC_MSG_CHECKING([for __progname])
|
AC_CHECK_FUNCS([\
|
||||||
AC_LINK_IFELSE(
|
vasprintf \
|
||||||
[AC_LANG_PROGRAM([[extern char *__progname;]],
|
asprintf \
|
||||||
[[printf("%s", __progname);]])],
|
clearenv \
|
||||||
[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
dirfd \
|
||||||
AC_MSG_RESULT([yes])],
|
flock \
|
||||||
[AC_MSG_RESULT([no])])
|
fopencookie \
|
||||||
|
__fpurge \
|
||||||
|
funopen \
|
||||||
|
getauxval \
|
||||||
|
getentropy \
|
||||||
|
getexecname \
|
||||||
|
getline \
|
||||||
|
open_memstream \
|
||||||
|
pstat_getproc \
|
||||||
|
sysconf \
|
||||||
|
uid_from_user \
|
||||||
|
gid_from_group \
|
||||||
|
user_from_uid \
|
||||||
|
group_from_gid \
|
||||||
|
])
|
||||||
|
|
||||||
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
|
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
|
||||||
getauxval getentropy getexecname getline \
|
|
||||||
pstat_getproc sysconf])
|
# API selection
|
||||||
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
|
LIBBSD_SELECT_API([time_macros], [time struct conversion macros])
|
||||||
|
|
||||||
|
# ABI selection
|
||||||
|
LIBBSD_SELECT_ABI([accmode], [setmode()/getmode()])
|
||||||
|
LIBBSD_SELECT_ABI([arc4random], [arc4random() API])
|
||||||
|
LIBBSD_SELECT_ABI([arc4random_stir], [arc4random_stir()/arc4random_addrandom()])
|
||||||
|
LIBBSD_SELECT_ABI([asprintf], [vasprintf()/asprintf()])
|
||||||
|
LIBBSD_SELECT_ABI([bsd_getopt], [BSD getopt()])
|
||||||
|
LIBBSD_SELECT_ABI([closefrom], [closefrom()])
|
||||||
|
LIBBSD_SELECT_ABI([err_h], [err.h header])
|
||||||
|
LIBBSD_SELECT_ABI([err], [err API])
|
||||||
|
LIBBSD_SELECT_ABI([errc], [errc API])
|
||||||
|
LIBBSD_SELECT_ABI([expand_number], [expand_number()])
|
||||||
|
LIBBSD_SELECT_ABI([explicit_bzero], [explicit_bzero()])
|
||||||
|
LIBBSD_SELECT_ABI([fgetln], [fgetln/fgetwln()])
|
||||||
|
LIBBSD_SELECT_ABI([flopen], [flopen()/flopenat()])
|
||||||
|
LIBBSD_SELECT_ABI([fmtcheck], [fmtcheck()])
|
||||||
|
LIBBSD_SELECT_ABI([fpurge], [fpurge()])
|
||||||
|
LIBBSD_SELECT_ABI([freezero], [freezero()])
|
||||||
|
LIBBSD_SELECT_ABI([funopen], [funopen()])
|
||||||
|
LIBBSD_SELECT_ABI([getbsize], [getbsize()])
|
||||||
|
LIBBSD_SELECT_ABI([getpeereid], [getpeereid()])
|
||||||
|
LIBBSD_SELECT_ABI([humanize_number], [humanize_number()/dehumanize_number()])
|
||||||
|
LIBBSD_SELECT_ABI([id_from_name], [uid_from_user()/gid_from_user()])
|
||||||
|
LIBBSD_SELECT_ABI([inet_net_pton], [inet_net_pton()])
|
||||||
|
LIBBSD_SELECT_ABI([md5], [MD5 digest functions])
|
||||||
|
LIBBSD_SELECT_ABI([name_from_id], [user_from_uid()/group_from_gid()])
|
||||||
|
LIBBSD_SELECT_ABI([nlist], [nlist()])
|
||||||
|
LIBBSD_SELECT_ABI([pidfile], [pidfile API])
|
||||||
|
LIBBSD_SELECT_ABI([proctitle], [setproctitle() API])
|
||||||
|
LIBBSD_SELECT_ABI([progname], [setprogname()/getprogname()])
|
||||||
|
LIBBSD_SELECT_ABI([pwcache], [password cache API])
|
||||||
|
LIBBSD_SELECT_ABI([readpassphrase], [readpassphrase()])
|
||||||
|
LIBBSD_SELECT_ABI([reallocarray], [reallocarray()])
|
||||||
|
LIBBSD_SELECT_ABI([reallocf], [reallocf()])
|
||||||
|
LIBBSD_SELECT_ABI([recallocarray], [recallocarray()])
|
||||||
|
LIBBSD_SELECT_ABI([stringlist], [stringlist sl_*() API])
|
||||||
|
LIBBSD_SELECT_ABI([sort], [BSD sort functions])
|
||||||
|
LIBBSD_SELECT_ABI([strl], [strlcpy()/strlcat()])
|
||||||
|
LIBBSD_SELECT_ABI([strmode], [strmode()])
|
||||||
|
LIBBSD_SELECT_ABI([strnstr], [strnstr()])
|
||||||
|
LIBBSD_SELECT_ABI([strtonum], [strtonum()])
|
||||||
|
LIBBSD_SELECT_ABI([strtox], [strtoi()/strtou()])
|
||||||
|
LIBBSD_SELECT_ABI([timeconv], [timeconv.h API])
|
||||||
|
LIBBSD_SELECT_ABI([transparent_libmd], [transparent libmd support])
|
||||||
|
LIBBSD_SELECT_ABI([vis], [vis API])
|
||||||
|
LIBBSD_SELECT_ABI([wcsl], [wcslcpy()/wcslcat()])
|
||||||
|
|
||||||
|
AS_IF([test "x$abi_funopen" = "xno" && \
|
||||||
|
test "x$ac_cv_func_funopen" != "xyes" && \
|
||||||
|
test "x$ac_cv_func_fopencookie" = "xyes"], [
|
||||||
|
AC_MSG_WARN([[can implement funopen() now based on newly added fopencooke(), report upstream]])
|
||||||
|
])
|
||||||
|
|
||||||
|
AC_SUBST([MD5_LIBS])
|
||||||
|
AC_SUBST([LIBBSD_LIBS])
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
include/Makefile
|
include/Makefile
|
||||||
man/Makefile
|
man/Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
src/libbsd.pc
|
src/libbsd.pc
|
||||||
src/libbsd-ctor.pc
|
src/libbsd-ctor.pc
|
||||||
src/libbsd-overlay.pc
|
src/libbsd-overlay.pc
|
||||||
test/Makefile
|
test/Makefile
|
||||||
])
|
])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
@ -4,6 +4,7 @@ nobase_include_HEADERS = \
|
|||||||
bsd/sys/bitstring.h \
|
bsd/sys/bitstring.h \
|
||||||
bsd/sys/cdefs.h \
|
bsd/sys/cdefs.h \
|
||||||
bsd/sys/endian.h \
|
bsd/sys/endian.h \
|
||||||
|
bsd/sys/param.h \
|
||||||
bsd/sys/poll.h \
|
bsd/sys/poll.h \
|
||||||
bsd/sys/queue.h \
|
bsd/sys/queue.h \
|
||||||
bsd/sys/time.h \
|
bsd/sys/time.h \
|
||||||
@ -11,18 +12,77 @@ nobase_include_HEADERS = \
|
|||||||
bsd/netinet/ip_icmp.h \
|
bsd/netinet/ip_icmp.h \
|
||||||
bsd/bitstring.h \
|
bsd/bitstring.h \
|
||||||
bsd/bsd.h \
|
bsd/bsd.h \
|
||||||
bsd/err.h \
|
bsd/inttypes.h \
|
||||||
bsd/getopt.h \
|
|
||||||
bsd/libutil.h \
|
bsd/libutil.h \
|
||||||
bsd/md5.h \
|
|
||||||
bsd/nlist.h \
|
|
||||||
bsd/readpassphrase.h \
|
|
||||||
bsd/stdio.h \
|
bsd/stdio.h \
|
||||||
bsd/stdlib.h \
|
bsd/stdlib.h \
|
||||||
bsd/string.h \
|
bsd/string.h \
|
||||||
bsd/stringlist.h \
|
|
||||||
bsd/timeconv.h \
|
|
||||||
bsd/unistd.h \
|
bsd/unistd.h \
|
||||||
bsd/vis.h \
|
|
||||||
bsd/wchar.h \
|
bsd/wchar.h \
|
||||||
$(nil)
|
# EOL
|
||||||
|
|
||||||
|
if ABI_ERR_H
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/err.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_BSD_GETOPT
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/getopt.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_MD5
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/md5.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_NLIST
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/nlist.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_READPASSPHRASE
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/readpassphrase.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_PWCACHE
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/grp.h \
|
||||||
|
bsd/pwd.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRINGLIST
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/stringlist.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_TIMECONV
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/timeconv.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_VIS
|
||||||
|
nobase_include_HEADERS += \
|
||||||
|
bsd/vis.h \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
do_header_subst = $(AM_V_GEN) $(SED) \
|
||||||
|
-e 's:^//\(.define LIBBSD_SYS_TIME_BITS\).*:\1 $(LIBBSD_SYS_TIME_BITS):' \
|
||||||
|
-e 's:^//\(.define LIBBSD_SYS_HAS_TIME64\).*:\1 $(LIBBSD_SYS_HAS_TIME64):' \
|
||||||
|
# EOL
|
||||||
|
|
||||||
|
install-data-hook:
|
||||||
|
$(do_header_subst) <$(DESTDIR)$(includedir)/bsd/sys/cdefs.h \
|
||||||
|
>$(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new
|
||||||
|
mv $(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new \
|
||||||
|
$(DESTDIR)$(includedir)/bsd/sys/cdefs.h
|
||||||
|
@ -26,31 +26,56 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<err.h>)
|
||||||
#include_next <err.h>
|
#include_next <err.h>
|
||||||
#else
|
#else
|
||||||
|
#define LIBBSD_NEED_ERR_H_FUNCS
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<err.h>)
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#else
|
||||||
|
#define LIBBSD_NEED_ERR_H_FUNCS
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_ERR_H
|
#ifndef LIBBSD_ERR_H
|
||||||
#define LIBBSD_ERR_H
|
#define LIBBSD_ERR_H
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#else
|
|
||||||
#include <bsd/sys/cdefs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
void warnc(int code, const char *format, ...)
|
|
||||||
__printflike(2, 3);
|
|
||||||
void vwarnc(int code, const char *format, va_list ap)
|
void vwarnc(int code, const char *format, va_list ap)
|
||||||
__printflike(2, 0);
|
__printflike(2, 0);
|
||||||
void errc(int status, int code, const char *format, ...)
|
void warnc(int code, const char *format, ...)
|
||||||
__printflike(3, 4);
|
__printflike(2, 3);
|
||||||
|
|
||||||
void verrc(int status, int code, const char *format, va_list ap)
|
void verrc(int status, int code, const char *format, va_list ap)
|
||||||
__printflike(3, 0);
|
__printflike(3, 0) __dead2;
|
||||||
|
void errc(int status, int code, const char *format, ...)
|
||||||
|
__printflike(3, 4) __dead2;
|
||||||
|
|
||||||
|
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||||
|
void vwarn(const char *format, va_list ap)
|
||||||
|
__printflike(1, 0);
|
||||||
|
void vwarnx(const char *format, va_list ap)
|
||||||
|
__printflike(1, 0);
|
||||||
|
void warn(const char *format, ...)
|
||||||
|
__printflike(1, 2);
|
||||||
|
void warnx(const char *format, ...)
|
||||||
|
__printflike(1, 2);
|
||||||
|
|
||||||
|
void verr(int status, const char *format, va_list ap)
|
||||||
|
__printflike(2, 0) __dead2;
|
||||||
|
void verrx(int status, const char *format, va_list ap)
|
||||||
|
__printflike(2, 0) __dead2;
|
||||||
|
void err(int status, const char *format, ...)
|
||||||
|
__printflike(2, 3) __dead2;
|
||||||
|
void errx(int status, const char *format, ...)
|
||||||
|
__printflike(2, 3) __dead2;
|
||||||
|
#endif
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,9 +25,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<getopt.h>)
|
||||||
#include_next <getopt.h>
|
#include_next <getopt.h>
|
||||||
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<getopt.h>)
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#endif
|
||||||
#include <bsd/unistd.h>
|
#include <bsd/unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
53
include/bsd/grp.h
Normal file
53
include/bsd/grp.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<grp.h>)
|
||||||
|
#include_next <grp.h>
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<grp.h>)
|
||||||
|
#include <grp.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_GRP_H
|
||||||
|
#define LIBBSD_GRP_H
|
||||||
|
|
||||||
|
#define _GR_BUF_LEN (1024 + 200 * sizeof(char *))
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
int
|
||||||
|
gid_from_group(const char *, gid_t *);
|
||||||
|
#ifndef __APPLE__
|
||||||
|
const char *
|
||||||
|
group_from_gid(gid_t, int);
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
49
include/bsd/inttypes.h
Normal file
49
include/bsd/inttypes.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2018 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <inttypes.h>
|
||||||
|
#else
|
||||||
|
#include <inttypes.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_INTTYPES_H
|
||||||
|
#define LIBBSD_INTTYPES_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
intmax_t strtoi(const char *__restrict nptr, char **__restrict endptr,
|
||||||
|
int base, intmax_t lo, intmax_t hi, int *rstatus);
|
||||||
|
uintmax_t strtou(const char *__restrict nptr, char **__restrict endptr,
|
||||||
|
int base, uintmax_t lo, uintmax_t hi, int *rstatus);
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
@ -39,19 +39,16 @@
|
|||||||
#ifndef LIBBSD_LIBUTIL_H
|
#ifndef LIBBSD_LIBUTIL_H
|
||||||
#define LIBBSD_LIBUTIL_H
|
#define LIBBSD_LIBUTIL_H
|
||||||
|
|
||||||
#include <features.h>
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* for pidfile.c */
|
struct pidfh;
|
||||||
struct pidfh {
|
|
||||||
int pf_fd;
|
|
||||||
char *pf_path;
|
|
||||||
dev_t pf_dev;
|
|
||||||
ino_t pf_ino;
|
|
||||||
};
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
int humanize_number(char *buf, size_t len, int64_t bytes,
|
int humanize_number(char *buf, size_t len, int64_t bytes,
|
||||||
@ -59,8 +56,10 @@ int humanize_number(char *buf, size_t len, int64_t bytes,
|
|||||||
int expand_number(const char *_buf, uint64_t *_num);
|
int expand_number(const char *_buf, uint64_t *_num);
|
||||||
|
|
||||||
int flopen(const char *_path, int _flags, ...);
|
int flopen(const char *_path, int _flags, ...);
|
||||||
|
int flopenat(int dirfd, const char *path, int flags, ...);
|
||||||
|
|
||||||
struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
|
struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
|
||||||
|
int pidfile_fileno(const struct pidfh *pfh);
|
||||||
int pidfile_write(struct pidfh *pfh);
|
int pidfile_write(struct pidfh *pfh);
|
||||||
int pidfile_close(struct pidfh *pfh);
|
int pidfile_close(struct pidfh *pfh);
|
||||||
int pidfile_remove(struct pidfh *pfh);
|
int pidfile_remove(struct pidfh *pfh);
|
||||||
@ -68,14 +67,16 @@ int pidfile_remove(struct pidfh *pfh);
|
|||||||
char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
|
char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
/* humanize_number(3) */
|
/* Values for humanize_number(3)'s flags parameter. */
|
||||||
#define HN_DECIMAL 0x01
|
#define HN_DECIMAL 0x01
|
||||||
#define HN_NOSPACE 0x02
|
#define HN_NOSPACE 0x02
|
||||||
#define HN_B 0x04
|
#define HN_B 0x04
|
||||||
#define HN_DIVISOR_1000 0x08
|
#define HN_DIVISOR_1000 0x08
|
||||||
|
#define HN_IEC_PREFIXES 0x10
|
||||||
|
|
||||||
#define HN_GETSCALE 0x10
|
/* Values for humanize_number(3)'s scale parameter. */
|
||||||
#define HN_AUTOSCALE 0x20
|
#define HN_GETSCALE 0x10
|
||||||
|
#define HN_AUTOSCALE 0x20
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fparseln() specific operation flags.
|
* fparseln() specific operation flags.
|
||||||
|
@ -1,54 +1,33 @@
|
|||||||
/* $OpenBSD: md5.h,v 1.16 2004/06/22 01:57:30 jfb Exp $ */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This code implements the MD5 message-digest algorithm.
|
* Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||||
* The algorithm is due to Ron Rivest. This code was
|
|
||||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
|
||||||
* This code is in the public domain; do with it what you wish.
|
|
||||||
*
|
*
|
||||||
* Equivalent code is available from RSA Data Security, Inc.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* This code has been tested against that, and is equivalent,
|
* modification, are permitted provided that the following conditions
|
||||||
* except that you don't need to include two pages of legalese
|
* are met:
|
||||||
* with every copy.
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_MD5_H
|
#ifndef _AIX
|
||||||
#define LIBBSD_MD5_H
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <md5.h>
|
||||||
#include <stdint.h>
|
#else
|
||||||
|
#include <md5.h>
|
||||||
#define MD5_BLOCK_LENGTH 64
|
#endif
|
||||||
#define MD5_DIGEST_LENGTH 16
|
#endif
|
||||||
#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
|
|
||||||
|
|
||||||
typedef struct MD5Context {
|
|
||||||
uint32_t state[4]; /* state */
|
|
||||||
uint64_t count; /* number of bits, mod 2^64 */
|
|
||||||
uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
|
|
||||||
} MD5_CTX;
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
void MD5Init(MD5_CTX *);
|
|
||||||
void MD5Update(MD5_CTX *, const uint8_t *, size_t)
|
|
||||||
__attribute__((__bounded__(__string__,2,3)));
|
|
||||||
void MD5Pad(MD5_CTX *);
|
|
||||||
void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
|
|
||||||
__attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
|
|
||||||
void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH])
|
|
||||||
__attribute__((__bounded__(__minbytes__,1,4)))
|
|
||||||
__attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
|
|
||||||
char *MD5End(MD5_CTX *, char *)
|
|
||||||
__attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
|
|
||||||
char *MD5File(const char *, char *)
|
|
||||||
__attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
|
|
||||||
char *MD5FileChunk(const char *, char *, off_t, off_t)
|
|
||||||
__attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
|
|
||||||
char *MD5Data(const uint8_t *, size_t, char *)
|
|
||||||
__attribute__((__bounded__(__string__,1,2)))
|
|
||||||
__attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif /* LIBBSD_MD5_H */
|
|
||||||
|
@ -27,14 +27,21 @@
|
|||||||
#ifndef LIBBSD_NLIST_H
|
#ifndef LIBBSD_NLIST_H
|
||||||
#define LIBBSD_NLIST_H
|
#define LIBBSD_NLIST_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct nlist {
|
struct nlist {
|
||||||
union {
|
union {
|
||||||
char *n_name;
|
char *n_name;
|
||||||
struct n_list *n_next;
|
union {
|
||||||
long n_strx;
|
char *n_name;
|
||||||
} n_un;
|
struct n_list *n_next;
|
||||||
|
long n_strx;
|
||||||
|
} n_un;
|
||||||
|
};
|
||||||
unsigned char n_type;
|
unsigned char n_type;
|
||||||
char n_other;
|
char n_other;
|
||||||
short n_desc;
|
short n_desc;
|
||||||
|
53
include/bsd/pwd.h
Normal file
53
include/bsd/pwd.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<pwd.h>)
|
||||||
|
#include_next <pwd.h>
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<pwd.h>)
|
||||||
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_PWD_H
|
||||||
|
#define LIBBSD_PWD_H
|
||||||
|
|
||||||
|
#define _PW_BUF_LEN 1024 /* length of getpw*_r buffer */
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
int
|
||||||
|
uid_from_user(const char *, uid_t *);
|
||||||
|
#ifndef __APPLE__
|
||||||
|
const char *
|
||||||
|
user_from_uid(uid_t, int);
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
@ -31,7 +31,11 @@
|
|||||||
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
|
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
|
||||||
#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
|
#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004-2005, 2009, 2011-2013 Guillem Jover <guillem@hadrons.org>
|
* Copyright © 2004-2024 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -44,8 +44,18 @@
|
|||||||
#include <bsd/sys/cdefs.h>
|
#include <bsd/sys/cdefs.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#if defined(_AIX)
|
||||||
|
#include <stdarg.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
#if defined(_AIX)
|
||||||
|
int asprintf(char **strp, char const *fmt, ...)
|
||||||
|
__printflike(2, 3);
|
||||||
|
int vasprintf(char **strp, char const *fmt, va_list args)
|
||||||
|
__printflike(2, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *fmtcheck(const char *, const char *);
|
const char *fmtcheck(const char *, const char *);
|
||||||
|
|
||||||
/* XXX: The function requires cooperation from the system libc to store the
|
/* XXX: The function requires cooperation from the system libc to store the
|
||||||
|
@ -42,23 +42,35 @@
|
|||||||
#ifndef LIBBSD_STDLIB_H
|
#ifndef LIBBSD_STDLIB_H
|
||||||
#define LIBBSD_STDLIB_H
|
#define LIBBSD_STDLIB_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
#if !defined(__APPLE__) && !defined(__sun)
|
||||||
|
#if !defined(__GLIBC__) || \
|
||||||
|
!__GLIBC_PREREQ(2, 36) || \
|
||||||
|
!defined(_DEFAULT_SOURCE)
|
||||||
uint32_t arc4random(void);
|
uint32_t arc4random(void);
|
||||||
void arc4random_stir(void);
|
|
||||||
void arc4random_addrandom(unsigned char *dat, int datlen);
|
|
||||||
void arc4random_buf(void *_buf, size_t n);
|
void arc4random_buf(void *_buf, size_t n);
|
||||||
uint32_t arc4random_uniform(uint32_t upper_bound);
|
uint32_t arc4random_uniform(uint32_t upper_bound);
|
||||||
|
#endif
|
||||||
|
void arc4random_stir(void);
|
||||||
|
void arc4random_addrandom(unsigned char *dat, int datlen);
|
||||||
|
#endif
|
||||||
|
|
||||||
int dehumanize_number(const char *str, int64_t *size);
|
int dehumanize_number(const char *str, int64_t *size);
|
||||||
|
|
||||||
|
#if !defined(__APPLE__)
|
||||||
const char *getprogname(void);
|
const char *getprogname(void);
|
||||||
void setprogname(const char *);
|
void setprogname(const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
|
||||||
int mergesort(void *base, size_t nmemb, size_t size,
|
int mergesort(void *base, size_t nmemb, size_t size,
|
||||||
int (*cmp)(const void *, const void *));
|
int (*cmp)(const void *, const void *));
|
||||||
int radixsort(const unsigned char **base, int nmemb,
|
int radixsort(const unsigned char **base, int nmemb,
|
||||||
@ -67,9 +79,14 @@ int sradixsort(const unsigned char **base, int nmemb,
|
|||||||
const unsigned char *table, unsigned endbyte);
|
const unsigned char *table, unsigned endbyte);
|
||||||
|
|
||||||
void *reallocf(void *ptr, size_t size);
|
void *reallocf(void *ptr, size_t size);
|
||||||
#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
|
#if !defined(__GLIBC__) || \
|
||||||
|
!__GLIBC_PREREQ(2, 26) || \
|
||||||
|
(__GLIBC_PREREQ(2, 26) && !__GLIBC_PREREQ(2, 29) && !defined(_GNU_SOURCE)) || \
|
||||||
|
(__GLIBC_PREREQ(2, 29) && !defined(_DEFAULT_SOURCE))
|
||||||
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
void *recallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size);
|
||||||
|
void freezero(void *ptr, size_t size);
|
||||||
|
|
||||||
long long strtonum(const char *nptr, long long minval, long long maxval,
|
long long strtonum(const char *nptr, long long minval, long long maxval,
|
||||||
const char **errstr);
|
const char **errstr);
|
||||||
|
@ -33,16 +33,27 @@
|
|||||||
#ifndef LIBBSD_STRING_H
|
#ifndef LIBBSD_STRING_H
|
||||||
#define LIBBSD_STRING_H
|
#define LIBBSD_STRING_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
#if !defined(__APPLE__) && \
|
||||||
|
(!defined(__GLIBC__) || !__GLIBC_PREREQ(2, 38) || !defined(_DEFAULT_SOURCE))
|
||||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||||
|
#endif
|
||||||
char *strnstr(const char *str, const char *find, size_t str_len);
|
char *strnstr(const char *str, const char *find, size_t str_len);
|
||||||
|
#ifndef __APPLE__
|
||||||
void strmode(mode_t mode, char *str);
|
void strmode(mode_t mode, char *str);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
|
#if !defined(__GLIBC__) || \
|
||||||
|
!__GLIBC_PREREQ(2, 25) || \
|
||||||
|
!defined(_DEFAULT_SOURCE)
|
||||||
void explicit_bzero(void *buf, size_t len);
|
void explicit_bzero(void *buf, size_t len);
|
||||||
#endif
|
#endif
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
@ -31,7 +31,12 @@
|
|||||||
|
|
||||||
#ifndef LIBBSD_STRINGLIST_H
|
#ifndef LIBBSD_STRINGLIST_H
|
||||||
#define LIBBSD_STRINGLIST_H
|
#define LIBBSD_STRINGLIST_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -30,6 +30,16 @@
|
|||||||
#ifndef __has_include_next
|
#ifndef __has_include_next
|
||||||
#define __has_include_next(x) 1
|
#define __has_include_next(x) 1
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef __has_attribute
|
||||||
|
#define __has_attribute(x) 0
|
||||||
|
#endif
|
||||||
|
/* Clang expands this to 1 if an identifier is *not* reserved. */
|
||||||
|
#ifndef __is_identifier
|
||||||
|
#define __is_identifier(x) 1
|
||||||
|
#endif
|
||||||
|
#ifndef __has_builtin
|
||||||
|
#define __has_builtin(x) !__is_identifier(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
/*
|
/*
|
||||||
@ -58,6 +68,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On non-glibc based systems, we cannot unconditionally use the
|
||||||
|
* __GLIBC_PREREQ macro as it gets expanded before evaluation.
|
||||||
|
*/
|
||||||
|
#ifndef __GLIBC_PREREQ
|
||||||
|
#define __GLIBC_PREREQ(maj, min) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some kFreeBSD headers expect those macros to be set for sanity checks.
|
* Some kFreeBSD headers expect those macros to be set for sanity checks.
|
||||||
*/
|
*/
|
||||||
@ -68,22 +86,41 @@
|
|||||||
#define _SYS_CDEFS_H
|
#define _SYS_CDEFS_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define the ABI for the current system. */
|
||||||
|
//#define LIBBSD_SYS_TIME_BITS 0
|
||||||
|
//#define LIBBSD_SYS_HAS_TIME64 0
|
||||||
|
|
||||||
|
#define LIBBSD_CONCAT(x, y) x ## y
|
||||||
|
#define LIBBSD_STRING(x) #x
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
|
#define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
|
||||||
#else
|
#else
|
||||||
#define LIBBSD_GCC_VERSION 0
|
#define LIBBSD_GCC_VERSION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIBBSD_GCC_VERSION >= 0x0405
|
#if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__unused__)
|
||||||
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x)))
|
# define LIBBSD_UNUSED __attribute__((__unused__))
|
||||||
|
#else
|
||||||
|
# define LIBBSD_UNUSED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
|
||||||
|
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
|
||||||
#elif LIBBSD_GCC_VERSION >= 0x0301
|
#elif LIBBSD_GCC_VERSION >= 0x0301
|
||||||
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated))
|
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
|
||||||
#else
|
#else
|
||||||
#define LIBBSD_DEPRECATED(x)
|
#define LIBBSD_DEPRECATED(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
|
||||||
|
#define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
|
||||||
|
#endif
|
||||||
|
#define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
|
||||||
|
#define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
|
||||||
|
|
||||||
#ifndef __dead2
|
#ifndef __dead2
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
|
||||||
# define __dead2 __attribute__((__noreturn__))
|
# define __dead2 __attribute__((__noreturn__))
|
||||||
# else
|
# else
|
||||||
# define __dead2
|
# define __dead2
|
||||||
@ -91,7 +128,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __pure2
|
#ifndef __pure2
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
|
||||||
# define __pure2 __attribute__((__const__))
|
# define __pure2 __attribute__((__const__))
|
||||||
# else
|
# else
|
||||||
# define __pure2
|
# define __pure2
|
||||||
@ -99,7 +136,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __packed
|
#ifndef __packed
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
|
||||||
# define __packed __attribute__((__packed__))
|
# define __packed __attribute__((__packed__))
|
||||||
# else
|
# else
|
||||||
# define __packed
|
# define __packed
|
||||||
@ -107,7 +144,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __aligned
|
#ifndef __aligned
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
|
||||||
# define __aligned(x) __attribute__((__aligned__(x)))
|
# define __aligned(x) __attribute__((__aligned__(x)))
|
||||||
# else
|
# else
|
||||||
# define __aligned(x)
|
# define __aligned(x)
|
||||||
@ -119,24 +156,20 @@
|
|||||||
* Disable for now. */
|
* Disable for now. */
|
||||||
#if 0
|
#if 0
|
||||||
#ifndef __unused
|
#ifndef __unused
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0300
|
# define __unused LIBBSD_UNUSED
|
||||||
# define __unused __attribute__((unused))
|
|
||||||
# else
|
|
||||||
# define __unused
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __printflike
|
#ifndef __printflike
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0300
|
# if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
|
||||||
# define __printflike(x, y) __attribute((format(printf, (x), (y))))
|
# define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
|
||||||
# else
|
# else
|
||||||
# define __printflike(x, y)
|
# define __printflike(x, y)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __nonnull
|
#ifndef __nonnull
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0302
|
# if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
|
||||||
# define __nonnull(x) __attribute__((__nonnull__(x)))
|
# define __nonnull(x) __attribute__((__nonnull__(x)))
|
||||||
# else
|
# else
|
||||||
# define __nonnull(x)
|
# define __nonnull(x)
|
||||||
@ -147,20 +180,26 @@
|
|||||||
# define __bounded__(x, y, z)
|
# define __bounded__(x, y, z)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the number of elements in a statically-allocated array,
|
||||||
|
* __x.
|
||||||
|
*/
|
||||||
|
#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
|
* We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
|
||||||
* require it.
|
* require it.
|
||||||
*/
|
*/
|
||||||
#ifndef __offsetof
|
#ifndef __offsetof
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0401
|
# if LIBBSD_GCC_VERSION >= 0x0401 || __has_builtin(__builtin_offsetof)
|
||||||
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
||||||
# else
|
# else
|
||||||
# ifndef __cplusplus
|
# ifndef __cplusplus
|
||||||
# define __offsetof(type, field) \
|
# define __offsetof(type, field) \
|
||||||
((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
|
((size_t)(uintptr_t)((const volatile void *)&((type *)0)->field))
|
||||||
# else
|
# else
|
||||||
# define __offsetof(type, field) \
|
# define __offsetof(type, field) \
|
||||||
(__offsetof__ (reinterpret_cast <__size_t> \
|
(__offsetof__ (reinterpret_cast <size_t> \
|
||||||
(&reinterpret_cast <const volatile char &> \
|
(&reinterpret_cast <const volatile char &> \
|
||||||
(static_cast<type *> (0)->field))))
|
(static_cast<type *> (0)->field))))
|
||||||
# endif
|
# endif
|
||||||
@ -177,9 +216,9 @@
|
|||||||
* compatible with member m.
|
* compatible with member m.
|
||||||
*/
|
*/
|
||||||
#ifndef __containerof
|
#ifndef __containerof
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0301
|
# if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
|
||||||
# define __containerof(x, s, m) ({ \
|
# define __containerof(x, s, m) ({ \
|
||||||
const volatile __typeof(((s *)0)->m) *__x = (x); \
|
const volatile __typeof__(((s *)0)->m) *__x = (x); \
|
||||||
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
|
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
|
||||||
})
|
})
|
||||||
# else
|
# else
|
||||||
@ -213,15 +252,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __DECONST
|
#ifndef __DECONST
|
||||||
#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
|
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __DEVOLATILE
|
#ifndef __DEVOLATILE
|
||||||
#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
|
#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __DEQUALIFY
|
#ifndef __DEQUALIFY
|
||||||
#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
|
#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,10 +27,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<endian.h>)
|
||||||
#include_next <endian.h>
|
#include_next <endian.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<endian.h>)
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_SYS_ENDIAN_H
|
#ifndef LIBBSD_SYS_ENDIAN_H
|
||||||
#define LIBBSD_SYS_ENDIAN_H
|
#define LIBBSD_SYS_ENDIAN_H
|
||||||
|
49
include/bsd/sys/param.h
Normal file
49
include/bsd/sys/param.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2018 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<sys/param.h>)
|
||||||
|
#include_next <sys/param.h>
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<sys/param.h>)
|
||||||
|
#include <sys/param.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_PARAM_H
|
||||||
|
#define LIBBSD_SYS_PARAM_H
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
#endif
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,6 @@
|
|||||||
/*-
|
/*-
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
* Copyright (c) 1991, 1993
|
* Copyright (c) 1991, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -10,7 +12,7 @@
|
|||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 4. Neither the name of the University nor the names of its contributors
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
@ -33,7 +35,11 @@
|
|||||||
#ifndef LIBBSD_SYS_QUEUE_H
|
#ifndef LIBBSD_SYS_QUEUE_H
|
||||||
#define LIBBSD_SYS_QUEUE_H
|
#define LIBBSD_SYS_QUEUE_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file defines four types of data structures: singly-linked lists,
|
* This file defines four types of data structures: singly-linked lists,
|
||||||
@ -76,17 +82,25 @@
|
|||||||
*
|
*
|
||||||
* For details on the use of these macros, see the queue(3) manual page.
|
* For details on the use of these macros, see the queue(3) manual page.
|
||||||
*
|
*
|
||||||
|
* Below is a summary of implemented functions where:
|
||||||
|
* + means the macro is available
|
||||||
|
* - means the macro is not available
|
||||||
|
* s means the macro is available but is slow (runs in O(n) time)
|
||||||
*
|
*
|
||||||
* SLIST LIST STAILQ TAILQ
|
* SLIST LIST STAILQ TAILQ
|
||||||
* _HEAD + + + +
|
* _HEAD + + + +
|
||||||
|
* _CLASS_HEAD + + + +
|
||||||
* _HEAD_INITIALIZER + + + +
|
* _HEAD_INITIALIZER + + + +
|
||||||
* _ENTRY + + + +
|
* _ENTRY + + + +
|
||||||
|
* _CLASS_ENTRY + + + +
|
||||||
* _INIT + + + +
|
* _INIT + + + +
|
||||||
* _EMPTY + + + +
|
* _EMPTY + + + +
|
||||||
|
* _END + + + +
|
||||||
* _FIRST + + + +
|
* _FIRST + + + +
|
||||||
* _NEXT + + + +
|
* _NEXT + + + +
|
||||||
* _PREV - + - +
|
* _PREV - + - +
|
||||||
* _LAST - - + +
|
* _LAST - - + +
|
||||||
|
* _LAST_FAST - - - +
|
||||||
* _FOREACH + + + +
|
* _FOREACH + + + +
|
||||||
* _FOREACH_FROM + + + +
|
* _FOREACH_FROM + + + +
|
||||||
* _FOREACH_SAFE + + + +
|
* _FOREACH_SAFE + + + +
|
||||||
@ -99,14 +113,20 @@
|
|||||||
* _INSERT_BEFORE - + - +
|
* _INSERT_BEFORE - + - +
|
||||||
* _INSERT_AFTER + + + +
|
* _INSERT_AFTER + + + +
|
||||||
* _INSERT_TAIL - - + +
|
* _INSERT_TAIL - - + +
|
||||||
* _CONCAT - - + +
|
* _CONCAT s s + +
|
||||||
* _REMOVE_AFTER + - + -
|
* _REMOVE_AFTER + - + -
|
||||||
* _REMOVE_HEAD + - + -
|
* _REMOVE_HEAD + - + -
|
||||||
* _REMOVE + + + +
|
* _REMOVE s + s +
|
||||||
* _SWAP + + + +
|
* _SWAP + + + +
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifdef QUEUE_MACRO_DEBUG
|
#ifdef QUEUE_MACRO_DEBUG
|
||||||
|
#warn Use QUEUE_MACRO_DEBUG_TRACE and/or QUEUE_MACRO_DEBUG_TRASH
|
||||||
|
#define QUEUE_MACRO_DEBUG_TRACE
|
||||||
|
#define QUEUE_MACRO_DEBUG_TRASH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef QUEUE_MACRO_DEBUG_TRACE
|
||||||
/* Store the last 2 places the queue element or head was altered */
|
/* Store the last 2 places the queue element or head was altered */
|
||||||
struct qm_trace {
|
struct qm_trace {
|
||||||
unsigned long lastline;
|
unsigned long lastline;
|
||||||
@ -116,9 +136,7 @@ struct qm_trace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define TRACEBUF struct qm_trace trace;
|
#define TRACEBUF struct qm_trace trace;
|
||||||
#define TRACEBUF_INITIALIZER { __FILE__, __LINE__, NULL, 0 } ,
|
#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } ,
|
||||||
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
|
|
||||||
#define QMD_SAVELINK(name, link) void **name = (void *)&(link)
|
|
||||||
|
|
||||||
#define QMD_TRACE_HEAD(head) do { \
|
#define QMD_TRACE_HEAD(head) do { \
|
||||||
(head)->trace.prevline = (head)->trace.lastline; \
|
(head)->trace.prevline = (head)->trace.lastline; \
|
||||||
@ -134,14 +152,31 @@ struct qm_trace {
|
|||||||
(elem)->trace.lastfile = __FILE__; \
|
(elem)->trace.lastfile = __FILE__; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else /* !QUEUE_MACRO_DEBUG_TRACE */
|
||||||
#define QMD_TRACE_ELEM(elem)
|
#define QMD_TRACE_ELEM(elem)
|
||||||
#define QMD_TRACE_HEAD(head)
|
#define QMD_TRACE_HEAD(head)
|
||||||
#define QMD_SAVELINK(name, link)
|
|
||||||
#define TRACEBUF
|
#define TRACEBUF
|
||||||
#define TRACEBUF_INITIALIZER
|
#define TRACEBUF_INITIALIZER
|
||||||
|
#endif /* QUEUE_MACRO_DEBUG_TRACE */
|
||||||
|
|
||||||
|
#ifdef QUEUE_MACRO_DEBUG_TRASH
|
||||||
|
#define QMD_SAVELINK(name, link) void **name = (void *)&(link)
|
||||||
|
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
|
||||||
|
#define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1)
|
||||||
|
#else /* !QUEUE_MACRO_DEBUG_TRASH */
|
||||||
|
#define QMD_SAVELINK(name, link)
|
||||||
#define TRASHIT(x)
|
#define TRASHIT(x)
|
||||||
#endif /* QUEUE_MACRO_DEBUG */
|
#define QMD_IS_TRASHED(x) 0
|
||||||
|
#endif /* QUEUE_MACRO_DEBUG_TRASH */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
/*
|
||||||
|
* In C++ there can be structure lists and class lists:
|
||||||
|
*/
|
||||||
|
#define QUEUE_TYPEOF(type) type
|
||||||
|
#else
|
||||||
|
#define QUEUE_TYPEOF(type) struct type
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Singly-linked List declarations.
|
* Singly-linked List declarations.
|
||||||
@ -151,6 +186,11 @@ struct name { \
|
|||||||
struct type *slh_first; /* first element */ \
|
struct type *slh_first; /* first element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SLIST_CLASS_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
class type *slh_first; /* first element */ \
|
||||||
|
}
|
||||||
|
|
||||||
#define SLIST_HEAD_INITIALIZER(head) \
|
#define SLIST_HEAD_INITIALIZER(head) \
|
||||||
{ NULL }
|
{ NULL }
|
||||||
|
|
||||||
@ -159,9 +199,37 @@ struct { \
|
|||||||
struct type *sle_next; /* next element */ \
|
struct type *sle_next; /* next element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SLIST_CLASS_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
class type *sle_next; /* next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Singly-linked List functions.
|
* Singly-linked List functions.
|
||||||
*/
|
*/
|
||||||
|
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||||
|
#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) do { \
|
||||||
|
if (*(prevp) != (elm)) \
|
||||||
|
panic("Bad prevptr *(%p) == %p != %p", \
|
||||||
|
(prevp), *(prevp), (elm)); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define QMD_SLIST_CHECK_PREVPTR(prevp, elm)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SLIST_CONCAT(head1, head2, type, field) do { \
|
||||||
|
QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \
|
||||||
|
if (curelm == NULL) { \
|
||||||
|
if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \
|
||||||
|
SLIST_INIT(head2); \
|
||||||
|
} else if (SLIST_FIRST(head2) != NULL) { \
|
||||||
|
while (SLIST_NEXT(curelm, field) != NULL) \
|
||||||
|
curelm = SLIST_NEXT(curelm, field); \
|
||||||
|
SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \
|
||||||
|
SLIST_INIT(head2); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
|
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
|
||||||
|
|
||||||
#define SLIST_FIRST(head) ((head)->slh_first)
|
#define SLIST_FIRST(head) ((head)->slh_first)
|
||||||
@ -213,7 +281,7 @@ struct { \
|
|||||||
SLIST_REMOVE_HEAD((head), field); \
|
SLIST_REMOVE_HEAD((head), field); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
struct type *curelm = SLIST_FIRST((head)); \
|
QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \
|
||||||
while (SLIST_NEXT(curelm, field) != (elm)) \
|
while (SLIST_NEXT(curelm, field) != (elm)) \
|
||||||
curelm = SLIST_NEXT(curelm, field); \
|
curelm = SLIST_NEXT(curelm, field); \
|
||||||
SLIST_REMOVE_AFTER(curelm, field); \
|
SLIST_REMOVE_AFTER(curelm, field); \
|
||||||
@ -230,12 +298,20 @@ struct { \
|
|||||||
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
|
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \
|
||||||
|
QMD_SLIST_CHECK_PREVPTR(prevp, elm); \
|
||||||
|
*(prevp) = SLIST_NEXT(elm, field); \
|
||||||
|
TRASHIT((elm)->field.sle_next); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define SLIST_SWAP(head1, head2, type) do { \
|
#define SLIST_SWAP(head1, head2, type) do { \
|
||||||
struct type *swap_first = SLIST_FIRST(head1); \
|
QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \
|
||||||
SLIST_FIRST(head1) = SLIST_FIRST(head2); \
|
SLIST_FIRST(head1) = SLIST_FIRST(head2); \
|
||||||
SLIST_FIRST(head2) = swap_first; \
|
SLIST_FIRST(head2) = swap_first; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define SLIST_END(head) NULL
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Singly-linked Tail queue declarations.
|
* Singly-linked Tail queue declarations.
|
||||||
*/
|
*/
|
||||||
@ -245,6 +321,12 @@ struct name { \
|
|||||||
struct type **stqh_last;/* addr of last next element */ \
|
struct type **stqh_last;/* addr of last next element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STAILQ_CLASS_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
class type *stqh_first; /* first element */ \
|
||||||
|
class type **stqh_last; /* addr of last next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
#define STAILQ_HEAD_INITIALIZER(head) \
|
#define STAILQ_HEAD_INITIALIZER(head) \
|
||||||
{ NULL, &(head).stqh_first }
|
{ NULL, &(head).stqh_first }
|
||||||
|
|
||||||
@ -253,6 +335,11 @@ struct { \
|
|||||||
struct type *stqe_next; /* next element */ \
|
struct type *stqe_next; /* next element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STAILQ_CLASS_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
class type *stqe_next; /* next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Singly-linked Tail queue functions.
|
* Singly-linked Tail queue functions.
|
||||||
*/
|
*/
|
||||||
@ -311,9 +398,10 @@ struct { \
|
|||||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define STAILQ_LAST(head, type, field) \
|
#define STAILQ_LAST(head, type, field) \
|
||||||
(STAILQ_EMPTY((head)) ? NULL : \
|
(STAILQ_EMPTY((head)) ? NULL : \
|
||||||
__containerof((head)->stqh_last, struct type, field.stqe_next))
|
__containerof((head)->stqh_last, \
|
||||||
|
QUEUE_TYPEOF(type), field.stqe_next))
|
||||||
|
|
||||||
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
|
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
|
||||||
|
|
||||||
@ -323,7 +411,7 @@ struct { \
|
|||||||
STAILQ_REMOVE_HEAD((head), field); \
|
STAILQ_REMOVE_HEAD((head), field); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
struct type *curelm = STAILQ_FIRST((head)); \
|
QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \
|
||||||
while (STAILQ_NEXT(curelm, field) != (elm)) \
|
while (STAILQ_NEXT(curelm, field) != (elm)) \
|
||||||
curelm = STAILQ_NEXT(curelm, field); \
|
curelm = STAILQ_NEXT(curelm, field); \
|
||||||
STAILQ_REMOVE_AFTER(head, curelm, field); \
|
STAILQ_REMOVE_AFTER(head, curelm, field); \
|
||||||
@ -344,8 +432,8 @@ struct { \
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define STAILQ_SWAP(head1, head2, type) do { \
|
#define STAILQ_SWAP(head1, head2, type) do { \
|
||||||
struct type *swap_first = STAILQ_FIRST(head1); \
|
QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \
|
||||||
struct type **swap_last = (head1)->stqh_last; \
|
QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \
|
||||||
STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
|
STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
|
||||||
(head1)->stqh_last = (head2)->stqh_last; \
|
(head1)->stqh_last = (head2)->stqh_last; \
|
||||||
STAILQ_FIRST(head2) = swap_first; \
|
STAILQ_FIRST(head2) = swap_first; \
|
||||||
@ -356,6 +444,8 @@ struct { \
|
|||||||
(head2)->stqh_last = &STAILQ_FIRST(head2); \
|
(head2)->stqh_last = &STAILQ_FIRST(head2); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define STAILQ_END(head) NULL
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List declarations.
|
* List declarations.
|
||||||
@ -365,6 +455,11 @@ struct name { \
|
|||||||
struct type *lh_first; /* first element */ \
|
struct type *lh_first; /* first element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LIST_CLASS_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
class type *lh_first; /* first element */ \
|
||||||
|
}
|
||||||
|
|
||||||
#define LIST_HEAD_INITIALIZER(head) \
|
#define LIST_HEAD_INITIALIZER(head) \
|
||||||
{ NULL }
|
{ NULL }
|
||||||
|
|
||||||
@ -374,11 +469,23 @@ struct { \
|
|||||||
struct type **le_prev; /* address of previous next element */ \
|
struct type **le_prev; /* address of previous next element */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LIST_CLASS_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
class type *le_next; /* next element */ \
|
||||||
|
class type **le_prev; /* address of previous next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List functions.
|
* List functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||||
|
/*
|
||||||
|
* QMD_LIST_CHECK_HEAD(LIST_HEAD *head, LIST_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* If the list is non-empty, validates that the first element of the list
|
||||||
|
* points back at 'head.'
|
||||||
|
*/
|
||||||
#define QMD_LIST_CHECK_HEAD(head, field) do { \
|
#define QMD_LIST_CHECK_HEAD(head, field) do { \
|
||||||
if (LIST_FIRST((head)) != NULL && \
|
if (LIST_FIRST((head)) != NULL && \
|
||||||
LIST_FIRST((head))->field.le_prev != \
|
LIST_FIRST((head))->field.le_prev != \
|
||||||
@ -386,6 +493,12 @@ struct { \
|
|||||||
panic("Bad list head %p first->prev != head", (head)); \
|
panic("Bad list head %p first->prev != head", (head)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QMD_LIST_CHECK_NEXT(TYPE *elm, LIST_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* If an element follows 'elm' in the list, validates that the next element
|
||||||
|
* points back at 'elm.'
|
||||||
|
*/
|
||||||
#define QMD_LIST_CHECK_NEXT(elm, field) do { \
|
#define QMD_LIST_CHECK_NEXT(elm, field) do { \
|
||||||
if (LIST_NEXT((elm), field) != NULL && \
|
if (LIST_NEXT((elm), field) != NULL && \
|
||||||
LIST_NEXT((elm), field)->field.le_prev != \
|
LIST_NEXT((elm), field)->field.le_prev != \
|
||||||
@ -393,6 +506,11 @@ struct { \
|
|||||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QMD_LIST_CHECK_PREV(TYPE *elm, LIST_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* Validates that the previous element (or head of the list) points to 'elm.'
|
||||||
|
*/
|
||||||
#define QMD_LIST_CHECK_PREV(elm, field) do { \
|
#define QMD_LIST_CHECK_PREV(elm, field) do { \
|
||||||
if (*(elm)->field.le_prev != (elm)) \
|
if (*(elm)->field.le_prev != (elm)) \
|
||||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||||
@ -403,6 +521,23 @@ struct { \
|
|||||||
#define QMD_LIST_CHECK_PREV(elm, field)
|
#define QMD_LIST_CHECK_PREV(elm, field)
|
||||||
#endif /* (_KERNEL && INVARIANTS) */
|
#endif /* (_KERNEL && INVARIANTS) */
|
||||||
|
|
||||||
|
#define LIST_CONCAT(head1, head2, type, field) do { \
|
||||||
|
QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \
|
||||||
|
if (curelm == NULL) { \
|
||||||
|
if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \
|
||||||
|
LIST_FIRST(head2)->field.le_prev = \
|
||||||
|
&LIST_FIRST((head1)); \
|
||||||
|
LIST_INIT(head2); \
|
||||||
|
} \
|
||||||
|
} else if (LIST_FIRST(head2) != NULL) { \
|
||||||
|
while (LIST_NEXT(curelm, field) != NULL) \
|
||||||
|
curelm = LIST_NEXT(curelm, field); \
|
||||||
|
LIST_NEXT(curelm, field) = LIST_FIRST(head2); \
|
||||||
|
LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \
|
||||||
|
LIST_INIT(head2); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
|
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
|
||||||
|
|
||||||
#define LIST_FIRST(head) ((head)->lh_first)
|
#define LIST_FIRST(head) ((head)->lh_first)
|
||||||
@ -458,9 +593,10 @@ struct { \
|
|||||||
|
|
||||||
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
||||||
|
|
||||||
#define LIST_PREV(elm, head, type, field) \
|
#define LIST_PREV(elm, head, type, field) \
|
||||||
((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \
|
((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \
|
||||||
__containerof((elm)->field.le_prev, struct type, field.le_next))
|
__containerof((elm)->field.le_prev, \
|
||||||
|
QUEUE_TYPEOF(type), field.le_next))
|
||||||
|
|
||||||
#define LIST_REMOVE(elm, field) do { \
|
#define LIST_REMOVE(elm, field) do { \
|
||||||
QMD_SAVELINK(oldnext, (elm)->field.le_next); \
|
QMD_SAVELINK(oldnext, (elm)->field.le_next); \
|
||||||
@ -476,7 +612,7 @@ struct { \
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LIST_SWAP(head1, head2, type, field) do { \
|
#define LIST_SWAP(head1, head2, type, field) do { \
|
||||||
struct type *swap_tmp = LIST_FIRST((head1)); \
|
QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \
|
||||||
LIST_FIRST((head1)) = LIST_FIRST((head2)); \
|
LIST_FIRST((head1)) = LIST_FIRST((head2)); \
|
||||||
LIST_FIRST((head2)) = swap_tmp; \
|
LIST_FIRST((head2)) = swap_tmp; \
|
||||||
if ((swap_tmp = LIST_FIRST((head1))) != NULL) \
|
if ((swap_tmp = LIST_FIRST((head1))) != NULL) \
|
||||||
@ -485,6 +621,8 @@ struct { \
|
|||||||
swap_tmp->field.le_prev = &LIST_FIRST((head2)); \
|
swap_tmp->field.le_prev = &LIST_FIRST((head2)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define LIST_END(head) NULL
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tail queue declarations.
|
* Tail queue declarations.
|
||||||
*/
|
*/
|
||||||
@ -495,6 +633,13 @@ struct name { \
|
|||||||
TRACEBUF \
|
TRACEBUF \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TAILQ_CLASS_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
class type *tqh_first; /* first element */ \
|
||||||
|
class type **tqh_last; /* addr of last next element */ \
|
||||||
|
TRACEBUF \
|
||||||
|
}
|
||||||
|
|
||||||
#define TAILQ_HEAD_INITIALIZER(head) \
|
#define TAILQ_HEAD_INITIALIZER(head) \
|
||||||
{ NULL, &(head).tqh_first, TRACEBUF_INITIALIZER }
|
{ NULL, &(head).tqh_first, TRACEBUF_INITIALIZER }
|
||||||
|
|
||||||
@ -505,10 +650,23 @@ struct { \
|
|||||||
TRACEBUF \
|
TRACEBUF \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TAILQ_CLASS_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
class type *tqe_next; /* next element */ \
|
||||||
|
class type **tqe_prev; /* address of previous next element */ \
|
||||||
|
TRACEBUF \
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tail queue functions.
|
* Tail queue functions.
|
||||||
*/
|
*/
|
||||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||||
|
/*
|
||||||
|
* QMD_TAILQ_CHECK_HEAD(TAILQ_HEAD *head, TAILQ_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* If the tailq is non-empty, validates that the first element of the tailq
|
||||||
|
* points back at 'head.'
|
||||||
|
*/
|
||||||
#define QMD_TAILQ_CHECK_HEAD(head, field) do { \
|
#define QMD_TAILQ_CHECK_HEAD(head, field) do { \
|
||||||
if (!TAILQ_EMPTY(head) && \
|
if (!TAILQ_EMPTY(head) && \
|
||||||
TAILQ_FIRST((head))->field.tqe_prev != \
|
TAILQ_FIRST((head))->field.tqe_prev != \
|
||||||
@ -516,11 +674,22 @@ struct { \
|
|||||||
panic("Bad tailq head %p first->prev != head", (head)); \
|
panic("Bad tailq head %p first->prev != head", (head)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QMD_TAILQ_CHECK_TAIL(TAILQ_HEAD *head, TAILQ_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* Validates that the tail of the tailq is a pointer to pointer to NULL.
|
||||||
|
*/
|
||||||
#define QMD_TAILQ_CHECK_TAIL(head, field) do { \
|
#define QMD_TAILQ_CHECK_TAIL(head, field) do { \
|
||||||
if (*(head)->tqh_last != NULL) \
|
if (*(head)->tqh_last != NULL) \
|
||||||
panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
|
panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QMD_TAILQ_CHECK_NEXT(TYPE *elm, TAILQ_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* If an element follows 'elm' in the tailq, validates that the next element
|
||||||
|
* points back at 'elm.'
|
||||||
|
*/
|
||||||
#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
|
#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
|
||||||
if (TAILQ_NEXT((elm), field) != NULL && \
|
if (TAILQ_NEXT((elm), field) != NULL && \
|
||||||
TAILQ_NEXT((elm), field)->field.tqe_prev != \
|
TAILQ_NEXT((elm), field)->field.tqe_prev != \
|
||||||
@ -528,6 +697,11 @@ struct { \
|
|||||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QMD_TAILQ_CHECK_PREV(TYPE *elm, TAILQ_ENTRY NAME)
|
||||||
|
*
|
||||||
|
* Validates that the previous element (or head of the tailq) points to 'elm.'
|
||||||
|
*/
|
||||||
#define QMD_TAILQ_CHECK_PREV(elm, field) do { \
|
#define QMD_TAILQ_CHECK_PREV(elm, field) do { \
|
||||||
if (*(elm)->field.tqe_prev != (elm)) \
|
if (*(elm)->field.tqe_prev != (elm)) \
|
||||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||||
@ -612,7 +786,7 @@ struct { \
|
|||||||
TAILQ_NEXT((listelm), field) = (elm); \
|
TAILQ_NEXT((listelm), field) = (elm); \
|
||||||
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
|
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
|
||||||
QMD_TRACE_ELEM(&(elm)->field); \
|
QMD_TRACE_ELEM(&(elm)->field); \
|
||||||
QMD_TRACE_ELEM(&listelm->field); \
|
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
||||||
@ -622,7 +796,7 @@ struct { \
|
|||||||
*(listelm)->field.tqe_prev = (elm); \
|
*(listelm)->field.tqe_prev = (elm); \
|
||||||
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
|
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
|
||||||
QMD_TRACE_ELEM(&(elm)->field); \
|
QMD_TRACE_ELEM(&(elm)->field); \
|
||||||
QMD_TRACE_ELEM(&listelm->field); \
|
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||||
@ -651,11 +825,25 @@ struct { \
|
|||||||
#define TAILQ_LAST(head, headname) \
|
#define TAILQ_LAST(head, headname) \
|
||||||
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The FAST function is fast in that it causes no data access other
|
||||||
|
* then the access to the head. The standard LAST function above
|
||||||
|
* will cause a data access of both the element you want and
|
||||||
|
* the previous element. FAST is very useful for instances when
|
||||||
|
* you may want to prefetch the last data element.
|
||||||
|
*/
|
||||||
|
#define TAILQ_LAST_FAST(head, type, field) \
|
||||||
|
(TAILQ_EMPTY(head) ? NULL : __containerof((head)->tqh_last, QUEUE_TYPEOF(type), field.tqe_next))
|
||||||
|
|
||||||
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
||||||
|
|
||||||
#define TAILQ_PREV(elm, headname, field) \
|
#define TAILQ_PREV(elm, headname, field) \
|
||||||
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
||||||
|
|
||||||
|
#define TAILQ_PREV_FAST(elm, head, type, field) \
|
||||||
|
((elm)->field.tqe_prev == &(head)->tqh_first ? NULL : \
|
||||||
|
__containerof((elm)->field.tqe_prev, QUEUE_TYPEOF(type), field.tqe_next))
|
||||||
|
|
||||||
#define TAILQ_REMOVE(head, elm, field) do { \
|
#define TAILQ_REMOVE(head, elm, field) do { \
|
||||||
QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \
|
QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \
|
||||||
QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \
|
QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \
|
||||||
@ -675,8 +863,8 @@ struct { \
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TAILQ_SWAP(head1, head2, type, field) do { \
|
#define TAILQ_SWAP(head1, head2, type, field) do { \
|
||||||
struct type *swap_first = (head1)->tqh_first; \
|
QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \
|
||||||
struct type **swap_last = (head1)->tqh_last; \
|
QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \
|
||||||
(head1)->tqh_first = (head2)->tqh_first; \
|
(head1)->tqh_first = (head2)->tqh_first; \
|
||||||
(head1)->tqh_last = (head2)->tqh_last; \
|
(head1)->tqh_last = (head2)->tqh_last; \
|
||||||
(head2)->tqh_first = swap_first; \
|
(head2)->tqh_first = swap_first; \
|
||||||
@ -691,4 +879,6 @@ struct { \
|
|||||||
(head2)->tqh_last = &(head2)->tqh_first; \
|
(head2)->tqh_last = &(head2)->tqh_first; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define TAILQ_END(head) NULL
|
||||||
|
|
||||||
#endif /* !LIBBSD_SYS_QUEUE_H */
|
#endif /* !LIBBSD_SYS_QUEUE_H */
|
||||||
|
@ -33,10 +33,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<sys/time.h>)
|
||||||
#include_next <sys/time.h>
|
#include_next <sys/time.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<sys/time.h>)
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_SYS_TIME_H
|
#ifndef LIBBSD_SYS_TIME_H
|
||||||
#define LIBBSD_SYS_TIME_H
|
#define LIBBSD_SYS_TIME_H
|
||||||
|
@ -30,7 +30,11 @@
|
|||||||
#ifndef LIBBSD_SYS_TREE_H
|
#ifndef LIBBSD_SYS_TREE_H
|
||||||
#define LIBBSD_SYS_TREE_H
|
#define LIBBSD_SYS_TREE_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file defines data structures for different types of trees:
|
* This file defines data structures for different types of trees:
|
||||||
@ -381,7 +385,7 @@ struct { \
|
|||||||
#define RB_PROTOTYPE(name, type, field, cmp) \
|
#define RB_PROTOTYPE(name, type, field, cmp) \
|
||||||
RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
|
RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
|
||||||
#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \
|
#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \
|
||||||
RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static)
|
RB_PROTOTYPE_INTERNAL(name, type, field, cmp, LIBBSD_UNUSED static)
|
||||||
#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \
|
#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \
|
||||||
attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \
|
attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \
|
||||||
attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\
|
attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\
|
||||||
@ -400,7 +404,7 @@ attr struct type *name##_RB_MINMAX(struct name *, int); \
|
|||||||
#define RB_GENERATE(name, type, field, cmp) \
|
#define RB_GENERATE(name, type, field, cmp) \
|
||||||
RB_GENERATE_INTERNAL(name, type, field, cmp,)
|
RB_GENERATE_INTERNAL(name, type, field, cmp,)
|
||||||
#define RB_GENERATE_STATIC(name, type, field, cmp) \
|
#define RB_GENERATE_STATIC(name, type, field, cmp) \
|
||||||
RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static)
|
RB_GENERATE_INTERNAL(name, type, field, cmp, LIBBSD_UNUSED static)
|
||||||
#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \
|
#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \
|
||||||
attr void \
|
attr void \
|
||||||
name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \
|
name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \
|
||||||
|
@ -41,7 +41,11 @@
|
|||||||
#ifndef LIBBSD_TIMECONV_H
|
#ifndef LIBBSD_TIMECONV_H
|
||||||
#define LIBBSD_TIMECONV_H
|
#define LIBBSD_TIMECONV_H
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -54,4 +58,17 @@ time_t _long_to_time(long tlong);
|
|||||||
int _time_to_int(time_t t);
|
int _time_to_int(time_t t);
|
||||||
time_t _int_to_time(int tint);
|
time_t _int_to_time(int tint);
|
||||||
|
|
||||||
|
#if LIBBSD_SYS_TIME_BITS == 32 && LIBBSD_SYS_HAS_TIME64
|
||||||
|
#if defined _TIME_BITS && _TIME_BITS == 64
|
||||||
|
time_t LIBBSD_REDIRECT(_time32_to_time, (int32_t t32), _time32_to_time_time64);
|
||||||
|
int32_t LIBBSD_REDIRECT(_time_to_time32, (time_t t), _time_to_time32_time64);
|
||||||
|
time_t LIBBSD_REDIRECT(_time64_to_time, (int64_t t64), _time64_to_time_time64);
|
||||||
|
int64_t LIBBSD_REDIRECT(_time_to_time64, (time_t t), _time_to_time64_time64);
|
||||||
|
long LIBBSD_REDIRECT(_time_to_long, (time_t t), _time_to_long_time64);
|
||||||
|
time_t LIBBSD_REDIRECT(_long_to_time, (long tlong), _long_to_time_time64);
|
||||||
|
int LIBBSD_REDIRECT(_time_to_int, (time_t t), _time_to_int_time64);
|
||||||
|
time_t LIBBSD_REDIRECT(_int_to_time, (int tint), _int_to_time_time64);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LIBBSD_TIMECONV_H */
|
#endif /* LIBBSD_TIMECONV_H */
|
||||||
|
@ -26,26 +26,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if __has_include_next(<unistd.h>)
|
||||||
#include_next <unistd.h>
|
#include_next <unistd.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#if __has_include(<unistd.h>)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_UNISTD_H
|
#ifndef LIBBSD_UNISTD_H
|
||||||
#define LIBBSD_UNISTD_H
|
#define LIBBSD_UNISTD_H
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#else
|
|
||||||
#include <bsd/sys/cdefs.h>
|
|
||||||
#endif
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifndef S_ISTXT
|
#if !defined(S_ISTXT) && defined(S_ISVTX)
|
||||||
#define S_ISTXT S_ISVTX
|
#define S_ISTXT S_ISVTX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
#if !defined(__APPLE__)
|
||||||
extern int optreset;
|
extern int optreset;
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
@ -54,11 +56,16 @@ extern int optreset;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int bsd_getopt(int argc, char * const argv[], const char *shortopts);
|
int bsd_getopt(int argc, char * const argv[], const char *shortopts);
|
||||||
|
#endif
|
||||||
|
|
||||||
mode_t getmode(const void *set, mode_t mode);
|
mode_t getmode(const void *set, mode_t mode);
|
||||||
void *setmode(const char *mode_str);
|
void *setmode(const char *mode_str);
|
||||||
|
|
||||||
|
#if !defined(__GLIBC__) || \
|
||||||
|
!__GLIBC_PREREQ(2, 34) || \
|
||||||
|
!defined(_DEFAULT_SOURCE)
|
||||||
void closefrom(int lowfd);
|
void closefrom(int lowfd);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Compatibility with sendmail implementations. */
|
/* Compatibility with sendmail implementations. */
|
||||||
#define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))
|
#define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* $NetBSD: vis.h,v 1.25 2017/04/23 01:57:36 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1990, 1993
|
* Copyright (c) 1990, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@ -27,7 +29,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)vis.h 8.1 (Berkeley) 6/2/93
|
* @(#)vis.h 8.1 (Berkeley) 6/2/93
|
||||||
* $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_VIS_H
|
#ifndef LIBBSD_VIS_H
|
||||||
@ -38,25 +39,34 @@
|
|||||||
/*
|
/*
|
||||||
* to select alternate encoding format
|
* to select alternate encoding format
|
||||||
*/
|
*/
|
||||||
#define VIS_OCTAL 0x01 /* use octal \ddd format */
|
#define VIS_OCTAL 0x0001 /* use octal \ddd format */
|
||||||
#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
|
#define VIS_CSTYLE 0x0002 /* use \[nrft0..] where appropriate */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* to alter set of characters encoded (default is to encode all
|
* to alter set of characters encoded (default is to encode all
|
||||||
* non-graphic except space, tab, and newline).
|
* non-graphic except space, tab, and newline).
|
||||||
*/
|
*/
|
||||||
#define VIS_SP 0x04 /* also encode space */
|
#define VIS_SP 0x0004 /* also encode space */
|
||||||
#define VIS_TAB 0x08 /* also encode tab */
|
#define VIS_TAB 0x0008 /* also encode tab */
|
||||||
#define VIS_NL 0x10 /* also encode newline */
|
#define VIS_NL 0x0010 /* also encode newline */
|
||||||
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
|
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
|
||||||
#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
|
#define VIS_SAFE 0x0020 /* only encode "unsafe" characters */
|
||||||
|
#define VIS_DQ 0x8000 /* also encode double quotes */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* other
|
* other
|
||||||
*/
|
*/
|
||||||
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
|
#define VIS_NOSLASH 0x0040 /* inhibit printing '\' */
|
||||||
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
|
#define VIS_HTTP1808 0x0080 /* http-style escape % hex hex */
|
||||||
#define VIS_GLOB 0x100 /* encode glob(3) magics */
|
#define VIS_HTTPSTYLE 0x0080 /* http-style escape % hex hex */
|
||||||
|
#define VIS_MIMESTYLE 0x0100 /* mime-style escape = HEX HEX */
|
||||||
|
#define VIS_HTTP1866 0x0200 /* http-style &#num; or &string; */
|
||||||
|
#define VIS_NOESCAPE 0x0400 /* don't decode `\' */
|
||||||
|
#define _VIS_END 0x0800 /* for unvis */
|
||||||
|
#define VIS_GLOB 0x1000 /* encode glob(3) magic characters */
|
||||||
|
#define VIS_SHELL 0x2000 /* encode shell special characters [not glob] */
|
||||||
|
#define VIS_META (VIS_WHITE | VIS_GLOB | VIS_SHELL)
|
||||||
|
#define VIS_NOLOCALE 0x4000 /* encode using the C locale */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unvis return codes
|
* unvis return codes
|
||||||
@ -70,18 +80,76 @@
|
|||||||
/*
|
/*
|
||||||
* unvis flags
|
* unvis flags
|
||||||
*/
|
*/
|
||||||
#define UNVIS_END 1 /* no more characters */
|
#define UNVIS_END _VIS_END /* no more characters */
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NetBSD added an strnvis and unfortunately made it incompatible with the
|
||||||
|
* existing one in OpenBSD and Freedesktop's libbsd (the former having existed
|
||||||
|
* for over ten years). Despite this incompatibility being reported during
|
||||||
|
* development (see http://gnats.netbsd.org/44977) they still shipped it.
|
||||||
|
* Even more unfortunately FreeBSD and later macOS picked up this incompatible
|
||||||
|
* implementation.
|
||||||
|
*
|
||||||
|
* Provide both implementations and default for now on the historical one to
|
||||||
|
* avoid breakage, we will switch to the NetBSD one in libbsd 0.10.0 or so.
|
||||||
|
* Define LIBBSD_NETBSD_VIS to switch to the NetBSD one now.
|
||||||
|
* Define LIBBSD_OPENBSD_VIS to keep using the OpenBSD one.
|
||||||
|
*/
|
||||||
|
#if defined(LIBBSD_OPENBSD_VIS)
|
||||||
|
#undef LIBBSD_NETBSD_VIS
|
||||||
|
#elif !defined(LIBBSD_NETBSD_VIS)
|
||||||
|
#warning "NetBSD added incompatible strnvis() and strnunvis(), please see <bsd/vis.h> for more detils."
|
||||||
|
#endif
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
char *vis(char *, int, int, int);
|
char *vis(char *, int, int, int);
|
||||||
|
char *nvis(char *, size_t, int, int, int);
|
||||||
|
|
||||||
|
char *svis(char *, int, int, int, const char *);
|
||||||
|
char *snvis(char *, size_t, int, int, int, const char *);
|
||||||
|
|
||||||
int strvis(char *, const char *, int);
|
int strvis(char *, const char *, int);
|
||||||
int strvisx(char *, const char *, size_t, int);
|
int stravis(char **, const char *, int);
|
||||||
|
#ifdef LIBBSD_NETBSD_VIS
|
||||||
|
/* NetBSD prototype. */
|
||||||
|
int LIBBSD_REDIRECT(strnvis, (char *, size_t, const char *, int),
|
||||||
|
strnvis_netbsd);
|
||||||
|
#else
|
||||||
|
/* OpenBSD prototype (current default). */
|
||||||
int strnvis(char *, const char *, size_t, int);
|
int strnvis(char *, const char *, size_t, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int strsvis(char *, const char *, int, const char *);
|
||||||
|
int strsnvis(char *, size_t, const char *, int, const char *);
|
||||||
|
|
||||||
|
int strvisx(char *, const char *, size_t, int);
|
||||||
|
int strnvisx(char *, size_t, const char *, size_t, int);
|
||||||
|
int strenvisx(char *, size_t, const char *, size_t, int, int *);
|
||||||
|
|
||||||
|
int strsvisx(char *, const char *, size_t, int, const char *);
|
||||||
|
int strsnvisx(char *, size_t, const char *, size_t, int, const char *);
|
||||||
|
int strsenvisx(char *, size_t, const char *, size_t , int, const char *,
|
||||||
|
int *);
|
||||||
|
|
||||||
int strunvis(char *, const char *);
|
int strunvis(char *, const char *);
|
||||||
|
#ifdef LIBBSD_NETBSD_VIS
|
||||||
|
/* NetBSD prototype. */
|
||||||
|
int LIBBSD_REDIRECT(strnunvis, (char *, size_t, const char *),
|
||||||
|
strnunvis_netbsd);
|
||||||
|
#else
|
||||||
|
/* OpenBSD prototype (current default). */
|
||||||
|
ssize_t strnunvis(char *, const char *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
int strunvisx(char *, const char *, int);
|
int strunvisx(char *, const char *, int);
|
||||||
ssize_t strnunvis(char *, const char *, size_t);
|
int strnunvisx(char *, size_t, const char *, int);
|
||||||
|
|
||||||
int unvis(char *, int, int *, int);
|
int unvis(char *, int, int *, int);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
@ -40,14 +40,20 @@
|
|||||||
#define LIBBSD_WCHAR_H
|
#define LIBBSD_WCHAR_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/sys/cdefs.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
wchar_t *fgetwln(FILE *stream, size_t *len);
|
wchar_t *fgetwln(FILE *stream, size_t *len);
|
||||||
|
|
||||||
|
#if !defined(__APPLE__)
|
||||||
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
|
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
|
||||||
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
|
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
|
||||||
|
#endif
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
m4/.gitignore
vendored
Normal file
2
m4/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.m4
|
||||||
|
!libbsd*.m4
|
104
m4/libbsd-compiler.m4
Normal file
104
m4/libbsd-compiler.m4
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
# Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||||
|
|
||||||
|
# LIBBSD_CHECK_COMPILER_FLAG
|
||||||
|
# --------------------------
|
||||||
|
AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
|
||||||
|
AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1])
|
||||||
|
AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [
|
||||||
|
m4_define([libbsd_check_flag], m4_bpatsubst([$1], [^-Wno-], [-W]))
|
||||||
|
AS_VAR_COPY([libbsd_save_CFLAGS], [CFLAGS])
|
||||||
|
AS_VAR_SET([CFLAGS], ["-Werror libbsd_check_flag"])
|
||||||
|
AC_COMPILE_IFELSE([
|
||||||
|
AC_LANG_SOURCE([[]])
|
||||||
|
], [
|
||||||
|
AS_VAR_SET([libbsd_varname_cache], [yes])
|
||||||
|
], [
|
||||||
|
AS_VAR_SET([libbsd_varname_cache], [no])
|
||||||
|
])
|
||||||
|
AS_VAR_COPY([CFLAGS], [libbsd_save_CFLAGS])
|
||||||
|
])
|
||||||
|
AS_VAR_IF([libbsd_varname_cache], [yes], [
|
||||||
|
AS_VAR_APPEND([LIBBSD_COMPILER_FLAGS], [" $1"])
|
||||||
|
])
|
||||||
|
AS_VAR_POPDEF([libbsd_varname_cache])
|
||||||
|
])
|
||||||
|
|
||||||
|
# LIBBSD_HAS_GNU_INIT_ARRAY
|
||||||
|
# -------------------------
|
||||||
|
AC_DEFUN([LIBBSD_HAS_GNU_INIT_ARRAY], [
|
||||||
|
AC_CACHE_CHECK([for GNU .init_array section support],
|
||||||
|
[libbsd_cv_gnu_init_array_support], [
|
||||||
|
AC_RUN_IFELSE([
|
||||||
|
AC_LANG_SOURCE([[
|
||||||
|
static int rc = 1;
|
||||||
|
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||||
|
void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
|
||||||
|
int main() { return rc; }
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
libbsd_cv_gnu_init_array_support=yes
|
||||||
|
], [
|
||||||
|
libbsd_cv_gnu_init_array_support=no
|
||||||
|
], [
|
||||||
|
AC_PREPROC_IFELSE([
|
||||||
|
AC_LANG_SOURCE([[
|
||||||
|
/* Look for a known libc that supports .init_array with the GNU extension
|
||||||
|
* to pass main() arguments to the init functions. */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#if defined __GLIBC_PREREQ
|
||||||
|
# if __GLIBC_PREREQ(2, 4)
|
||||||
|
/* glibc supports GNU .init_array since 2.4. */
|
||||||
|
# else
|
||||||
|
# error glibc does not support GNU .init_array
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
||||||
|
* - Bionic since its inception.
|
||||||
|
* - uClibc since 0.9.29.
|
||||||
|
*/
|
||||||
|
# error unknown whether libc supports GNU .init_array
|
||||||
|
#endif
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
libbsd_cv_gnu_init_array_support=yes
|
||||||
|
], [
|
||||||
|
libbsd_cv_gnu_init_array_support=no
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
|
||||||
|
[test "$libbsd_cv_gnu_init_array_support" = yes])
|
||||||
|
])
|
||||||
|
|
||||||
|
# LIBBSD_SELECT_API(name, desc)
|
||||||
|
# -----------------
|
||||||
|
AC_DEFUN([LIBBSD_SELECT_API], [
|
||||||
|
AS_IF([test -z "$AS_TR_SH([api_$1])"], [
|
||||||
|
AC_MSG_ERROR([missing API selection for $1])
|
||||||
|
], [test "$AS_TR_SH([api_$1])" = "unknown"], [
|
||||||
|
AC_MSG_ERROR([unknown ABI selection for $1])
|
||||||
|
], [test "$AS_TR_SH([api_$1])" = "yes"], [
|
||||||
|
AC_DEFINE(AS_TR_CPP([LIBBSD_API_$1]), [1], [Provide API for $2])
|
||||||
|
], [
|
||||||
|
AC_DEFINE(AS_TR_CPP([LIBBSD_API_$1]), [0])
|
||||||
|
])
|
||||||
|
AM_CONDITIONAL(AS_TR_CPP([API_$1]),
|
||||||
|
[test "x$AS_TR_SH([api_$1])" = "xyes"])
|
||||||
|
])
|
||||||
|
|
||||||
|
# LIBBSD_SELECT_ABI(name, desc)
|
||||||
|
# -----------------
|
||||||
|
AC_DEFUN([LIBBSD_SELECT_ABI], [
|
||||||
|
AS_IF([test -z "$AS_TR_SH([abi_$1])"], [
|
||||||
|
AC_MSG_ERROR([missing ABI selection for $1])
|
||||||
|
], [test "$AS_TR_SH([abi_$1])" = "unknown"], [
|
||||||
|
AC_MSG_ERROR([unknown ABI selection for $1])
|
||||||
|
], [test "$AS_TR_SH([abi_$1])" = "yes"], [
|
||||||
|
AC_DEFINE(AS_TR_CPP([LIBBSD_ABI_$1]), [1], [Provide ABI for $2])
|
||||||
|
], [
|
||||||
|
AC_DEFINE(AS_TR_CPP([LIBBSD_ABI_$1]), [0])
|
||||||
|
])
|
||||||
|
AM_CONDITIONAL(AS_TR_CPP([ABI_$1]),
|
||||||
|
[test "x$AS_TR_SH([abi_$1])" = "xyes"])
|
||||||
|
])
|
57
m4/libbsd-funcs.m4
Normal file
57
m4/libbsd-funcs.m4
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Copyright © 2011-2024 Guillem Jover <guillem@hadrons.org>
|
||||||
|
|
||||||
|
# LIBBSD_CHECK_PROGNAME
|
||||||
|
# ---------------------
|
||||||
|
AC_DEFUN([LIBBSD_CHECK_PROGNAME], [
|
||||||
|
AC_MSG_CHECKING([for program_invocation_short_name])
|
||||||
|
AC_LINK_IFELSE([
|
||||||
|
AC_LANG_PROGRAM([[
|
||||||
|
#include <errno.h>
|
||||||
|
]], [[
|
||||||
|
const char *p = program_invocation_short_name;
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
||||||
|
[Define to 1 if you have program_invocation_short_name])
|
||||||
|
AC_MSG_RESULT([yes])
|
||||||
|
], [
|
||||||
|
AC_MSG_RESULT([no])
|
||||||
|
])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for __progname])
|
||||||
|
AC_LINK_IFELSE([
|
||||||
|
AC_LANG_PROGRAM([[
|
||||||
|
#include <stdio.h>
|
||||||
|
extern char *__progname;
|
||||||
|
]], [[
|
||||||
|
printf("%s", __progname);
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
||||||
|
AC_MSG_RESULT([yes])
|
||||||
|
], [
|
||||||
|
AC_MSG_RESULT([no])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
|
# LIBBSD_CHECK_REGISTER_ATFORK
|
||||||
|
# ----------------------------
|
||||||
|
AC_DEFUN([LIBBSD_CHECK_REGISTER_ATFORK], [
|
||||||
|
AC_MSG_CHECKING([for __register_atfork])
|
||||||
|
AC_LINK_IFELSE([
|
||||||
|
AC_LANG_PROGRAM([[
|
||||||
|
#include <stddef.h>
|
||||||
|
extern void *__dso_handle;
|
||||||
|
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||||
|
]], [[
|
||||||
|
__register_atfork(NULL, NULL, NULL, __dso_handle);
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
|
||||||
|
[Define to 1 if you have __register_atfork])
|
||||||
|
AC_MSG_RESULT([yes])
|
||||||
|
], [
|
||||||
|
LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
|
||||||
|
AC_MSG_RESULT([no])
|
||||||
|
])
|
||||||
|
])
|
61
m4/libbsd-large.m4
Normal file
61
m4/libbsd-large.m4
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright © 2024 Guillem Jover <guillem@hadrons.org>
|
||||||
|
|
||||||
|
# LIBBSD_SYS_TIME64
|
||||||
|
# -----------------
|
||||||
|
# Check for availability of time64 support.
|
||||||
|
AC_DEFUN([LIBBSD_SYS_TIME64], [
|
||||||
|
# Check the default time_t size.
|
||||||
|
AC_CHECK_SIZEOF([time_t], [], [[
|
||||||
|
#undef _TIME_BITS
|
||||||
|
#include <time.h>
|
||||||
|
]])
|
||||||
|
AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
|
||||||
|
libbsd_sys_time_bits=64
|
||||||
|
], [
|
||||||
|
libbsd_sys_time_bits=32
|
||||||
|
])
|
||||||
|
AC_DEFINE_UNQUOTED([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits],
|
||||||
|
[The number of bits for the default system time_t ABI])
|
||||||
|
AC_SUBST([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits])
|
||||||
|
AS_UNSET([ac_cv_sizeof_time_t])
|
||||||
|
AM_CONDITIONAL([LIBBSD_SYS_IS_TIME32], [test "$libbsd_sys_time_bits" -eq 32])
|
||||||
|
|
||||||
|
# Check the whether the system supports 64-bit time_t.
|
||||||
|
AC_CHECK_SIZEOF([time_t], [], [[
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
#define _TIME_BITS 64
|
||||||
|
#include <time.h>
|
||||||
|
]])
|
||||||
|
AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
|
||||||
|
libbsd_sys_has_time64=1
|
||||||
|
], [
|
||||||
|
libbsd_sys_has_time64=0
|
||||||
|
])
|
||||||
|
AC_DEFINE_UNQUOTED([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64],
|
||||||
|
[Enable if the system supports 64-bit time_t])
|
||||||
|
AC_SUBST([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64])
|
||||||
|
AM_CONDITIONAL([LIBBSD_SYS_HAS_TIME64], [test "$libbsd_sys_has_time64" -eq 1])
|
||||||
|
AS_IF([test "$libbsd_sys_time_bits" -eq 32 && \
|
||||||
|
test "$libbsd_sys_has_time64" -eq 1], [
|
||||||
|
abi_time64=yes
|
||||||
|
], [
|
||||||
|
abi_time64=no
|
||||||
|
])
|
||||||
|
LIBBSD_SELECT_ABI([time64], [explicit time64 time_t support])
|
||||||
|
|
||||||
|
AC_CHECK_SIZEOF([off_t], [], [[
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
#include <sys/types.h>
|
||||||
|
]])
|
||||||
|
AS_IF([test $ac_cv_sizeof_off_t = 8], [
|
||||||
|
libbsd_sys_has_lfs=1
|
||||||
|
], [
|
||||||
|
libbsd_sys_has_lfs=0
|
||||||
|
])
|
||||||
|
|
||||||
|
AS_IF([test $libbsd_sys_has_lfs -eq 1 && \
|
||||||
|
test $libbsd_sys_time_bits -eq 32 && \
|
||||||
|
test $ac_cv_sizeof_time_t -eq 8], [
|
||||||
|
AC_DEFINE([_TIME_BITS], [64], [Enable 64-bit time_t support])
|
||||||
|
])
|
||||||
|
])
|
27
m4/libbsd-linker.m4
Normal file
27
m4/libbsd-linker.m4
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright © 2019, 2022 Guillem Jover <guillem@hadrons.org>
|
||||||
|
|
||||||
|
# LIBBSD_LINKER_VERSION_SCRIPT
|
||||||
|
# ----------------------------
|
||||||
|
AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
|
||||||
|
AC_CACHE_CHECK([if ld supports --version-script flag],
|
||||||
|
[libbsd_cv_version_script], [
|
||||||
|
echo "{ global: symbol; local: *; };" >conftest.map
|
||||||
|
save_LDFLAGS=$LDFLAGS
|
||||||
|
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
|
||||||
|
AC_LINK_IFELSE([
|
||||||
|
AC_LANG_PROGRAM([[
|
||||||
|
extern int symbol(void);
|
||||||
|
int symbol(void) { return 0; }
|
||||||
|
]], [[
|
||||||
|
]])
|
||||||
|
], [
|
||||||
|
libbsd_cv_version_script=yes
|
||||||
|
], [
|
||||||
|
libbsd_cv_version_script=no
|
||||||
|
])
|
||||||
|
LDFLAGS="$save_LDFLAGS"
|
||||||
|
rm -f conftest.map
|
||||||
|
])
|
||||||
|
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
|
||||||
|
[test "x$libbsd_cv_version_script" = "xyes"])
|
||||||
|
])
|
1
man/LIST_CLASS_ENTRY.3bsd
Normal file
1
man/LIST_CLASS_ENTRY.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/LIST_CLASS_HEAD.3bsd
Normal file
1
man/LIST_CLASS_HEAD.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
326
man/Makefile.am
326
man/Makefile.am
@ -2,18 +2,20 @@
|
|||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
mdX.3bsd \
|
mdX.3bsd \
|
||||||
$(nil)
|
# EOL
|
||||||
|
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
md5.3bsd \
|
md5.3bsd \
|
||||||
$(nil)
|
# EOL
|
||||||
|
|
||||||
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
|
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
|
||||||
|
|
||||||
md5.3bsd: $(srcdir)/mdX.3bsd
|
md5.3bsd: $(srcdir)/mdX.3bsd
|
||||||
$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
|
$(AM_V_GEN) $(SED) $(SED_MD5_SUBST) $< >$@
|
||||||
|
|
||||||
dist_man_MANS = \
|
dist_man_MANS = \
|
||||||
|
LIST_CLASS_ENTRY.3bsd \
|
||||||
|
LIST_CLASS_HEAD.3bsd \
|
||||||
LIST_EMPTY.3bsd \
|
LIST_EMPTY.3bsd \
|
||||||
LIST_ENTRY.3bsd \
|
LIST_ENTRY.3bsd \
|
||||||
LIST_FIRST.3bsd \
|
LIST_FIRST.3bsd \
|
||||||
@ -54,6 +56,8 @@ dist_man_MANS = \
|
|||||||
RB_REMOVE.3bsd \
|
RB_REMOVE.3bsd \
|
||||||
RB_RIGHT.3bsd \
|
RB_RIGHT.3bsd \
|
||||||
RB_ROOT.3bsd \
|
RB_ROOT.3bsd \
|
||||||
|
SLIST_CLASS_ENTRY.3bsd \
|
||||||
|
SLIST_CLASS_HEAD.3bsd \
|
||||||
SLIST_EMPTY.3bsd \
|
SLIST_EMPTY.3bsd \
|
||||||
SLIST_ENTRY.3bsd \
|
SLIST_ENTRY.3bsd \
|
||||||
SLIST_FIRST.3bsd \
|
SLIST_FIRST.3bsd \
|
||||||
@ -70,6 +74,7 @@ dist_man_MANS = \
|
|||||||
SLIST_REMOVE.3bsd \
|
SLIST_REMOVE.3bsd \
|
||||||
SLIST_REMOVE_AFTER.3bsd \
|
SLIST_REMOVE_AFTER.3bsd \
|
||||||
SLIST_REMOVE_HEAD.3bsd \
|
SLIST_REMOVE_HEAD.3bsd \
|
||||||
|
SLIST_REMOVE_PREVPTR.3bsd \
|
||||||
SLIST_SWAP.3bsd \
|
SLIST_SWAP.3bsd \
|
||||||
SPLAY_EMPTY.3bsd \
|
SPLAY_EMPTY.3bsd \
|
||||||
SPLAY_ENTRY.3bsd \
|
SPLAY_ENTRY.3bsd \
|
||||||
@ -88,6 +93,8 @@ dist_man_MANS = \
|
|||||||
SPLAY_REMOVE.3bsd \
|
SPLAY_REMOVE.3bsd \
|
||||||
SPLAY_RIGHT.3bsd \
|
SPLAY_RIGHT.3bsd \
|
||||||
SPLAY_ROOT.3bsd \
|
SPLAY_ROOT.3bsd \
|
||||||
|
STAILQ_CLASS_ENTRY.3bsd \
|
||||||
|
STAILQ_CLASS_HEAD.3bsd \
|
||||||
STAILQ_CONCAT.3bsd \
|
STAILQ_CONCAT.3bsd \
|
||||||
STAILQ_EMPTY.3bsd \
|
STAILQ_EMPTY.3bsd \
|
||||||
STAILQ_ENTRY.3bsd \
|
STAILQ_ENTRY.3bsd \
|
||||||
@ -108,6 +115,8 @@ dist_man_MANS = \
|
|||||||
STAILQ_REMOVE_AFTER.3bsd \
|
STAILQ_REMOVE_AFTER.3bsd \
|
||||||
STAILQ_REMOVE_HEAD.3bsd \
|
STAILQ_REMOVE_HEAD.3bsd \
|
||||||
STAILQ_SWAP.3bsd \
|
STAILQ_SWAP.3bsd \
|
||||||
|
TAILQ_CLASS_ENTRY.3bsd \
|
||||||
|
TAILQ_CLASS_HEAD.3bsd \
|
||||||
TAILQ_CONCAT.3bsd \
|
TAILQ_CONCAT.3bsd \
|
||||||
TAILQ_EMPTY.3bsd \
|
TAILQ_EMPTY.3bsd \
|
||||||
TAILQ_ENTRY.3bsd \
|
TAILQ_ENTRY.3bsd \
|
||||||
@ -132,13 +141,6 @@ dist_man_MANS = \
|
|||||||
TAILQ_PREV.3bsd \
|
TAILQ_PREV.3bsd \
|
||||||
TAILQ_REMOVE.3bsd \
|
TAILQ_REMOVE.3bsd \
|
||||||
TAILQ_SWAP.3bsd \
|
TAILQ_SWAP.3bsd \
|
||||||
TIMESPEC_TO_TIMEVAL.3bsd \
|
|
||||||
TIMEVAL_TO_TIMESPEC.3bsd \
|
|
||||||
arc4random.3bsd \
|
|
||||||
arc4random_addrandom.3bsd \
|
|
||||||
arc4random_buf.3bsd \
|
|
||||||
arc4random_stir.3bsd \
|
|
||||||
arc4random_uniform.3bsd \
|
|
||||||
be16dec.3bsd \
|
be16dec.3bsd \
|
||||||
be16enc.3bsd \
|
be16enc.3bsd \
|
||||||
be32dec.3bsd \
|
be32dec.3bsd \
|
||||||
@ -157,24 +159,6 @@ dist_man_MANS = \
|
|||||||
bitstr_size.3bsd \
|
bitstr_size.3bsd \
|
||||||
bitstring.3bsd \
|
bitstring.3bsd \
|
||||||
byteorder.3bsd \
|
byteorder.3bsd \
|
||||||
closefrom.3bsd \
|
|
||||||
dehumanize_number.3bsd \
|
|
||||||
errc.3bsd \
|
|
||||||
expand_number.3bsd \
|
|
||||||
explicit_bzero.3bsd \
|
|
||||||
fgetln.3bsd \
|
|
||||||
fgetwln.3bsd \
|
|
||||||
flopen.3bsd \
|
|
||||||
fmtcheck.3bsd \
|
|
||||||
fparseln.3bsd \
|
|
||||||
fpurge.3bsd \
|
|
||||||
funopen.3bsd \
|
|
||||||
getbsize.3bsd \
|
|
||||||
getmode.3bsd \
|
|
||||||
getpeereid.3bsd \
|
|
||||||
getprogname.3bsd \
|
|
||||||
heapsort.3bsd \
|
|
||||||
humanize_number.3bsd \
|
|
||||||
le16dec.3bsd \
|
le16dec.3bsd \
|
||||||
le16enc.3bsd \
|
le16enc.3bsd \
|
||||||
le32dec.3bsd \
|
le32dec.3bsd \
|
||||||
@ -182,40 +166,7 @@ dist_man_MANS = \
|
|||||||
le64dec.3bsd \
|
le64dec.3bsd \
|
||||||
le64enc.3bsd \
|
le64enc.3bsd \
|
||||||
libbsd.7 \
|
libbsd.7 \
|
||||||
md5.3bsd \
|
|
||||||
mergesort.3bsd \
|
|
||||||
nlist.3bsd \
|
|
||||||
pidfile.3bsd \
|
|
||||||
pidfile_close.3bsd \
|
|
||||||
pidfile_open.3bsd \
|
|
||||||
pidfile_remove.3bsd \
|
|
||||||
pidfile_write.3bsd \
|
|
||||||
queue.3bsd \
|
queue.3bsd \
|
||||||
radixsort.3bsd \
|
|
||||||
readpassphrase.3bsd \
|
|
||||||
reallocarray.3bsd \
|
|
||||||
reallocf.3bsd \
|
|
||||||
setmode.3bsd \
|
|
||||||
setproctitle.3bsd \
|
|
||||||
setproctitle_init.3bsd \
|
|
||||||
setprogname.3bsd \
|
|
||||||
sl_add.3bsd \
|
|
||||||
sl_delete.3bsd \
|
|
||||||
sl_find.3bsd \
|
|
||||||
sl_free.3bsd \
|
|
||||||
sl_init.3bsd \
|
|
||||||
sradixsort.3bsd \
|
|
||||||
stringlist.3bsd \
|
|
||||||
strlcat.3bsd \
|
|
||||||
strlcpy.3bsd \
|
|
||||||
strmode.3bsd \
|
|
||||||
strnstr.3bsd \
|
|
||||||
strnunvis.3bsd \
|
|
||||||
strnvis.3bsd \
|
|
||||||
strtonum.3bsd \
|
|
||||||
strunvis.3bsd \
|
|
||||||
strvis.3bsd \
|
|
||||||
strvisx.3bsd \
|
|
||||||
timeradd.3bsd \
|
timeradd.3bsd \
|
||||||
timerclear.3bsd \
|
timerclear.3bsd \
|
||||||
timercmp.3bsd \
|
timercmp.3bsd \
|
||||||
@ -226,10 +177,259 @@ dist_man_MANS = \
|
|||||||
timespeccmp.3bsd \
|
timespeccmp.3bsd \
|
||||||
timespecisset.3bsd \
|
timespecisset.3bsd \
|
||||||
timespecsub.3bsd \
|
timespecsub.3bsd \
|
||||||
timeval.3bsd \
|
|
||||||
tree.3bsd \
|
tree.3bsd \
|
||||||
|
# EOL
|
||||||
|
|
||||||
|
if API_TIME_MACROS
|
||||||
|
dist_man_MANS += \
|
||||||
|
TIMESPEC_TO_TIMEVAL.3bsd \
|
||||||
|
TIMEVAL_TO_TIMESPEC.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_ACCMODE
|
||||||
|
dist_man_MANS += \
|
||||||
|
getmode.3bsd \
|
||||||
|
setmode.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_ARC4RANDOM
|
||||||
|
dist_man_MANS += \
|
||||||
|
arc4random.3bsd \
|
||||||
|
arc4random_addrandom.3bsd \
|
||||||
|
arc4random_buf.3bsd \
|
||||||
|
arc4random_stir.3bsd \
|
||||||
|
arc4random_uniform.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_CLOSEFROM
|
||||||
|
dist_man_MANS += \
|
||||||
|
closefrom.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_ERRC
|
||||||
|
dist_man_MANS += \
|
||||||
|
errc.3bsd \
|
||||||
|
verrc.3bsd \
|
||||||
|
vwarnc.3bsd \
|
||||||
|
warnc.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_EXPAND_NUMBER
|
||||||
|
dist_man_MANS += \
|
||||||
|
expand_number.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_EXPLICIT_BZERO
|
||||||
|
dist_man_MANS += \
|
||||||
|
explicit_bzero.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FGETLN
|
||||||
|
dist_man_MANS += \
|
||||||
|
fgetln.3bsd \
|
||||||
|
fgetwln.3bsd \
|
||||||
|
fparseln.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FLOPEN
|
||||||
|
dist_man_MANS += \
|
||||||
|
flopen.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FMTCHECK
|
||||||
|
dist_man_MANS += \
|
||||||
|
fmtcheck.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FPURGE
|
||||||
|
dist_man_MANS += \
|
||||||
|
fpurge.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FREEZERO
|
||||||
|
dist_man_MANS += \
|
||||||
|
freezero.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_FUNOPEN
|
||||||
|
dist_man_MANS += \
|
||||||
|
funopen.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_GETBSIZE
|
||||||
|
dist_man_MANS += \
|
||||||
|
getbsize.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_GETPEEREID
|
||||||
|
dist_man_MANS += \
|
||||||
|
getpeereid.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_HUMANIZE_NUMBER
|
||||||
|
dist_man_MANS += \
|
||||||
|
dehumanize_number.3bsd \
|
||||||
|
humanize_number.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_MD5
|
||||||
|
dist_man_MANS += \
|
||||||
|
md5.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_NLIST
|
||||||
|
dist_man_MANS += \
|
||||||
|
nlist.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_PIDFILE
|
||||||
|
dist_man_MANS += \
|
||||||
|
pidfile.3bsd \
|
||||||
|
pidfile_close.3bsd \
|
||||||
|
pidfile_open.3bsd \
|
||||||
|
pidfile_remove.3bsd \
|
||||||
|
pidfile_write.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_PROCTITLE
|
||||||
|
dist_man_MANS += \
|
||||||
|
setproctitle.3bsd \
|
||||||
|
setproctitle_init.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_PROGNAME
|
||||||
|
dist_man_MANS += \
|
||||||
|
getprogname.3bsd \
|
||||||
|
setprogname.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_PWCACHE
|
||||||
|
dist_man_MANS += \
|
||||||
|
pwcache.3bsd \
|
||||||
|
gid_from_group.3bsd \
|
||||||
|
uid_from_user.3bsd \
|
||||||
|
# EOL
|
||||||
|
|
||||||
|
if ABI_NAME_FROM_ID
|
||||||
|
dist_man_MANS += \
|
||||||
|
group_from_gid.3bsd \
|
||||||
|
user_from_uid.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_READPASSPHRASE
|
||||||
|
dist_man_MANS += \
|
||||||
|
readpassphrase.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_REALLOCARRAY
|
||||||
|
dist_man_MANS += \
|
||||||
|
reallocarray.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_REALLOCF
|
||||||
|
dist_man_MANS += \
|
||||||
|
reallocf.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_RECALLOCARRAY
|
||||||
|
dist_man_MANS += \
|
||||||
|
recallocarray.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_SORT
|
||||||
|
dist_man_MANS += \
|
||||||
|
heapsort.3bsd \
|
||||||
|
mergesort.3bsd \
|
||||||
|
radixsort.3bsd \
|
||||||
|
sradixsort.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRINGLIST
|
||||||
|
dist_man_MANS += \
|
||||||
|
sl_add.3bsd \
|
||||||
|
sl_delete.3bsd \
|
||||||
|
sl_find.3bsd \
|
||||||
|
sl_free.3bsd \
|
||||||
|
sl_init.3bsd \
|
||||||
|
stringlist.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRL
|
||||||
|
dist_man_MANS += \
|
||||||
|
strlcat.3bsd \
|
||||||
|
strlcpy.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRMODE
|
||||||
|
dist_man_MANS += \
|
||||||
|
strmode.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRNSTR
|
||||||
|
dist_man_MANS += \
|
||||||
|
strnstr.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRTOX
|
||||||
|
dist_man_MANS += \
|
||||||
|
strtoi.3bsd \
|
||||||
|
strtou.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_STRTONUM
|
||||||
|
dist_man_MANS += \
|
||||||
|
strtonum.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_VIS
|
||||||
|
dist_man_MANS += \
|
||||||
|
strnunvis.3bsd \
|
||||||
|
strnvis.3bsd \
|
||||||
|
strunvis.3bsd \
|
||||||
|
strvis.3bsd \
|
||||||
|
strvisx.3bsd \
|
||||||
unvis.3bsd \
|
unvis.3bsd \
|
||||||
vis.3bsd \
|
vis.3bsd \
|
||||||
|
# EOL
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ABI_WCSL
|
||||||
|
dist_man_MANS += \
|
||||||
wcslcat.3bsd \
|
wcslcat.3bsd \
|
||||||
wcslcpy.3bsd \
|
wcslcpy.3bsd \
|
||||||
$(nil)
|
# EOL
|
||||||
|
endif
|
||||||
|
1
man/SLIST_CLASS_ENTRY.3bsd
Normal file
1
man/SLIST_CLASS_ENTRY.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/SLIST_CLASS_HEAD.3bsd
Normal file
1
man/SLIST_CLASS_HEAD.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/SLIST_REMOVE_PREVPTR.3bsd
Normal file
1
man/SLIST_REMOVE_PREVPTR.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/STAILQ_CLASS_ENTRY.3bsd
Normal file
1
man/STAILQ_CLASS_ENTRY.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/STAILQ_CLASS_HEAD.3bsd
Normal file
1
man/STAILQ_CLASS_HEAD.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/TAILQ_CLASS_ENTRY.3bsd
Normal file
1
man/TAILQ_CLASS_ENTRY.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
1
man/TAILQ_CLASS_HEAD.3bsd
Normal file
1
man/TAILQ_CLASS_HEAD.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/queue.3bsd
|
@ -1 +1,100 @@
|
|||||||
.so man3/timeval.3bsd
|
.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
.\" by Jukka Ruohonen.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.Dd April 12, 2011
|
||||||
|
.Dt TIMEVAL_TO_TIMESPEC 3bsd
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm TIMEVAL_TO_TIMESPEC ,
|
||||||
|
.Nm TIMESPEC_TO_TIMEVAL
|
||||||
|
.Nd time structures conversion macros
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In sys/time.h
|
||||||
|
(See
|
||||||
|
.Xr libbsd 7
|
||||||
|
for include usage.)
|
||||||
|
.Ft void
|
||||||
|
.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
|
||||||
|
.Ft void
|
||||||
|
.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Va timeval
|
||||||
|
structure represents elapsed time, in whole seconds,
|
||||||
|
and the rest of the elapsed time in microseconds.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Va timespec
|
||||||
|
structure represents elapsed time, in whole seconds,
|
||||||
|
and the rest of the elapsed time in nanoseconds.
|
||||||
|
.Pp
|
||||||
|
A microsecond is equal to one millionth of a second,
|
||||||
|
1000 nanoseconds, or 1/1000 milliseconds.
|
||||||
|
To ease the conversions, the macros
|
||||||
|
.Fn TIMEVAL_TO_TIMESPEC
|
||||||
|
and
|
||||||
|
.Fn TIMESPEC_TO_TIMEVAL
|
||||||
|
can be used to convert between
|
||||||
|
.Em struct timeval
|
||||||
|
and
|
||||||
|
.Em struct timespec .
|
||||||
|
.Sh EXAMPLES
|
||||||
|
It can be stressed that the traditional
|
||||||
|
.Tn UNIX
|
||||||
|
.Va timeval
|
||||||
|
and
|
||||||
|
.Va timespec
|
||||||
|
structures represent elapsed time, measured by the system clock.
|
||||||
|
The following sketch implements a function suitable
|
||||||
|
for use in a context where the
|
||||||
|
.Va timespec
|
||||||
|
structure is required for a conditional timeout:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
static void
|
||||||
|
example(struct timespec *spec, time_t minutes)
|
||||||
|
{
|
||||||
|
struct timeval elapsed;
|
||||||
|
|
||||||
|
(void)gettimeofday(&elapsed, NULL);
|
||||||
|
|
||||||
|
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
|
||||||
|
|
||||||
|
/* Add the offset for timeout in minutes. */
|
||||||
|
spec->tv_sec = spec->tv_sec + minutes * 60;
|
||||||
|
}
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
A better alternative would use the more precise
|
||||||
|
.Xr clock_gettime 2 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr timeradd 3bsd
|
||||||
|
@ -1 +1 @@
|
|||||||
.so man3/timeval.3bsd
|
.so man3/TIMESPEC_TO_TIMEVAL.3bsd
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
.\" $OpenBSD: arc4random.3,v 1.34 2014/07/19 16:11:16 naddy Exp $
|
.\" $NetBSD: arc4random.3,v 1.21 2016/07/15 21:19:19 wiz Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
.\" Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
.\" by Taylor R. Campbell.
|
||||||
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
.\" are met:
|
.\" are met:
|
||||||
@ -11,37 +14,32 @@
|
|||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
.\" 3. All advertising materials mentioning features or use of this software
|
|
||||||
.\" must display the following acknowledgement:
|
|
||||||
.\" This product includes software developed by Niels Provos.
|
|
||||||
.\" 4. The name of the author may not be used to endorse or promote products
|
|
||||||
.\" derived from this software without specific prior written permission.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" Manual page, using -mandoc macros
|
.Dd November 16, 2014
|
||||||
.\"
|
.Dt arc4random 3bsd
|
||||||
.Dd $Mdocdate: July 19 2014 $
|
|
||||||
.Dt ARC4RANDOM 3bsd
|
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm arc4random ,
|
.Nm arc4random ,
|
||||||
.Nm arc4random_buf ,
|
|
||||||
.Nm arc4random_uniform ,
|
.Nm arc4random_uniform ,
|
||||||
|
.Nm arc4random_buf ,
|
||||||
.Nm arc4random_stir ,
|
.Nm arc4random_stir ,
|
||||||
.Nm arc4random_addrandom
|
.Nm arc4random_addrandom
|
||||||
.Nd arc4 random number generator
|
.Nd random number generator
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
@ -50,83 +48,208 @@
|
|||||||
for include usage.)
|
for include usage.)
|
||||||
.Ft uint32_t
|
.Ft uint32_t
|
||||||
.Fn arc4random "void"
|
.Fn arc4random "void"
|
||||||
.Ft void
|
|
||||||
.Fn arc4random_buf "void *buf" "size_t nbytes"
|
|
||||||
.Ft uint32_t
|
.Ft uint32_t
|
||||||
.Fn arc4random_uniform "uint32_t upper_bound"
|
.Fn arc4random_uniform "uint32_t bound"
|
||||||
|
.Ft void
|
||||||
|
.Fn arc4random_buf "void *buf" "size_t len"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn arc4random_stir "void"
|
.Fn arc4random_stir "void"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn arc4random_addrandom "unsigned char *dat" "int datlen"
|
.Fn arc4random_addrandom "unsigned char *buf" "int len"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
This family of functions provides higher quality data than those
|
The
|
||||||
described in
|
.Nm
|
||||||
.Xr rand 3 ,
|
family of functions provides a cryptographic pseudorandom number
|
||||||
|
generator automatically seeded from the system entropy pool and safe to
|
||||||
|
use from multiple threads.
|
||||||
|
.Nm
|
||||||
|
is designed to prevent an adversary from guessing outputs,
|
||||||
|
unlike
|
||||||
|
.Xr rand 3
|
||||||
|
and
|
||||||
.Xr random 3 ,
|
.Xr random 3 ,
|
||||||
and
|
and is faster and more convenient than reading from
|
||||||
.Xr rand48 3 .
|
.Pa /dev/urandom
|
||||||
|
directly.
|
||||||
.Pp
|
.Pp
|
||||||
Use of these functions is encouraged for almost all random number
|
|
||||||
consumption because the other interfaces are deficient in either
|
|
||||||
quality, portability, standardization, or availability.
|
|
||||||
These functions can be called in almost all coding environments,
|
|
||||||
including
|
|
||||||
.Xr pthreads 3
|
|
||||||
and
|
|
||||||
.Xr chroot 2 .
|
|
||||||
.Pp
|
|
||||||
High quality 32-bit pseudo-random numbers are generated very quickly.
|
|
||||||
On each call, a cryptographic pseudo-random number generator is used
|
|
||||||
to generate a new result.
|
|
||||||
One data pool is used for all consumers in a process, so that consumption
|
|
||||||
under program flow can act as additional stirring.
|
|
||||||
The subsystem is re-seeded from the kernel random number subsystem using
|
|
||||||
.Xr getentropy 2
|
|
||||||
on a regular basis, and also upon
|
|
||||||
.Xr fork 2 .
|
|
||||||
.Pp
|
|
||||||
The
|
|
||||||
.Fn arc4random
|
.Fn arc4random
|
||||||
function returns a single 32-bit value.
|
returns an integer in [0, 2^32) chosen independently with uniform
|
||||||
.Pp
|
distribution.
|
||||||
The
|
|
||||||
.Fn arc4random_buf
|
|
||||||
function fills the region
|
|
||||||
.Fa buf
|
|
||||||
of length
|
|
||||||
.Fa nbytes
|
|
||||||
with random data.
|
|
||||||
.Pp
|
.Pp
|
||||||
.Fn arc4random_uniform
|
.Fn arc4random_uniform
|
||||||
will return a single 32-bit value, uniformly distributed but less than
|
returns an integer in [0,
|
||||||
.Fa upper_bound .
|
.Fa bound )
|
||||||
This is recommended over constructions like
|
chosen independently with uniform distribution.
|
||||||
.Dq Li arc4random() % upper_bound
|
|
||||||
as it avoids "modulo bias" when the upper bound is not a power of two.
|
|
||||||
In the worst case, this function may consume multiple iterations
|
|
||||||
to ensure uniformity; see the source code to understand the problem
|
|
||||||
and solution.
|
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fn arc4random_buf
|
||||||
|
stores
|
||||||
|
.Fa len
|
||||||
|
bytes into the memory pointed to by
|
||||||
|
.Fa buf ,
|
||||||
|
each byte chosen independently from [0, 256) with uniform
|
||||||
|
distribution.
|
||||||
|
.Pp
|
||||||
|
.Fn arc4random_stir
|
||||||
|
draws entropy from the operating system and incorporates it into the
|
||||||
|
library's PRNG state to influence future outputs.
|
||||||
|
.Pp
|
||||||
|
.Fn arc4random_addrandom
|
||||||
|
incorporates
|
||||||
|
.Fa len
|
||||||
|
bytes, which must be nonnegative, from the buffer
|
||||||
|
.Fa buf ,
|
||||||
|
into the library's PRNG state to influence future outputs.
|
||||||
|
.Pp
|
||||||
|
It is not necessary for an application to call
|
||||||
|
.Fn arc4random_stir
|
||||||
|
or
|
||||||
|
.Fn arc4random_addrandom
|
||||||
|
before calling other
|
||||||
|
.Nm
|
||||||
|
functions.
|
||||||
|
The first call to any
|
||||||
|
.Nm
|
||||||
|
function will initialize the PRNG state unpredictably from the system
|
||||||
|
entropy pool.
|
||||||
|
.Sh SECURITY MODEL
|
||||||
The
|
The
|
||||||
.Fn arc4random_stir
|
.Nm
|
||||||
function reads data from
|
functions provide the following security properties against three
|
||||||
.Xr getentropy 2
|
different classes of attackers, assuming enough entropy is provided by
|
||||||
and uses it to re-seed the subsystem via
|
the operating system:
|
||||||
.Fn arc4random_addrandom .
|
.Bl -enum -offset abcd
|
||||||
|
.It
|
||||||
|
An attacker who has seen some outputs of any of the
|
||||||
|
.Nm
|
||||||
|
functions cannot predict past or future unseen outputs.
|
||||||
|
.It
|
||||||
|
An attacker who has seen the library's PRNG state in memory cannot
|
||||||
|
predict past outputs.
|
||||||
|
.It
|
||||||
|
An attacker who has seen one process's PRNG state cannot predict past
|
||||||
|
or future outputs in other processes, particularly its parent or
|
||||||
|
siblings.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
One
|
||||||
|
.Sq output
|
||||||
|
means the result of any single request to an
|
||||||
|
.Nm
|
||||||
|
function, no matter how short it is.
|
||||||
|
.Pp
|
||||||
|
The second property is sometimes called
|
||||||
|
.Sq forward secrecy ,
|
||||||
|
.Sq backtracking resistance ,
|
||||||
|
or
|
||||||
|
.Sq key erasure after each output .
|
||||||
|
.Sh IMPLEMENTATION NOTES
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
functions are currently implemented using the ChaCha20 pseudorandom
|
||||||
|
function family.
|
||||||
|
For any 32-byte string
|
||||||
|
.Fa s ,
|
||||||
|
.Pf ChaCha20_ Fa s
|
||||||
|
is a function from 16-byte strings to 64-byte strings.
|
||||||
|
It is conjectured that if
|
||||||
|
.Fa s
|
||||||
|
is chosen with uniform distribution, then the distribution on
|
||||||
|
.Pf ChaCha20_ Fa s
|
||||||
|
is indistinguishable to a computationally bounded adversary from a
|
||||||
|
uniform distribution on all functions from 16-byte strings to 64-byte
|
||||||
|
strings.
|
||||||
|
.Pp
|
||||||
|
The PRNG state is a 32-byte ChaCha20 key
|
||||||
|
.Fa s .
|
||||||
|
Each request to
|
||||||
|
an
|
||||||
|
.Nm
|
||||||
|
function
|
||||||
|
.Bl -bullet -offset abcd -compact
|
||||||
|
.It
|
||||||
|
computes the 64-byte quantity
|
||||||
|
.Fa x
|
||||||
|
=
|
||||||
|
.Pf ChaCha20_ Fa s Ns Pq 0 ,
|
||||||
|
.It
|
||||||
|
splits
|
||||||
|
.Fa x
|
||||||
|
into two 32-byte quantities
|
||||||
|
.Fa s'
|
||||||
|
and
|
||||||
|
.Fa k ,
|
||||||
|
.It
|
||||||
|
replaces
|
||||||
|
.Fa s
|
||||||
|
by
|
||||||
|
.Fa s' ,
|
||||||
|
and
|
||||||
|
.It
|
||||||
|
uses
|
||||||
|
.Fa k
|
||||||
|
as output.
|
||||||
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
There is no need to call
|
|
||||||
.Fn arc4random_stir
|
|
||||||
before using
|
|
||||||
.Fn arc4random
|
.Fn arc4random
|
||||||
functions family, since
|
yields the first four bytes of
|
||||||
they automatically initialize themselves.
|
.Fa k
|
||||||
.Sh RETURN VALUES
|
as output directly.
|
||||||
These functions are always successful, and no return value is
|
.Fn arc4random_buf
|
||||||
reserved to indicate an error.
|
either yields up to 32 bytes of
|
||||||
|
.Fa k
|
||||||
|
as output directly, or, for longer
|
||||||
|
requests, uses
|
||||||
|
.Fa k
|
||||||
|
as a ChaCha20 key and yields the concatenation
|
||||||
|
.Pf ChaCha20_ Fa k Ns Pq 0
|
||||||
|
||
|
||||||
|
.Pf ChaCha20_ Fa k Ns Pq 1
|
||||||
|
|| ... as output.
|
||||||
|
.Fn arc4random_uniform
|
||||||
|
repeats
|
||||||
|
.Fn arc4random
|
||||||
|
until it obtains an integer in [2^32 %
|
||||||
|
.Fa bound ,
|
||||||
|
2^32), and reduces that modulo
|
||||||
|
.Fa bound .
|
||||||
|
.Pp
|
||||||
|
The PRNG state is per-thread, unless memory allocation fails inside the
|
||||||
|
library, in which case some threads may share global PRNG state with a
|
||||||
|
mutex.
|
||||||
|
The global PRNG state is zeroed on fork in the parent via
|
||||||
|
.Xr pthread_atfork 3 ,
|
||||||
|
and the per-thread PRNG state is zeroed on fork in the child via
|
||||||
|
.Xr minherit 2
|
||||||
|
with
|
||||||
|
.Dv MAP_INHERIT_ZERO ,
|
||||||
|
so that the child cannot reuse or see the parent's PRNG state.
|
||||||
|
The PRNG state is reseeded automatically from the system entropy pool
|
||||||
|
on the first use of an
|
||||||
|
.Nm
|
||||||
|
function after zeroing.
|
||||||
|
.Pp
|
||||||
|
The first use of an
|
||||||
|
.Nm
|
||||||
|
function may abort the process in the highly unlikely event that
|
||||||
|
library initialization necessary to implement the security model fails.
|
||||||
|
Additionally,
|
||||||
|
.Fn arc4random_stir
|
||||||
|
and
|
||||||
|
.Fn arc4random_addrandom
|
||||||
|
may abort the process in the highly unlikely event that the operating
|
||||||
|
system fails to provide entropy.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rand 3 ,
|
.Xr rand 3 ,
|
||||||
.Xr rand48 3 ,
|
.Xr random 3 ,
|
||||||
.Xr random 3
|
.Xr rnd 4 ,
|
||||||
|
.Xr cprng 9
|
||||||
|
.Rs
|
||||||
|
.%A Daniel J. Bernstein
|
||||||
|
.%T ChaCha, a variant of Salsa20
|
||||||
|
.%D 2008-01-28
|
||||||
|
.%O Document ID: 4027b5256e17b9796842e6d0f68b0b5e
|
||||||
|
.%U http://cr.yp.to/papers.html#chacha
|
||||||
|
.Re
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
These functions first appeared in
|
These functions first appeared in
|
||||||
.Ox 2.1 ,
|
.Ox 2.1 ,
|
||||||
@ -134,12 +257,85 @@ These functions first appeared in
|
|||||||
.Nx 1.6 ,
|
.Nx 1.6 ,
|
||||||
and
|
and
|
||||||
.Dx 1.0 .
|
.Dx 1.0 .
|
||||||
|
The functions
|
||||||
|
.Fn arc4random ,
|
||||||
|
.Fn arc4random_buf
|
||||||
|
and
|
||||||
|
.Fn arc4random_uniform
|
||||||
|
appeared in glibc 2.36.
|
||||||
|
.Sh BUGS
|
||||||
|
There is no way to get deterministic, reproducible results out of
|
||||||
|
.Nm
|
||||||
|
for testing purposes.
|
||||||
.Pp
|
.Pp
|
||||||
The original version of this random number generator used the
|
The name
|
||||||
RC4 (also known as ARC4) algorithm.
|
.Sq arc4random
|
||||||
In
|
was chosen for hysterical raisins -- it was originally implemented
|
||||||
.Ox 5.5
|
using the RC4 stream cipher, which has been known since shortly after
|
||||||
it was replaced with the ChaCha20 cipher, and it may be replaced
|
it was published in 1994 to have observable biases in the output, and
|
||||||
again in the future as cryptographic techniques advance.
|
is now known to be broken badly enough to admit practical attacks in
|
||||||
A good mnemonic is
|
the real world.
|
||||||
.Dq A Replacement Call for Random .
|
.\" Bob Jenkins, sci.crypt post dated 1994-09-16, message-id
|
||||||
|
.\" <359qjg$55v$1@mhadg.production.compuserve.com>,
|
||||||
|
.\" https://groups.google.com/d/msg/sci.crypt/JsO3xEATGFA/-wO4ttv7BCYJ
|
||||||
|
.\"
|
||||||
|
.\" Andrew Roos, `A Class of Weak Keys in the RC4 Stream Cipher',
|
||||||
|
.\" sci.crypt posts dated 1995-09-22, message-ids
|
||||||
|
.\" <43u1eh$1j3@hermes.is.co.za> and <44ebge$llf@hermes.is.co.za>.
|
||||||
|
.\"
|
||||||
|
.\" Paul Crowley, `Small bias in RC4 experimentally verified', March
|
||||||
|
.\" 1998, http://www.ciphergoth.org/crypto/rc4/
|
||||||
|
Unfortunately, the library found widespread adoption and the name stuck
|
||||||
|
before anyone recognized that it was silly.
|
||||||
|
.Pp
|
||||||
|
The signature of
|
||||||
|
.Fn arc4random_addrandom
|
||||||
|
is silly.
|
||||||
|
There is no reason to require casts or accept negative lengths:
|
||||||
|
it should take a
|
||||||
|
.Vt void *
|
||||||
|
buffer and a
|
||||||
|
.Vt size_t
|
||||||
|
length.
|
||||||
|
But it's too late to change that now.
|
||||||
|
.Pp
|
||||||
|
.Fn arc4random_uniform
|
||||||
|
does not help to choose integers in [0,
|
||||||
|
.Fa n )
|
||||||
|
uniformly at random when
|
||||||
|
.Fa n
|
||||||
|
> 2^32.
|
||||||
|
.Pp
|
||||||
|
The security model of
|
||||||
|
.Nm
|
||||||
|
is stronger than many applications need, and stronger than other
|
||||||
|
operating systems provide.
|
||||||
|
For example, applications encrypting messages with random, but not
|
||||||
|
secret, initialization vectors need only prevent an adversary from
|
||||||
|
guessing future outputs, since past outputs will have been published
|
||||||
|
already.
|
||||||
|
.Pp
|
||||||
|
On the one hand,
|
||||||
|
.Nm
|
||||||
|
could be marginally faster if it were not necessary to prevent an
|
||||||
|
adversary who sees the state from predicting past outputs.
|
||||||
|
On the other hand, there are applications in the wild that use
|
||||||
|
.Nm
|
||||||
|
to generate key material, such as OpenSSH, so for the sake of
|
||||||
|
.Nx
|
||||||
|
users it would be imprudent to weaken the security model.
|
||||||
|
On the third hand, relying on the security model of
|
||||||
|
.Nm
|
||||||
|
in
|
||||||
|
.Nx
|
||||||
|
may lead you to an unpleasant surprise on another operating system
|
||||||
|
whose implementation of
|
||||||
|
.Nm
|
||||||
|
has a weaker security model.
|
||||||
|
.Pp
|
||||||
|
One may be tempted to create new APIs to accommodate different
|
||||||
|
security models and performance constraints without unpleasant
|
||||||
|
surprises on different operating systems.
|
||||||
|
This should not be done lightly, though, because there are already too
|
||||||
|
many different choices, and too many opportunities for programmers to
|
||||||
|
reach for one and pick the wrong one.
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 19, 1993
|
.Dd July 19, 1993
|
||||||
.Dt BITSTRING 3bsd
|
.Dt bitstring 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm bit_alloc ,
|
.Nm bit_alloc ,
|
||||||
@ -44,6 +44,10 @@
|
|||||||
.Nm bitstr_size ,
|
.Nm bitstr_size ,
|
||||||
.Nm bit_test
|
.Nm bit_test
|
||||||
.Nd bit-string manipulation macros
|
.Nd bit-string manipulation macros
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In bitstring.h
|
.In bitstring.h
|
||||||
(See
|
(See
|
||||||
|
@ -25,12 +25,16 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd April 29, 2002
|
.Dd April 29, 2002
|
||||||
.Dt BYTEORDER 3bsd
|
.Dt byteorder 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
|
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
|
||||||
.Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec
|
.Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec
|
||||||
.Nd byte order operations
|
.Nd byte order operations
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/endian.h
|
.In sys/endian.h
|
||||||
(See
|
(See
|
||||||
|
@ -26,13 +26,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 12, 2009
|
.Dd June 12, 2009
|
||||||
.Dt CLOSEFROM 3bsd
|
.Dt closefrom 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm closefrom
|
.Nm closefrom
|
||||||
.Nd delete open file descriptors
|
.Nd delete open file descriptors
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In unistd.h
|
.In unistd.h
|
||||||
@ -50,8 +51,17 @@ from the per-process object reference table.
|
|||||||
Any errors encountered while closing file descriptors are ignored.
|
Any errors encountered while closing file descriptors are ignored.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr close 2
|
.Xr close 2
|
||||||
|
.Sh STANDARDS
|
||||||
|
.Fn closefrom
|
||||||
|
is a
|
||||||
|
.Bx
|
||||||
|
and Solaris extension.
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Fn closefrom
|
.Fn closefrom
|
||||||
function first appeared in
|
function first appeared in Solaris 9,
|
||||||
.Fx 8.0 .
|
.Ox 3.5 ,
|
||||||
|
.Dx 1.2 ,
|
||||||
|
.Nx 3.0 ,
|
||||||
|
.Fx 8.0
|
||||||
|
and glibc 2.34.
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: April 23 2014 $
|
.Dd $Mdocdate: April 23 2014 $
|
||||||
.Dt ERRC 3bsd
|
.Dt errc 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm errc ,
|
.Nm errc ,
|
||||||
@ -38,6 +38,7 @@
|
|||||||
.Nd formatted error messages
|
.Nd formatted error messages
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In err.h
|
.In err.h
|
||||||
@ -144,6 +145,7 @@ if ((fd = open(block_device, O_RDONLY, 0)) == -1)
|
|||||||
.Xr printf 3 ,
|
.Xr printf 3 ,
|
||||||
.Xr strerror 3
|
.Xr strerror 3
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||||
The functions
|
The functions
|
||||||
.Fn errc ,
|
.Fn errc ,
|
||||||
.Fn verrc ,
|
.Fn verrc ,
|
||||||
|
@ -26,13 +26,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd August 15, 2010
|
.Dd August 15, 2010
|
||||||
.Dt EXPAND_NUMBER 3bsd
|
.Dt expand_number 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm expand_number
|
.Nm expand_number
|
||||||
.Nd format a number from human readable form
|
.Nd format a number from human readable form
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In libutil.h
|
.In libutil.h
|
||||||
|
@ -30,13 +30,14 @@
|
|||||||
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
|
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: January 22 2014 $
|
.Dd $Mdocdate: January 22 2014 $
|
||||||
.Dt EXPLICIT_BZERO 3bsd
|
.Dt explicit_bzero 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm explicit_bzero
|
.Nm explicit_bzero
|
||||||
.Nd write zeroes to a byte string
|
.Nd write zeroes to a byte string
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In string.h
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
|
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 19, 1994
|
.Dd April 19, 1994
|
||||||
.Dt FGETLN 3bsd
|
.Dt fgetln 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fgetln
|
.Nm fgetln
|
||||||
.Nd get a line from a stream
|
.Nd get a line from a stream
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 16, 2004
|
.Dd July 16, 2004
|
||||||
.Dt FGETWLN 3bsd
|
.Dt fgetwln 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fgetwln
|
.Nm fgetwln
|
||||||
.Nd get a line of wide characters from a stream
|
.Nd get a line of wide characters from a stream
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
|
@ -25,14 +25,16 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 6, 2009
|
.Dd July 28, 2017
|
||||||
.Dt FLOPEN 3bsd
|
.Dt flopen 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm flopen
|
.Nm flopen ,
|
||||||
.Nd reliably open and lock a file
|
.Nm flopenat
|
||||||
|
.Nd "Reliably open and lock a file"
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/fcntl.h
|
.In sys/fcntl.h
|
||||||
@ -44,6 +46,10 @@ for include usage.)
|
|||||||
.Fn flopen "const char *path" "int flags"
|
.Fn flopen "const char *path" "int flags"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn flopen "const char *path" "int flags" "mode_t mode"
|
.Fn flopen "const char *path" "int flags" "mode_t mode"
|
||||||
|
.Ft int
|
||||||
|
.Fn flopenat "int fd" "const char *path" "int flags"
|
||||||
|
.Ft int
|
||||||
|
.Fn flopenat "int fd" "const char *path" "int flags" "mode_t mode"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn flopen
|
.Fn flopen
|
||||||
@ -53,7 +59,7 @@ It is essentially equivalent with calling
|
|||||||
with the same parameters followed by
|
with the same parameters followed by
|
||||||
.Fn flock
|
.Fn flock
|
||||||
with an
|
with an
|
||||||
.Va operation
|
.Fa operation
|
||||||
argument of
|
argument of
|
||||||
.Dv LOCK_EX ,
|
.Dv LOCK_EX ,
|
||||||
except that
|
except that
|
||||||
@ -65,7 +71,7 @@ files, mailboxes and other kinds of files which are used for
|
|||||||
synchronization between processes.
|
synchronization between processes.
|
||||||
.Pp
|
.Pp
|
||||||
If
|
If
|
||||||
.Va flags
|
.Fa flags
|
||||||
includes
|
includes
|
||||||
.Dv O_NONBLOCK
|
.Dv O_NONBLOCK
|
||||||
and the file is already locked,
|
and the file is already locked,
|
||||||
@ -78,11 +84,32 @@ to
|
|||||||
As with
|
As with
|
||||||
.Fn open ,
|
.Fn open ,
|
||||||
the additional
|
the additional
|
||||||
.Va mode
|
.Fa mode
|
||||||
argument is required if
|
argument is required if
|
||||||
.Va flags
|
.Fa flags
|
||||||
includes
|
includes
|
||||||
.Dv O_CREAT .
|
.Dv O_CREAT .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn flopenat
|
||||||
|
function is equivalent to the
|
||||||
|
.Fn flopen
|
||||||
|
function except in the case where the
|
||||||
|
.Fa path
|
||||||
|
specifies a relative path.
|
||||||
|
In this case the file to be opened is determined relative to the directory
|
||||||
|
associated with the file descriptor
|
||||||
|
.Fa fd
|
||||||
|
instead of the current working directory.
|
||||||
|
If
|
||||||
|
.Fn flopenat
|
||||||
|
is passed the special value
|
||||||
|
.Dv AT_FDCWD
|
||||||
|
in the
|
||||||
|
.Fa fd
|
||||||
|
parameter, the current working directory is used
|
||||||
|
and the behavior is identical to a call to
|
||||||
|
.Fn flopen .
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
If successful,
|
If successful,
|
||||||
.Fn flopen
|
.Fn flopen
|
||||||
@ -102,4 +129,4 @@ and
|
|||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
function and this manual page were written by
|
function and this manual page were written by
|
||||||
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
|
.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
.\" $NetBSD: fmtcheck.3,v 1.8 2014/06/14 08:18:24 apb Exp $
|
||||||
|
.\"
|
||||||
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
|
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
@ -24,17 +26,15 @@
|
|||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $
|
.Dd June 14, 2014
|
||||||
.Dd October 16, 2002
|
.Dt fmtcheck 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Dt FMTCHECK 3bsd
|
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fmtcheck
|
.Nm fmtcheck
|
||||||
.Nd sanitizes user-supplied
|
.Nd sanitizes user-supplied printf(3)-style format string
|
||||||
.Xr printf 3 Ns -style
|
|
||||||
format string
|
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
@ -45,8 +45,8 @@ for include usage.)
|
|||||||
.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
|
.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn fmtcheck
|
.Nm
|
||||||
scans
|
function scans
|
||||||
.Fa fmt_suspect
|
.Fa fmt_suspect
|
||||||
and
|
and
|
||||||
.Fa fmt_default
|
.Fa fmt_default
|
||||||
@ -60,55 +60,45 @@ is a valid format string.
|
|||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Xr printf 3
|
.Xr printf 3
|
||||||
family of functions cannot verify the types of arguments that they are
|
family of functions can not verify the types of arguments that they are
|
||||||
passed at run-time.
|
passed at run-time.
|
||||||
In some cases, like
|
In some cases, like
|
||||||
.Xr catgets 3 ,
|
.Xr catgets 3 ,
|
||||||
it is useful or necessary to use a user-supplied format string with no
|
it is useful or necessary to use a user-supplied format string with no
|
||||||
guarantee that the format string matches the specified arguments.
|
guarantee that the format string matches the specified parameters.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn fmtcheck
|
.Nm
|
||||||
was designed to be used in these cases, as in:
|
function was designed to be used in these cases, as in:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
printf(fmtcheck(user_format, standard_format), arg1, arg2);
|
printf(fmtcheck(user_format, standard_format), arg1, arg2);
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In the check, field widths, fillers, precisions, etc.\& are ignored (unless
|
In the check, field widths, fillers, precisions, etc. are ignored (unless
|
||||||
the field width or precision is an asterisk
|
the field width or precision is an asterisk
|
||||||
.Ql *
|
.Ql *
|
||||||
instead of a digit string).
|
instead of a digit string).
|
||||||
Also, any text other than the format specifiers
|
Also, any text other than the format specifiers is completely ignored.
|
||||||
is completely ignored.
|
.Pp
|
||||||
|
Note that the formats may be quite different as long as they accept the
|
||||||
|
same parameters.
|
||||||
|
For example, "%ld %o %30s %#llx %-10.*e %n" is
|
||||||
|
compatible with "This number %lu %d%% and string %s has %qd numbers
|
||||||
|
and %.*g floats (%n)."
|
||||||
|
However, "%o" is not equivalent to "%lx" because
|
||||||
|
the first requires an integer and the second requires a long,
|
||||||
|
and "%p" is not equivalent to "%lu" because
|
||||||
|
the first requires a pointer and the second requires a long.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
If
|
If
|
||||||
.Fa fmt_suspect
|
.Fa fmt_suspect
|
||||||
is a valid format and consumes the same argument types as
|
is a valid format and consumes the same argument types as
|
||||||
.Fa fmt_default ,
|
.Fa fmt_default ,
|
||||||
then the
|
then the
|
||||||
.Fn fmtcheck
|
.Nm
|
||||||
will return
|
function will return
|
||||||
.Fa fmt_suspect .
|
.Fa fmt_suspect .
|
||||||
Otherwise, it will return
|
Otherwise, it will return
|
||||||
.Fa fmt_default .
|
.Fa fmt_default .
|
||||||
.Sh SECURITY CONSIDERATIONS
|
|
||||||
Note that the formats may be quite different as long as they accept the
|
|
||||||
same arguments.
|
|
||||||
For example,
|
|
||||||
.Qq Li "%p %o %30s %#llx %-10.*e %n"
|
|
||||||
is compatible with
|
|
||||||
.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
|
|
||||||
However,
|
|
||||||
.Qq Li %o
|
|
||||||
is not equivalent to
|
|
||||||
.Qq Li %lx
|
|
||||||
because
|
|
||||||
the first requires an integer and the second requires a long.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr printf 3
|
.Xr printf 3
|
||||||
.Sh BUGS
|
|
||||||
The
|
|
||||||
.Fn fmtcheck
|
|
||||||
function does not understand all of the conversions that
|
|
||||||
.Xr printf 3
|
|
||||||
does.
|
|
||||||
|
@ -23,13 +23,14 @@
|
|||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd November 30, 2002
|
.Dd November 30, 2002
|
||||||
.Dt FPARSELN 3bsd
|
.Dt fparseln 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fparseln
|
.Nm fparseln
|
||||||
.Nd return the next logical line from a stream
|
.Nd return the next logical line from a stream
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
@ -149,4 +150,6 @@ if it runs out of memory.
|
|||||||
The
|
The
|
||||||
.Fn fparseln
|
.Fn fparseln
|
||||||
function first appeared in
|
function first appeared in
|
||||||
.Nx 1.4 .
|
.Nx 1.4
|
||||||
|
and
|
||||||
|
.Fx 4.0 .
|
||||||
|
@ -32,13 +32,14 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: November 4 2015 $
|
.Dd $Mdocdate: November 4 2015 $
|
||||||
.Dt FPURGE 3bsd
|
.Dt fpurge 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fpurge
|
.Nm fpurge
|
||||||
.Nd flush a stream
|
.Nd flush a stream
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
|
1
man/freezero.3bsd
Normal file
1
man/freezero.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/reallocarray.3bsd
|
@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 19, 2004
|
.Dd March 19, 2004
|
||||||
.Dt FUNOPEN 3bsd
|
.Dt funopen 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm funopen ,
|
.Nm funopen ,
|
||||||
@ -40,6 +40,7 @@
|
|||||||
.Nd open a stream
|
.Nd open a stream
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In stdio.h
|
||||||
@ -167,9 +168,12 @@ functions first appeared in
|
|||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
The
|
The
|
||||||
.Fn funopen
|
.Fn funopen
|
||||||
function
|
function may not be portable to systems other than
|
||||||
may not be portable to systems other than
|
.Bx ,
|
||||||
.Bx .
|
glibc- and musl-based ones
|
||||||
|
(as the libbsd implementation is only provided when the system has
|
||||||
|
.Fn fopencookie
|
||||||
|
available).
|
||||||
.Pp
|
.Pp
|
||||||
On
|
On
|
||||||
.Fx ,
|
.Fx ,
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd November 16, 2012
|
.Dd November 16, 2012
|
||||||
.Dt GETBSIZE 3bsd
|
.Dt getbsize 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getbsize
|
.Nm getbsize
|
||||||
.Nd get preferred block size
|
.Nd get preferred block size
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
|
@ -26,13 +26,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 15, 2001
|
.Dd July 15, 2001
|
||||||
.Dt GETPEEREID 3bsd
|
.Dt getpeereid 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getpeereid
|
.Nm getpeereid
|
||||||
.Nd get the effective credentials of a UNIX-domain peer
|
.Nd get the effective credentials of a UNIX-domain peer
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/types.h
|
.In sys/types.h
|
||||||
@ -138,4 +139,7 @@ or the kernel returned invalid data.
|
|||||||
The
|
The
|
||||||
.Fn getpeereid
|
.Fn getpeereid
|
||||||
function appeared in
|
function appeared in
|
||||||
.Fx 4.6 .
|
.Fx 4.6 ,
|
||||||
|
.Nx 5.0
|
||||||
|
and
|
||||||
|
.Ox 3.0 .
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
.\"
|
.\" Copyright (c) 2022 Guillem Jover <guillem@hadrons.org>
|
||||||
.\" Copyright (c) 2001 Christopher G. Demetriou
|
|
||||||
.\" All rights reserved.
|
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
@ -10,36 +8,30 @@
|
|||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
.\" 3. All advertising materials mentioning features or use of this software
|
.\" 3. The name of the author may not be used to endorse or promote products
|
||||||
.\" must display the following acknowledgement:
|
|
||||||
.\" This product includes software developed for the
|
|
||||||
.\" NetBSD Project. See http://www.netbsd.org/ for
|
|
||||||
.\" information about NetBSD.
|
|
||||||
.\" 4. The name of the author may not be used to endorse or promote products
|
|
||||||
.\" derived from this software without specific prior written permission.
|
.\" derived from this software without specific prior written permission.
|
||||||
|
.\" .
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
.Dd August 03, 2022
|
||||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
.Dt getprogname 3bsd
|
||||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
.\"
|
|
||||||
.\" $FreeBSD$
|
|
||||||
.\"
|
|
||||||
.Dd May 1, 2001
|
|
||||||
.Dt GETPROGNAME 3bsd
|
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getprogname ,
|
.Nm getprogname ,
|
||||||
.Nm setprogname
|
.Nm setprogname
|
||||||
.Nd get or set the program name
|
.Nd get and set program name
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
@ -53,46 +45,39 @@ for include usage.)
|
|||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn getprogname
|
.Fn getprogname
|
||||||
and
|
returns a string with the current program name,
|
||||||
.Fn setprogname
|
excluding any directory component.
|
||||||
functions manipulate the name of the current program.
|
The function will return
|
||||||
They are used by error-reporting routines to produce
|
.Dv NULL
|
||||||
consistent output.
|
if it was unable to get the program name from any known source.
|
||||||
.Pp
|
|
||||||
The
|
|
||||||
.Fn getprogname
|
|
||||||
function returns the name of the program.
|
|
||||||
If the name has not been set yet, it will return
|
|
||||||
.Dv NULL .
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn setprogname
|
.Fn setprogname
|
||||||
function sets the name of the program to be the last component of the
|
function sets the current program name,
|
||||||
.Fa progname
|
stripping any directory component prefix.
|
||||||
argument.
|
The function will keep a reference to the passed string pointer,
|
||||||
Since a pointer to the given string is kept as the program name,
|
so it must not be freed or modified while these functions might
|
||||||
it should not be modified for the rest of the program's lifetime.
|
be called.
|
||||||
.Pp
|
.Pp
|
||||||
In
|
The implementations on most BSDs will try to initialize the program name
|
||||||
.Fx ,
|
at program startup time, and
|
||||||
the name of the program is set by the start-up code that is run before
|
.Nm libbsd
|
||||||
.Fn main ;
|
will try to infer it from various known sources depending on the
|
||||||
thus,
|
target system.
|
||||||
running
|
But it is not a portable assumption that the program name will be set
|
||||||
.Fn setprogname
|
without calling
|
||||||
is not necessary.
|
.Fn setprogname ,
|
||||||
Programs that desire maximum portability should still call it;
|
so portable programs should always call it after starting up.
|
||||||
on another operating system,
|
|
||||||
these functions may be implemented in a portability library.
|
|
||||||
Calling
|
|
||||||
.Fn setprogname
|
|
||||||
allows the aforementioned library to learn the program name without
|
|
||||||
modifications to the start-up code.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr err 3 ,
|
.Xr setproctitle 3bsd .
|
||||||
.Xr setproctitle 3bsd
|
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
These functions first appeared in
|
The
|
||||||
|
.Fn setprogname
|
||||||
|
and
|
||||||
|
.Fn getprogname
|
||||||
|
functions first appeared in
|
||||||
.Nx 1.6 ,
|
.Nx 1.6 ,
|
||||||
and made their way into
|
.Fx 4.4 ,
|
||||||
.Fx 4.4 .
|
.Dx 2.1
|
||||||
|
and
|
||||||
|
.Ox 5.4 .
|
||||||
|
1
man/gid_from_group.3bsd
Normal file
1
man/gid_from_group.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/pwcache.3bsd
|
1
man/group_from_gid.3bsd
Normal file
1
man/group_from_gid.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/pwcache.3bsd
|
@ -33,13 +33,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd September 30, 2003
|
.Dd September 30, 2003
|
||||||
.Dt HEAPSORT 3bsd
|
.Dt heapsort 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm heapsort , mergesort
|
.Nm heapsort , mergesort
|
||||||
.Nd sort functions
|
.Nd sort functions
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd February 9, 2008
|
.Dd February 9, 2008
|
||||||
.Dt HUMANIZE_NUMBER 3bsd
|
.Dt humanize_number 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm dehumanize_number ,
|
.Nm dehumanize_number ,
|
||||||
@ -36,6 +36,7 @@
|
|||||||
.Nd format a number into a human readable form and viceversa
|
.Nd format a number into a human readable form and viceversa
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
@ -165,7 +166,9 @@ represented a number that does not fit in
|
|||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Fn humanize_number
|
.Fn humanize_number
|
||||||
first appeared in
|
first appeared in
|
||||||
.Nx 2.0 .
|
.Nx 2.0
|
||||||
|
and
|
||||||
|
.Fx 5.3 .
|
||||||
.Pp
|
.Pp
|
||||||
.Fn dehumanize_number
|
.Fn dehumanize_number
|
||||||
first appeared in
|
first appeared in
|
||||||
|
146
man/libbsd.7
146
man/libbsd.7
@ -1,6 +1,6 @@
|
|||||||
.\" libbsd man page
|
.\" libbsd man page
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright © 2017 Gullem Jover <guillem@hadrons.org>
|
.\" Copyright © 2017-2024 Guillem Jover <guillem@hadrons.org>
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
@ -24,8 +24,8 @@
|
|||||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd May 31 2017
|
.Dd January 8, 2024
|
||||||
.Dt LIBBSD 7
|
.Dt libbsd 7
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm libbsd
|
.Nm libbsd
|
||||||
@ -33,7 +33,7 @@
|
|||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm libbsd
|
.Nm libbsd
|
||||||
library provides a set if compatibility macros and functions commonly found
|
library provides a set of compatibility macros and functions commonly found
|
||||||
on BSD-based systems.
|
on BSD-based systems.
|
||||||
Its purpose is to make those available on non-BSD based systems to ease
|
Its purpose is to make those available on non-BSD based systems to ease
|
||||||
portability.
|
portability.
|
||||||
@ -42,7 +42,7 @@ The library can be used in an overlay mode, which is the preferred way, so
|
|||||||
that the code is portable and requires no modification to the original BSD
|
that the code is portable and requires no modification to the original BSD
|
||||||
code.
|
code.
|
||||||
This can be done easily with the
|
This can be done easily with the
|
||||||
.Xr pkg-config 3
|
.Xr pkgconf 1
|
||||||
library named
|
library named
|
||||||
.Pa libbsd-overlay .
|
.Pa libbsd-overlay .
|
||||||
Or by adding the system-specific include directory with the
|
Or by adding the system-specific include directory with the
|
||||||
@ -59,12 +59,12 @@ The includes in this case should be the usual system ones, such as
|
|||||||
.In unistd.h .
|
.In unistd.h .
|
||||||
.Pp
|
.Pp
|
||||||
The other way to use the library is to use the namespaced headers,
|
The other way to use the library is to use the namespaced headers,
|
||||||
this is less portable as it makes using
|
which is a discouraged way, being less portable as it makes using
|
||||||
.Nm libbsd
|
.Nm libbsd
|
||||||
mandatory and it will not work on BSD-based systems, and requires
|
mandatory and it will not work on BSD-based systems, and requires
|
||||||
modifying original BSD code.
|
modifying original BSD code.
|
||||||
This can be done with the
|
This can be done with the
|
||||||
.Xr pkg-config 3
|
.Xr pkgconf 1
|
||||||
library named
|
library named
|
||||||
.Pa libbsd .
|
.Pa libbsd .
|
||||||
The includes in this case should be namespaced with
|
The includes in this case should be namespaced with
|
||||||
@ -73,13 +73,13 @@ such as
|
|||||||
.In bsd/unistd.h .
|
.In bsd/unistd.h .
|
||||||
.Pp
|
.Pp
|
||||||
The package also provides a
|
The package also provides a
|
||||||
.Pa bsd-ctor
|
.Nm libbsd-ctor
|
||||||
static library that can be used to inject automatic constructors into a
|
static library that can be used to inject automatic constructors into a
|
||||||
program so that the
|
program so that the
|
||||||
.Fn setproctitle
|
.Xr setproctitle_init 3bsd
|
||||||
function gets invoked automatically at startup time.
|
function gets invoked automatically at startup time.
|
||||||
This can be done with the
|
This can be done with the
|
||||||
.Xr pkg-config 3
|
.Xr pkgconf 1
|
||||||
library named
|
library named
|
||||||
.Pa libbsd-ctor .
|
.Pa libbsd-ctor .
|
||||||
.Sh HEADERS
|
.Sh HEADERS
|
||||||
@ -94,10 +94,13 @@ be prefixed with
|
|||||||
.It In bitstring.h
|
.It In bitstring.h
|
||||||
.It In err.h
|
.It In err.h
|
||||||
.It In getopt.h
|
.It In getopt.h
|
||||||
|
.It In grp.h
|
||||||
|
.It In inttypes.h
|
||||||
.It In libutil.h
|
.It In libutil.h
|
||||||
.It In md5.h
|
.It In md5.h
|
||||||
.It In netinet/ip_icmp.h
|
.It In netinet/ip_icmp.h
|
||||||
.It In nlist.h
|
.It In nlist.h
|
||||||
|
.It In pwd.h
|
||||||
.It In readpassphrase.h
|
.It In readpassphrase.h
|
||||||
.It In stdio.h
|
.It In stdio.h
|
||||||
.It In stdlib.h
|
.It In stdlib.h
|
||||||
@ -106,6 +109,7 @@ be prefixed with
|
|||||||
.It In sys/bitstring.h
|
.It In sys/bitstring.h
|
||||||
.It In sys/cdefs.h
|
.It In sys/cdefs.h
|
||||||
.It In sys/endian.h
|
.It In sys/endian.h
|
||||||
|
.It In sys/param.h
|
||||||
.It In sys/poll.h
|
.It In sys/poll.h
|
||||||
.It In sys/queue.h
|
.It In sys/queue.h
|
||||||
.It In sys/time.h
|
.It In sys/time.h
|
||||||
@ -124,6 +128,47 @@ It only works in non-overlay mode.
|
|||||||
.Bl -tag -width 4m -compact
|
.Bl -tag -width 4m -compact
|
||||||
.It In bsd/bsd.h
|
.It In bsd/bsd.h
|
||||||
.El
|
.El
|
||||||
|
.Sh VARIANTS
|
||||||
|
Some functions have different prototypes depending on the BSD where they
|
||||||
|
originated from, and these various implementations provided are selectable
|
||||||
|
at build-time.
|
||||||
|
.Pp
|
||||||
|
This is the list of functions that provide multiple implementations:
|
||||||
|
.Pp
|
||||||
|
.Bl -tag -width 4m -compact
|
||||||
|
.It Xr strnvis 3bsd
|
||||||
|
.It Xr strnunvis 3bsd
|
||||||
|
.Nx
|
||||||
|
added
|
||||||
|
.Xr strnvis 3bsd
|
||||||
|
and
|
||||||
|
.Xr strnunvis 3bsd
|
||||||
|
but unfortunately made it incompatible with the existing one in
|
||||||
|
.Ox
|
||||||
|
and Freedesktop's libbsd (the former having existed for over ten years).
|
||||||
|
Despite this incompatibility being reported during development (see
|
||||||
|
http://gnats.netbsd.org/44977) they still shipped it.
|
||||||
|
Even more unfortunately
|
||||||
|
.Fx
|
||||||
|
and later macOS picked up this incompatible implementation.
|
||||||
|
.Pp
|
||||||
|
Provide both implementations and default for now to the historical one to
|
||||||
|
avoid breakage, but we will switch to the
|
||||||
|
.Nx
|
||||||
|
one in a later release, which is internally consistent with the other
|
||||||
|
.Xr vis 3bsd
|
||||||
|
functions and is now more widespread.
|
||||||
|
Define
|
||||||
|
.Dv LIBBSD_NETBSD_VIS
|
||||||
|
to switch to the
|
||||||
|
.Nx
|
||||||
|
one now.
|
||||||
|
Define
|
||||||
|
.Dv LIBBSD_OPENBSD_VIS
|
||||||
|
to keep using the
|
||||||
|
.Ox
|
||||||
|
one.
|
||||||
|
.El
|
||||||
.Sh DEPRECATED
|
.Sh DEPRECATED
|
||||||
Some functions have been deprecated, they will emit warnings at compile time
|
Some functions have been deprecated, they will emit warnings at compile time
|
||||||
and possibly while being linked at run-time.
|
and possibly while being linked at run-time.
|
||||||
@ -133,19 +178,30 @@ or non-buggy way; or because there are better more portable replacements now.
|
|||||||
.Pp
|
.Pp
|
||||||
This is the list of currently deprecated macros and functions:
|
This is the list of currently deprecated macros and functions:
|
||||||
.Bl -tag -width 4m
|
.Bl -tag -width 4m
|
||||||
.It Fn fgetln
|
.It Xr fgetln 3bsd
|
||||||
Unportable, requires assistance from the stdio layer.
|
Unportable, requires assistance from the stdio layer.
|
||||||
An implementation has to choose between leaking buffers or being reentrant
|
An implementation has to choose between leaking buffers or being reentrant
|
||||||
for a limited amount of streams (this implementation chose the latter with
|
for a limited amount of streams (this implementation chose the latter with
|
||||||
a limit of 32).
|
a limit of 32).
|
||||||
Use
|
Use
|
||||||
.Fn getline 3
|
.Xr getline 3
|
||||||
instead, which is available in many systems and required by
|
instead, which is available in many systems and required by
|
||||||
.St -p1003.1-2008 .
|
.St -p1003.1-2008 .
|
||||||
.It Fn funopen
|
.It Xr fgetwln 3bsd
|
||||||
|
Unportable, requires assistance from the stdio layer.
|
||||||
|
An implementation has to choose between leaking buffers or being reentrant
|
||||||
|
for a limited amount of streams (this implementation chose the latter with
|
||||||
|
a limit of 32).
|
||||||
|
Use
|
||||||
|
.Xr fgetwc 3
|
||||||
|
instead, which is available in many systems and required by
|
||||||
|
.St -isoC-99
|
||||||
|
and
|
||||||
|
.St -p1003.1-2001 .
|
||||||
|
.It Xr funopen 3bsd
|
||||||
Unportable, requires assistance from the stdio layer or some hook framework.
|
Unportable, requires assistance from the stdio layer or some hook framework.
|
||||||
On GNU systems the
|
On glibc- and musl-based systems the
|
||||||
.Fn fopencookie
|
.Xr fopencookie 3
|
||||||
function can be used.
|
function can be used.
|
||||||
Otherwise the code needs to be prepared for neither of these functions being
|
Otherwise the code needs to be prepared for neither of these functions being
|
||||||
available.
|
available.
|
||||||
@ -159,26 +215,53 @@ are present in all major
|
|||||||
for example.
|
for example.
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width 4m -compact
|
.Bl -tag -width 4m -compact
|
||||||
.It Fn MD5Init
|
.It Xr MD5Init 3
|
||||||
.It Fn MD5Update
|
.It Xr MD5Update 3
|
||||||
.It Fn MD5Pad
|
.It Xr MD5Pad 3
|
||||||
.It Fn MD5Final
|
.It Xr MD5Final 3
|
||||||
.It Fn MD5Transform
|
.It Xr MD5Transform 3
|
||||||
.It Fn MD5End
|
.It Xr MD5End 3
|
||||||
.It Fn MD5File
|
.It Xr MD5File 3
|
||||||
.It Fn MD5FileChunk
|
.It Xr MD5FileChunk 3
|
||||||
.It Fn MD5Data
|
.It Xr MD5Data 3
|
||||||
The set of MD5 digest functions are now provided by the
|
The set of MD5 digest functions are now proxies for the implementations
|
||||||
|
provided by the
|
||||||
.Nm libmd
|
.Nm libmd
|
||||||
companion library, so it is advised to use that instead.
|
companion library, so it is advised to switch to use that directly instead.
|
||||||
.It Fn explicit_bzero
|
.It Xr explicit_bzero 3bsd
|
||||||
This function is provided by
|
This function is provided by
|
||||||
.Nm glibc
|
.Nm glibc
|
||||||
2.25.
|
2.25, and
|
||||||
.It Fn reallocarray
|
.Nm musl
|
||||||
|
1.1.20.
|
||||||
|
.It Xr reallocarray 3bsd
|
||||||
This function is provided by
|
This function is provided by
|
||||||
.Nm glibc
|
.Nm glibc
|
||||||
2.26.
|
2.26, and
|
||||||
|
.Nm musl
|
||||||
|
1.2.2.
|
||||||
|
.It Xr closefrom 3bsd
|
||||||
|
This function is provided by
|
||||||
|
.Nm glibc
|
||||||
|
2.34.
|
||||||
|
.It Xr arc4random 3bsd
|
||||||
|
.It Xr arc4random_buf 3bsd
|
||||||
|
.It Xr arc4random_uniform 3bsd
|
||||||
|
These functions are provided by
|
||||||
|
.Nm glibc
|
||||||
|
2.36.
|
||||||
|
Note that it does not provide the
|
||||||
|
.Xr arc4random_stir 3bsd
|
||||||
|
and
|
||||||
|
.Xr arc4random_addrandom 3bsd
|
||||||
|
functions.
|
||||||
|
.It Xr strlcpy 3bsd
|
||||||
|
.It Xr strlcat 3bsd
|
||||||
|
These functions are provided by
|
||||||
|
.Nm glibc
|
||||||
|
2.38, and
|
||||||
|
.Nm musl
|
||||||
|
0.5.0.
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr arc4random 3bsd ,
|
.Xr arc4random 3bsd ,
|
||||||
@ -203,6 +286,7 @@ This function is provided by
|
|||||||
.Xr md5 3bsd ,
|
.Xr md5 3bsd ,
|
||||||
.Xr nlist 3bsd ,
|
.Xr nlist 3bsd ,
|
||||||
.Xr pidfile 3bsd ,
|
.Xr pidfile 3bsd ,
|
||||||
|
.Xr pwcache 3bsd ,
|
||||||
.Xr queue 3bsd ,
|
.Xr queue 3bsd ,
|
||||||
.Xr radixsort 3bsd ,
|
.Xr radixsort 3bsd ,
|
||||||
.Xr readpassphrase 3bsd ,
|
.Xr readpassphrase 3bsd ,
|
||||||
@ -214,7 +298,9 @@ This function is provided by
|
|||||||
.Xr strlcpy 3bsd ,
|
.Xr strlcpy 3bsd ,
|
||||||
.Xr strmode 3bsd ,
|
.Xr strmode 3bsd ,
|
||||||
.Xr strnstr 3bsd ,
|
.Xr strnstr 3bsd ,
|
||||||
|
.Xr strtoi 3bsd ,
|
||||||
.Xr strtonum 3bsd ,
|
.Xr strtonum 3bsd ,
|
||||||
|
.Xr strtou 3bsd ,
|
||||||
.Xr timeradd 3bsd ,
|
.Xr timeradd 3bsd ,
|
||||||
.Xr timeval 3bsd ,
|
.Xr timeval 3bsd ,
|
||||||
.Xr tree 3bsd ,
|
.Xr tree 3bsd ,
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
|
.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/types.h
|
.In sys/types.h
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
|
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 19, 1994
|
.Dd April 19, 1994
|
||||||
.Dt NLIST 3bsd
|
.Dt nlist 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm nlist
|
.Nm nlist
|
||||||
.Nd retrieve symbol table name list from an executable file
|
.Nd retrieve symbol table name list from an executable file
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In nlist.h
|
.In nlist.h
|
||||||
@ -50,7 +51,7 @@ The
|
|||||||
function
|
function
|
||||||
retrieves name list entries from the symbol table of an
|
retrieves name list entries from the symbol table of an
|
||||||
executable file (see
|
executable file (see
|
||||||
.Xr a.out 5 ) .
|
.Xr elf 5 ) .
|
||||||
The argument
|
The argument
|
||||||
.Fa \&nl
|
.Fa \&nl
|
||||||
is set to reference the
|
is set to reference the
|
||||||
@ -71,9 +72,12 @@ The last entry in the list is always
|
|||||||
The number of invalid entries is returned if successful; otherwise,
|
The number of invalid entries is returned if successful; otherwise,
|
||||||
if the file
|
if the file
|
||||||
.Fa filename
|
.Fa filename
|
||||||
does not exist or is not executable, the returned value is \-1.
|
does not exist or is not executable,
|
||||||
|
or the nl pointer is
|
||||||
|
.Dv NULL ,
|
||||||
|
the returned value is \-1.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr a.out 5
|
.Xr elf 5
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
A
|
A
|
||||||
.Fn nlist
|
.Fn nlist
|
||||||
|
@ -24,17 +24,19 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd October 20, 2008
|
.Dd February 8, 2012
|
||||||
.Dt PIDFILE 3bsd
|
.Dt pidfile 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm pidfile_open ,
|
.Nm pidfile_open ,
|
||||||
.Nm pidfile_write ,
|
.Nm pidfile_write ,
|
||||||
.Nm pidfile_close ,
|
.Nm pidfile_close ,
|
||||||
.Nm pidfile_remove
|
.Nm pidfile_remove ,
|
||||||
.Nd library for PID files handling
|
.Nm pidfile_fileno
|
||||||
|
.Nd "library for PID files handling"
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In libutil.h
|
.In libutil.h
|
||||||
@ -49,6 +51,8 @@ for include usage.)
|
|||||||
.Fn pidfile_close "struct pidfh *pfh"
|
.Fn pidfile_close "struct pidfh *pfh"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn pidfile_remove "struct pidfh *pfh"
|
.Fn pidfile_remove "struct pidfh *pfh"
|
||||||
|
.Ft int
|
||||||
|
.Fn pidfile_fileno "struct pidfh *pfh"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm pidfile
|
.Nm pidfile
|
||||||
@ -62,11 +66,14 @@ The
|
|||||||
function opens (or creates) a file specified by the
|
function opens (or creates) a file specified by the
|
||||||
.Fa path
|
.Fa path
|
||||||
argument and locks it.
|
argument and locks it.
|
||||||
If a file can not be locked, a PID of an already running daemon is returned in
|
If
|
||||||
the
|
|
||||||
.Fa pidptr
|
.Fa pidptr
|
||||||
argument (if it is not
|
argument is not
|
||||||
.Dv NULL ) .
|
.Dv NULL
|
||||||
|
and file can not be locked, the function will use it to store a PID of an
|
||||||
|
already running daemon or
|
||||||
|
.Li -1
|
||||||
|
in case daemon did not write its PID yet.
|
||||||
The function does not write process' PID into the file here, so it can be
|
The function does not write process' PID into the file here, so it can be
|
||||||
used before
|
used before
|
||||||
.Fn fork Ns ing
|
.Fn fork Ns ing
|
||||||
@ -77,10 +84,16 @@ argument is
|
|||||||
.Dv NULL ,
|
.Dv NULL ,
|
||||||
.Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid
|
.Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid
|
||||||
file will be used.
|
file will be used.
|
||||||
|
The
|
||||||
|
.Fn pidfile_open
|
||||||
|
function sets the O_CLOEXEC close-on-exec flag when opening the pidfile.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn pidfile_write
|
.Fn pidfile_write
|
||||||
function writes process' PID into a previously opened file.
|
function writes process' PID into a previously opened file.
|
||||||
|
The file is truncated before write, so calling the
|
||||||
|
.Fn pidfile_write
|
||||||
|
function multiple times is supported.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn pidfile_close
|
.Fn pidfile_close
|
||||||
@ -92,6 +105,10 @@ to start a child process.
|
|||||||
The
|
The
|
||||||
.Fn pidfile_remove
|
.Fn pidfile_remove
|
||||||
function closes and removes a pidfile.
|
function closes and removes a pidfile.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn pidfile_fileno
|
||||||
|
function returns the file descriptor for the open pidfile.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
The
|
The
|
||||||
.Fn pidfile_open
|
.Fn pidfile_open
|
||||||
@ -105,15 +122,27 @@ If an error occurs,
|
|||||||
will be set.
|
will be set.
|
||||||
.Pp
|
.Pp
|
||||||
.Rv -std pidfile_write pidfile_close pidfile_remove
|
.Rv -std pidfile_write pidfile_close pidfile_remove
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn pidfile_fileno
|
||||||
|
function returns the low-level file descriptor.
|
||||||
|
It returns
|
||||||
|
.Li -1
|
||||||
|
and sets
|
||||||
|
.Va errno
|
||||||
|
if a NULL
|
||||||
|
.Vt pidfh
|
||||||
|
is specified, or if the pidfile is no longer open.
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
The following example shows in which order these functions should be used.
|
The following example shows in which order these functions should be used.
|
||||||
Note that it is safe to pass
|
Note that it is safe to pass
|
||||||
.Dv NULL
|
.Dv NULL
|
||||||
to
|
to
|
||||||
.Fn pidfile_write ,
|
.Fn pidfile_write ,
|
||||||
.Fn pidfile_remove
|
.Fn pidfile_remove ,
|
||||||
and
|
|
||||||
.Fn pidfile_close
|
.Fn pidfile_close
|
||||||
|
and
|
||||||
|
.Fn pidfile_fileno
|
||||||
functions.
|
functions.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
struct pidfh *pfh;
|
struct pidfh *pfh;
|
||||||
@ -127,6 +156,11 @@ if (pfh == NULL) {
|
|||||||
}
|
}
|
||||||
/* If we cannot create pidfile from other reasons, only warn. */
|
/* If we cannot create pidfile from other reasons, only warn. */
|
||||||
warn("Cannot open or create pidfile");
|
warn("Cannot open or create pidfile");
|
||||||
|
/*
|
||||||
|
* Even though pfh is NULL we can continue, as the other pidfile_*
|
||||||
|
* function can handle such situation by doing nothing except setting
|
||||||
|
* errno to EINVAL.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (daemon(0, 0) == \-1) {
|
if (daemon(0, 0) == \-1) {
|
||||||
@ -165,16 +199,18 @@ function will fail if:
|
|||||||
.It Bq Er EEXIST
|
.It Bq Er EEXIST
|
||||||
Some process already holds the lock on the given pidfile, meaning that a
|
Some process already holds the lock on the given pidfile, meaning that a
|
||||||
daemon is already running.
|
daemon is already running.
|
||||||
|
If
|
||||||
|
.Fa pidptr
|
||||||
|
argument is not
|
||||||
|
.Dv NULL
|
||||||
|
the function will use it to store a PID of an already running daemon or
|
||||||
|
.Li -1
|
||||||
|
in case daemon did not write its PID yet.
|
||||||
.It Bq Er ENAMETOOLONG
|
.It Bq Er ENAMETOOLONG
|
||||||
Specified pidfile's name is too long.
|
Specified pidfile's name is too long.
|
||||||
.It Bq Er EINVAL
|
.It Bq Er EINVAL
|
||||||
Some process already holds the lock on the given pidfile, but PID read
|
Some process already holds the lock on the given pidfile, but PID read
|
||||||
from there is invalid.
|
from there is invalid.
|
||||||
.It Bq Er EAGAIN
|
|
||||||
Some process already holds the lock on the given pidfile, but the file
|
|
||||||
is truncated.
|
|
||||||
Most likely, the existing daemon is writing new PID into
|
|
||||||
the file.
|
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -242,16 +278,40 @@ and
|
|||||||
system calls and the
|
system calls and the
|
||||||
.Xr flopen 3bsd
|
.Xr flopen 3bsd
|
||||||
library function.
|
library function.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn pidfile_fileno
|
||||||
|
function will fail if:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
Improper function use.
|
||||||
|
Probably called not from the process which used
|
||||||
|
.Fn pidfile_open .
|
||||||
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr open 2 ,
|
.Xr open 2 ,
|
||||||
.Xr daemon 3 ,
|
.Xr daemon 3 ,
|
||||||
.Xr flopen 3bsd
|
.Xr flopen 3bsd
|
||||||
|
.Sh HISTORY
|
||||||
|
The functions
|
||||||
|
.Fn pidfile_open ,
|
||||||
|
.Fn pidfile_write ,
|
||||||
|
.Fn pidfile_close
|
||||||
|
and
|
||||||
|
.Fn pidfile_remove
|
||||||
|
first appeared in
|
||||||
|
.Fx 5.5 .
|
||||||
|
.Pp
|
||||||
|
The function
|
||||||
|
.Fn pidfile_fileno
|
||||||
|
first appeared in
|
||||||
|
.Fx 10.0 .
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.An -nosplit
|
.An -nosplit
|
||||||
The
|
The
|
||||||
.Nm pidfile
|
.Nm pidfile
|
||||||
functionality is based on ideas from
|
functionality is based on ideas from
|
||||||
.An John-Mark Gurney Aq jmg@FreeBSD.org .
|
.An John-Mark Gurney Aq Mt jmg@FreeBSD.org .
|
||||||
.Pp
|
.Pp
|
||||||
The code and manual page was written by
|
The code and manual page was written by
|
||||||
.An Pawel Jakub Dawidek Aq pjd@FreeBSD.org .
|
.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .
|
||||||
|
143
man/pwcache.3bsd
Normal file
143
man/pwcache.3bsd
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
.\" $OpenBSD: pwcache.3,v 1.15 2018/09/13 16:50:54 jmc Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1989, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.Dd $Mdocdate: September 13 2018 $
|
||||||
|
.Dt user_from_uid 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm user_from_uid ,
|
||||||
|
.Nm uid_from_user ,
|
||||||
|
.Nm group_from_gid ,
|
||||||
|
.Nm gid_from_group
|
||||||
|
.Nd cache password and group entries
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In pwd.h
|
||||||
|
(See
|
||||||
|
.Xr libbsd 7
|
||||||
|
for include usage.)
|
||||||
|
.Ft int
|
||||||
|
.Fn uid_from_user "const char *name" "uid_t *uid"
|
||||||
|
.Ft const char *
|
||||||
|
.Fn user_from_uid "uid_t uid" "int nouser"
|
||||||
|
.In grp.h
|
||||||
|
.Ft int
|
||||||
|
.Fn gid_from_group "const char *name" "gid_t *gid"
|
||||||
|
.Ft const char *
|
||||||
|
.Fn group_from_gid "gid_t gid" "int nogroup"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn user_from_uid
|
||||||
|
function returns the user name associated with the argument
|
||||||
|
.Fa uid .
|
||||||
|
The user name is cached so that multiple calls with the same
|
||||||
|
.Fa uid
|
||||||
|
do not require additional calls to
|
||||||
|
.Xr getpwuid 3 .
|
||||||
|
If there is no user associated with the
|
||||||
|
.Fa uid ,
|
||||||
|
a pointer is returned
|
||||||
|
to a string representation of the
|
||||||
|
.Fa uid ,
|
||||||
|
unless the argument
|
||||||
|
.Fa nouser
|
||||||
|
is non-zero, in which case a null pointer is returned.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn uid_from_user
|
||||||
|
function returns the user ID associated with the argument
|
||||||
|
.Fa name .
|
||||||
|
The user ID is cached so that multiple calls with the same
|
||||||
|
.Fa name
|
||||||
|
do not require additional calls to
|
||||||
|
.Xr getpwnam 3 .
|
||||||
|
If there is no user ID associated with the
|
||||||
|
.Fa name ,
|
||||||
|
the
|
||||||
|
.Fn uid_from_user
|
||||||
|
function returns -1;
|
||||||
|
otherwise it stores the user ID at the location pointed to by
|
||||||
|
.Fa uid
|
||||||
|
and returns 0.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn group_from_gid
|
||||||
|
function returns the group name associated with the argument
|
||||||
|
.Fa gid .
|
||||||
|
The group name is cached so that multiple calls with the same
|
||||||
|
.Fa gid
|
||||||
|
do not require additional calls to
|
||||||
|
.Xr getgrgid 3 .
|
||||||
|
If there is no group associated with the
|
||||||
|
.Fa gid ,
|
||||||
|
a pointer is returned
|
||||||
|
to a string representation of the
|
||||||
|
.Fa gid ,
|
||||||
|
unless the argument
|
||||||
|
.Fa nogroup
|
||||||
|
is non-zero, in which case a null pointer is returned.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn gid_from_group
|
||||||
|
function returns the group ID associated with the argument
|
||||||
|
.Fa name .
|
||||||
|
The group ID is cached so that multiple calls with the same
|
||||||
|
.Fa name
|
||||||
|
do not require additional calls to
|
||||||
|
.Xr getgrnam 3 .
|
||||||
|
If there is no group ID associated with the
|
||||||
|
.Fa name ,
|
||||||
|
the
|
||||||
|
.Fn gid_from_group
|
||||||
|
function returns -1;
|
||||||
|
otherwise it stores the group ID at the location pointed to by
|
||||||
|
.Fa gid
|
||||||
|
and returns 0.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr getgrgid 3 ,
|
||||||
|
.Xr getpwuid 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn user_from_uid
|
||||||
|
and
|
||||||
|
.Fn group_from_gid
|
||||||
|
functions first appeared in
|
||||||
|
.Bx 4.4 .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn uid_from_user
|
||||||
|
and
|
||||||
|
.Fn gid_from_group
|
||||||
|
functions first appeared in
|
||||||
|
.Nx 1.4
|
||||||
|
and
|
||||||
|
.Ox 6.4 .
|
159
man/queue.3bsd
159
man/queue.3bsd
@ -28,35 +28,40 @@
|
|||||||
.\" @(#)queue.3 8.2 (Berkeley) 1/24/94
|
.\" @(#)queue.3 8.2 (Berkeley) 1/24/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 17, 2013
|
.Dd September 8, 2016
|
||||||
.Dt QUEUE 3bsd
|
.Dt queue 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
.Nm SLIST_CLASS_ENTRY ,
|
||||||
|
.Nm SLIST_CLASS_HEAD ,
|
||||||
|
.Nm SLIST_CONCAT ,
|
||||||
.Nm SLIST_EMPTY ,
|
.Nm SLIST_EMPTY ,
|
||||||
.Nm SLIST_ENTRY ,
|
.Nm SLIST_ENTRY ,
|
||||||
.Nm SLIST_FIRST ,
|
.Nm SLIST_FIRST ,
|
||||||
.Nm SLIST_FOREACH ,
|
.Nm SLIST_FOREACH ,
|
||||||
.Nm SLIST_FOREACH_FROM ,
|
.Nm SLIST_FOREACH_FROM ,
|
||||||
.Nm SLIST_FOREACH_SAFE ,
|
|
||||||
.Nm SLIST_FOREACH_FROM_SAFE ,
|
.Nm SLIST_FOREACH_FROM_SAFE ,
|
||||||
|
.Nm SLIST_FOREACH_SAFE ,
|
||||||
.Nm SLIST_HEAD ,
|
.Nm SLIST_HEAD ,
|
||||||
.Nm SLIST_HEAD_INITIALIZER ,
|
.Nm SLIST_HEAD_INITIALIZER ,
|
||||||
.Nm SLIST_INIT ,
|
.Nm SLIST_INIT ,
|
||||||
.Nm SLIST_INSERT_AFTER ,
|
.Nm SLIST_INSERT_AFTER ,
|
||||||
.Nm SLIST_INSERT_HEAD ,
|
.Nm SLIST_INSERT_HEAD ,
|
||||||
.Nm SLIST_NEXT ,
|
.Nm SLIST_NEXT ,
|
||||||
|
.Nm SLIST_REMOVE ,
|
||||||
.Nm SLIST_REMOVE_AFTER ,
|
.Nm SLIST_REMOVE_AFTER ,
|
||||||
.Nm SLIST_REMOVE_HEAD ,
|
.Nm SLIST_REMOVE_HEAD ,
|
||||||
.Nm SLIST_REMOVE ,
|
|
||||||
.Nm SLIST_SWAP ,
|
.Nm SLIST_SWAP ,
|
||||||
|
.Nm STAILQ_CLASS_ENTRY ,
|
||||||
|
.Nm STAILQ_CLASS_HEAD ,
|
||||||
.Nm STAILQ_CONCAT ,
|
.Nm STAILQ_CONCAT ,
|
||||||
.Nm STAILQ_EMPTY ,
|
.Nm STAILQ_EMPTY ,
|
||||||
.Nm STAILQ_ENTRY ,
|
.Nm STAILQ_ENTRY ,
|
||||||
.Nm STAILQ_FIRST ,
|
.Nm STAILQ_FIRST ,
|
||||||
.Nm STAILQ_FOREACH ,
|
.Nm STAILQ_FOREACH ,
|
||||||
.Nm STAILQ_FOREACH_FROM ,
|
.Nm STAILQ_FOREACH_FROM ,
|
||||||
.Nm STAILQ_FOREACH_SAFE ,
|
|
||||||
.Nm STAILQ_FOREACH_FROM_SAFE ,
|
.Nm STAILQ_FOREACH_FROM_SAFE ,
|
||||||
|
.Nm STAILQ_FOREACH_SAFE ,
|
||||||
.Nm STAILQ_HEAD ,
|
.Nm STAILQ_HEAD ,
|
||||||
.Nm STAILQ_HEAD_INITIALIZER ,
|
.Nm STAILQ_HEAD_INITIALIZER ,
|
||||||
.Nm STAILQ_INIT ,
|
.Nm STAILQ_INIT ,
|
||||||
@ -65,17 +70,20 @@
|
|||||||
.Nm STAILQ_INSERT_TAIL ,
|
.Nm STAILQ_INSERT_TAIL ,
|
||||||
.Nm STAILQ_LAST ,
|
.Nm STAILQ_LAST ,
|
||||||
.Nm STAILQ_NEXT ,
|
.Nm STAILQ_NEXT ,
|
||||||
|
.Nm STAILQ_REMOVE ,
|
||||||
.Nm STAILQ_REMOVE_AFTER ,
|
.Nm STAILQ_REMOVE_AFTER ,
|
||||||
.Nm STAILQ_REMOVE_HEAD ,
|
.Nm STAILQ_REMOVE_HEAD ,
|
||||||
.Nm STAILQ_REMOVE ,
|
|
||||||
.Nm STAILQ_SWAP ,
|
.Nm STAILQ_SWAP ,
|
||||||
|
.Nm LIST_CLASS_ENTRY ,
|
||||||
|
.Nm LIST_CLASS_HEAD ,
|
||||||
|
.Nm LIST_CONCAT ,
|
||||||
.Nm LIST_EMPTY ,
|
.Nm LIST_EMPTY ,
|
||||||
.Nm LIST_ENTRY ,
|
.Nm LIST_ENTRY ,
|
||||||
.Nm LIST_FIRST ,
|
.Nm LIST_FIRST ,
|
||||||
.Nm LIST_FOREACH ,
|
.Nm LIST_FOREACH ,
|
||||||
.Nm LIST_FOREACH_FROM ,
|
.Nm LIST_FOREACH_FROM ,
|
||||||
.Nm LIST_FOREACH_SAFE ,
|
|
||||||
.Nm LIST_FOREACH_FROM_SAFE ,
|
.Nm LIST_FOREACH_FROM_SAFE ,
|
||||||
|
.Nm LIST_FOREACH_SAFE ,
|
||||||
.Nm LIST_HEAD ,
|
.Nm LIST_HEAD ,
|
||||||
.Nm LIST_HEAD_INITIALIZER ,
|
.Nm LIST_HEAD_INITIALIZER ,
|
||||||
.Nm LIST_INIT ,
|
.Nm LIST_INIT ,
|
||||||
@ -86,18 +94,20 @@
|
|||||||
.Nm LIST_PREV ,
|
.Nm LIST_PREV ,
|
||||||
.Nm LIST_REMOVE ,
|
.Nm LIST_REMOVE ,
|
||||||
.Nm LIST_SWAP ,
|
.Nm LIST_SWAP ,
|
||||||
|
.Nm TAILQ_CLASS_ENTRY ,
|
||||||
|
.Nm TAILQ_CLASS_HEAD ,
|
||||||
.Nm TAILQ_CONCAT ,
|
.Nm TAILQ_CONCAT ,
|
||||||
.Nm TAILQ_EMPTY ,
|
.Nm TAILQ_EMPTY ,
|
||||||
.Nm TAILQ_ENTRY ,
|
.Nm TAILQ_ENTRY ,
|
||||||
.Nm TAILQ_FIRST ,
|
.Nm TAILQ_FIRST ,
|
||||||
.Nm TAILQ_FOREACH ,
|
.Nm TAILQ_FOREACH ,
|
||||||
.Nm TAILQ_FOREACH_FROM ,
|
.Nm TAILQ_FOREACH_FROM ,
|
||||||
.Nm TAILQ_FOREACH_SAFE ,
|
|
||||||
.Nm TAILQ_FOREACH_FROM_SAFE ,
|
.Nm TAILQ_FOREACH_FROM_SAFE ,
|
||||||
.Nm TAILQ_FOREACH_REVERSE ,
|
.Nm TAILQ_FOREACH_REVERSE ,
|
||||||
.Nm TAILQ_FOREACH_REVERSE_FROM ,
|
.Nm TAILQ_FOREACH_REVERSE_FROM ,
|
||||||
.Nm TAILQ_FOREACH_REVERSE_SAFE ,
|
|
||||||
.Nm TAILQ_FOREACH_REVERSE_FROM_SAFE ,
|
.Nm TAILQ_FOREACH_REVERSE_FROM_SAFE ,
|
||||||
|
.Nm TAILQ_FOREACH_REVERSE_SAFE ,
|
||||||
|
.Nm TAILQ_FOREACH_SAFE ,
|
||||||
.Nm TAILQ_HEAD ,
|
.Nm TAILQ_HEAD ,
|
||||||
.Nm TAILQ_HEAD_INITIALIZER ,
|
.Nm TAILQ_HEAD_INITIALIZER ,
|
||||||
.Nm TAILQ_INIT ,
|
.Nm TAILQ_INIT ,
|
||||||
@ -112,58 +122,70 @@
|
|||||||
.Nm TAILQ_SWAP
|
.Nm TAILQ_SWAP
|
||||||
.Nd implementations of singly-linked lists, singly-linked tail queues,
|
.Nd implementations of singly-linked lists, singly-linked tail queues,
|
||||||
lists and tail queues
|
lists and tail queues
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/queue.h
|
.In sys/queue.h
|
||||||
(See
|
(See
|
||||||
.Xr libbsd 7
|
.Xr libbsd 7
|
||||||
for include usage.)
|
for include usage.)
|
||||||
.\"
|
.\"
|
||||||
|
.Fn SLIST_CLASS_ENTRY "CLASSTYPE"
|
||||||
|
.Fn SLIST_CLASS_HEAD "HEADNAME" "CLASSTYPE"
|
||||||
|
.Fn SLIST_CONCAT "SLIST_HEAD *head1" "SLIST_HEAD *head2" "TYPE" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_EMPTY "SLIST_HEAD *head"
|
.Fn SLIST_EMPTY "SLIST_HEAD *head"
|
||||||
.Fn SLIST_ENTRY "TYPE"
|
.Fn SLIST_ENTRY "TYPE"
|
||||||
.Fn SLIST_FIRST "SLIST_HEAD *head"
|
.Fn SLIST_FIRST "SLIST_HEAD *head"
|
||||||
.Fn SLIST_FOREACH "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
.Fn SLIST_FOREACH "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_FOREACH_FROM "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
.Fn SLIST_FOREACH_FROM "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_FOREACH_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var"
|
|
||||||
.Fn SLIST_FOREACH_FROM_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var"
|
.Fn SLIST_FOREACH_FROM_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var"
|
||||||
|
.Fn SLIST_FOREACH_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var"
|
||||||
.Fn SLIST_HEAD "HEADNAME" "TYPE"
|
.Fn SLIST_HEAD "HEADNAME" "TYPE"
|
||||||
.Fn SLIST_HEAD_INITIALIZER "SLIST_HEAD head"
|
.Fn SLIST_HEAD_INITIALIZER "SLIST_HEAD head"
|
||||||
.Fn SLIST_INIT "SLIST_HEAD *head"
|
.Fn SLIST_INIT "SLIST_HEAD *head"
|
||||||
.Fn SLIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "SLIST_ENTRY NAME"
|
.Fn SLIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_INSERT_HEAD "SLIST_HEAD *head" "TYPE *elm" "SLIST_ENTRY NAME"
|
.Fn SLIST_INSERT_HEAD "SLIST_HEAD *head" "TYPE *elm" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_NEXT "TYPE *elm" "SLIST_ENTRY NAME"
|
.Fn SLIST_NEXT "TYPE *elm" "SLIST_ENTRY NAME"
|
||||||
|
.Fn SLIST_REMOVE "SLIST_HEAD *head" "TYPE *elm" "TYPE" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_REMOVE_AFTER "TYPE *elm" "SLIST_ENTRY NAME"
|
.Fn SLIST_REMOVE_AFTER "TYPE *elm" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_REMOVE_HEAD "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
.Fn SLIST_REMOVE_HEAD "SLIST_HEAD *head" "SLIST_ENTRY NAME"
|
||||||
.Fn SLIST_REMOVE "SLIST_HEAD *head" "TYPE *elm" "TYPE" "SLIST_ENTRY NAME"
|
.Fn SLIST_SWAP "SLIST_HEAD *head1" "SLIST_HEAD *head2" "TYPE"
|
||||||
.Fn SLIST_SWAP "SLIST_HEAD *head1" "SLIST_HEAD *head2" "SLIST_ENTRY NAME"
|
|
||||||
.\"
|
.\"
|
||||||
|
.Fn STAILQ_CLASS_ENTRY "CLASSTYPE"
|
||||||
|
.Fn STAILQ_CLASS_HEAD "HEADNAME" "CLASSTYPE"
|
||||||
.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
|
.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
|
||||||
.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
|
.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
|
||||||
.Fn STAILQ_ENTRY "TYPE"
|
.Fn STAILQ_ENTRY "TYPE"
|
||||||
.Fn STAILQ_FIRST "STAILQ_HEAD *head"
|
.Fn STAILQ_FIRST "STAILQ_HEAD *head"
|
||||||
.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_FOREACH_FROM "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_FOREACH_FROM "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
|
|
||||||
.Fn STAILQ_FOREACH_FROM_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
|
.Fn STAILQ_FOREACH_FROM_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
|
.Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
.Fn STAILQ_HEAD "HEADNAME" "TYPE"
|
.Fn STAILQ_HEAD "HEADNAME" "TYPE"
|
||||||
.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
|
.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
|
||||||
.Fn STAILQ_INIT "STAILQ_HEAD *head"
|
.Fn STAILQ_INIT "STAILQ_HEAD *head"
|
||||||
.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
|
.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
|
||||||
.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
|
.Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "TYPE"
|
||||||
.Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
|
|
||||||
.\"
|
.\"
|
||||||
|
.Fn LIST_CLASS_ENTRY "CLASSTYPE"
|
||||||
|
.Fn LIST_CLASS_HEAD "HEADNAME" "CLASSTYPE"
|
||||||
|
.Fn LIST_CONCAT "LIST_HEAD *head1" "LIST_HEAD *head2" "TYPE" "LIST_ENTRY NAME"
|
||||||
.Fn LIST_EMPTY "LIST_HEAD *head"
|
.Fn LIST_EMPTY "LIST_HEAD *head"
|
||||||
.Fn LIST_ENTRY "TYPE"
|
.Fn LIST_ENTRY "TYPE"
|
||||||
.Fn LIST_FIRST "LIST_HEAD *head"
|
.Fn LIST_FIRST "LIST_HEAD *head"
|
||||||
.Fn LIST_FOREACH "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME"
|
.Fn LIST_FOREACH "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME"
|
||||||
.Fn LIST_FOREACH_FROM "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME"
|
.Fn LIST_FOREACH_FROM "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME"
|
||||||
.Fn LIST_FOREACH_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var"
|
|
||||||
.Fn LIST_FOREACH_FROM_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var"
|
.Fn LIST_FOREACH_FROM_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var"
|
||||||
|
.Fn LIST_FOREACH_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var"
|
||||||
.Fn LIST_HEAD "HEADNAME" "TYPE"
|
.Fn LIST_HEAD "HEADNAME" "TYPE"
|
||||||
.Fn LIST_HEAD_INITIALIZER "LIST_HEAD head"
|
.Fn LIST_HEAD_INITIALIZER "LIST_HEAD head"
|
||||||
.Fn LIST_INIT "LIST_HEAD *head"
|
.Fn LIST_INIT "LIST_HEAD *head"
|
||||||
@ -175,18 +197,20 @@ for include usage.)
|
|||||||
.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME"
|
.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME"
|
||||||
.Fn LIST_SWAP "LIST_HEAD *head1" "LIST_HEAD *head2" "TYPE" "LIST_ENTRY NAME"
|
.Fn LIST_SWAP "LIST_HEAD *head1" "LIST_HEAD *head2" "TYPE" "LIST_ENTRY NAME"
|
||||||
.\"
|
.\"
|
||||||
|
.Fn TAILQ_CLASS_ENTRY "CLASSTYPE"
|
||||||
|
.Fn TAILQ_CLASS_HEAD "HEADNAME" "CLASSTYPE"
|
||||||
.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME"
|
||||||
.Fn TAILQ_EMPTY "TAILQ_HEAD *head"
|
.Fn TAILQ_EMPTY "TAILQ_HEAD *head"
|
||||||
.Fn TAILQ_ENTRY "TYPE"
|
.Fn TAILQ_ENTRY "TYPE"
|
||||||
.Fn TAILQ_FIRST "TAILQ_HEAD *head"
|
.Fn TAILQ_FIRST "TAILQ_HEAD *head"
|
||||||
.Fn TAILQ_FOREACH "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_FOREACH "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME"
|
||||||
.Fn TAILQ_FOREACH_FROM "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_FOREACH_FROM "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME"
|
||||||
.Fn TAILQ_FOREACH_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
|
||||||
.Fn TAILQ_FOREACH_FROM_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
.Fn TAILQ_FOREACH_FROM_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
.Fn TAILQ_FOREACH_REVERSE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_FOREACH_REVERSE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME"
|
||||||
.Fn TAILQ_FOREACH_REVERSE_FROM "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_FOREACH_REVERSE_FROM "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME"
|
||||||
.Fn TAILQ_FOREACH_REVERSE_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
|
||||||
.Fn TAILQ_FOREACH_REVERSE_FROM_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
.Fn TAILQ_FOREACH_REVERSE_FROM_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
|
.Fn TAILQ_FOREACH_REVERSE_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
|
.Fn TAILQ_FOREACH_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var"
|
||||||
.Fn TAILQ_HEAD "HEADNAME" "TYPE"
|
.Fn TAILQ_HEAD "HEADNAME" "TYPE"
|
||||||
.Fn TAILQ_HEAD_INITIALIZER "TAILQ_HEAD head"
|
.Fn TAILQ_HEAD_INITIALIZER "TAILQ_HEAD head"
|
||||||
.Fn TAILQ_INIT "TAILQ_HEAD *head"
|
.Fn TAILQ_INIT "TAILQ_HEAD *head"
|
||||||
@ -201,8 +225,18 @@ for include usage.)
|
|||||||
.Fn TAILQ_SWAP "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TYPE" "TAILQ_ENTRY NAME"
|
.Fn TAILQ_SWAP "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TYPE" "TAILQ_ENTRY NAME"
|
||||||
.\"
|
.\"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
These macros define and operate on four types of data structures:
|
These macros define and operate on four types of data structures which
|
||||||
singly-linked lists, singly-linked tail queues, lists, and tail queues.
|
can be used in both C and C++ source code:
|
||||||
|
.Bl -enum -compact -offset indent
|
||||||
|
.It
|
||||||
|
Lists
|
||||||
|
.It
|
||||||
|
Singly-linked lists
|
||||||
|
.It
|
||||||
|
Singly-linked tail queues
|
||||||
|
.It
|
||||||
|
Tail queues
|
||||||
|
.El
|
||||||
All four structures support the following functionality:
|
All four structures support the following functionality:
|
||||||
.Bl -enum -compact -offset indent
|
.Bl -enum -compact -offset indent
|
||||||
.It
|
.It
|
||||||
@ -226,6 +260,8 @@ Singly-linked lists add the following functionality:
|
|||||||
.Bl -enum -compact -offset indent
|
.Bl -enum -compact -offset indent
|
||||||
.It
|
.It
|
||||||
O(n) removal of any entry in the list.
|
O(n) removal of any entry in the list.
|
||||||
|
.It
|
||||||
|
O(n) concatenation of two lists.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Singly-linked tail queues add the following functionality:
|
Singly-linked tail queues add the following functionality:
|
||||||
@ -273,6 +309,8 @@ Linked lists are the simplest of the doubly linked data structures.
|
|||||||
They add the following functionality over the above:
|
They add the following functionality over the above:
|
||||||
.Bl -enum -compact -offset indent
|
.Bl -enum -compact -offset indent
|
||||||
.It
|
.It
|
||||||
|
O(n) concatenation of two lists.
|
||||||
|
.It
|
||||||
They may be traversed backwards.
|
They may be traversed backwards.
|
||||||
.El
|
.El
|
||||||
However:
|
However:
|
||||||
@ -304,24 +342,39 @@ than singly-linked lists.
|
|||||||
.Pp
|
.Pp
|
||||||
In the macro definitions,
|
In the macro definitions,
|
||||||
.Fa TYPE
|
.Fa TYPE
|
||||||
is the name of a user defined structure,
|
is the name of a user defined structure.
|
||||||
that must contain a field of type
|
The structure must contain a field called
|
||||||
|
.Fa NAME
|
||||||
|
which is of type
|
||||||
.Li SLIST_ENTRY ,
|
.Li SLIST_ENTRY ,
|
||||||
.Li STAILQ_ENTRY ,
|
.Li STAILQ_ENTRY ,
|
||||||
.Li LIST_ENTRY ,
|
.Li LIST_ENTRY ,
|
||||||
or
|
or
|
||||||
.Li TAILQ_ENTRY ,
|
.Li TAILQ_ENTRY .
|
||||||
named
|
In the macro definitions,
|
||||||
.Fa NAME .
|
.Fa CLASSTYPE
|
||||||
|
is the name of a user defined class.
|
||||||
|
The class must contain a field called
|
||||||
|
.Fa NAME
|
||||||
|
which is of type
|
||||||
|
.Li SLIST_CLASS_ENTRY ,
|
||||||
|
.Li STAILQ_CLASS_ENTRY ,
|
||||||
|
.Li LIST_CLASS_ENTRY ,
|
||||||
|
or
|
||||||
|
.Li TAILQ_CLASS_ENTRY .
|
||||||
The argument
|
The argument
|
||||||
.Fa HEADNAME
|
.Fa HEADNAME
|
||||||
is the name of a user defined structure that must be declared
|
is the name of a user defined structure that must be declared
|
||||||
using the macros
|
using the macros
|
||||||
.Li SLIST_HEAD ,
|
.Li SLIST_HEAD ,
|
||||||
|
.Li SLIST_CLASS_HEAD ,
|
||||||
.Li STAILQ_HEAD ,
|
.Li STAILQ_HEAD ,
|
||||||
|
.Li STAILQ_CLASS_HEAD ,
|
||||||
.Li LIST_HEAD ,
|
.Li LIST_HEAD ,
|
||||||
|
.Li LIST_CLASS_HEAD ,
|
||||||
|
.Li TAILQ_HEAD ,
|
||||||
or
|
or
|
||||||
.Li TAILQ_HEAD .
|
.Li TAILQ_CLASS_HEAD .
|
||||||
See the examples below for further explanation of how these
|
See the examples below for further explanation of how these
|
||||||
macros are used.
|
macros are used.
|
||||||
.Sh SINGLY-LINKED LISTS
|
.Sh SINGLY-LINKED LISTS
|
||||||
@ -363,6 +416,19 @@ evaluates to an initializer for the list
|
|||||||
.Fa head .
|
.Fa head .
|
||||||
.Pp
|
.Pp
|
||||||
The macro
|
The macro
|
||||||
|
.Nm SLIST_CONCAT
|
||||||
|
concatenates the list headed by
|
||||||
|
.Fa head2
|
||||||
|
onto the end of the one headed by
|
||||||
|
.Fa head1
|
||||||
|
removing all entries from the former.
|
||||||
|
Use of this macro should be avoided as it traverses the entirety of the
|
||||||
|
.Fa head1
|
||||||
|
list.
|
||||||
|
A singly-linked tail queue should be used if this macro is needed in
|
||||||
|
high-usage code paths or to operate on long lists.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
.Nm SLIST_EMPTY
|
.Nm SLIST_EMPTY
|
||||||
evaluates to true if there are no elements in the list.
|
evaluates to true if there are no elements in the list.
|
||||||
.Pp
|
.Pp
|
||||||
@ -470,6 +536,9 @@ The macro
|
|||||||
removes the element
|
removes the element
|
||||||
.Fa elm
|
.Fa elm
|
||||||
from the list.
|
from the list.
|
||||||
|
Use of this macro should be avoided as it traverses the entire list.
|
||||||
|
A doubly-linked list should be used if this macro is needed in
|
||||||
|
high-usage code paths or to operate on long lists.
|
||||||
.Pp
|
.Pp
|
||||||
The macro
|
The macro
|
||||||
.Nm SLIST_SWAP
|
.Nm SLIST_SWAP
|
||||||
@ -686,6 +755,9 @@ The macro
|
|||||||
removes the element
|
removes the element
|
||||||
.Fa elm
|
.Fa elm
|
||||||
from the tail queue.
|
from the tail queue.
|
||||||
|
Use of this macro should be avoided as it traverses the entire list.
|
||||||
|
A doubly-linked tail queue should be used if this macro is needed in
|
||||||
|
high-usage code paths or to operate on long tail queues.
|
||||||
.Pp
|
.Pp
|
||||||
The macro
|
The macro
|
||||||
.Nm STAILQ_SWAP
|
.Nm STAILQ_SWAP
|
||||||
@ -785,6 +857,19 @@ evaluates to an initializer for the list
|
|||||||
.Fa head .
|
.Fa head .
|
||||||
.Pp
|
.Pp
|
||||||
The macro
|
The macro
|
||||||
|
.Nm LIST_CONCAT
|
||||||
|
concatenates the list headed by
|
||||||
|
.Fa head2
|
||||||
|
onto the end of the one headed by
|
||||||
|
.Fa head1
|
||||||
|
removing all entries from the former.
|
||||||
|
Use of this macro should be avoided as it traverses the entirety of the
|
||||||
|
.Fa head1
|
||||||
|
list.
|
||||||
|
A tail queue should be used if this macro is needed in
|
||||||
|
high-usage code paths or to operate on long lists.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
.Nm LIST_EMPTY
|
.Nm LIST_EMPTY
|
||||||
evaluates to true if there are no elements in the list.
|
evaluates to true if there are no elements in the list.
|
||||||
.Pp
|
.Pp
|
||||||
@ -1206,6 +1291,26 @@ while (n1 != NULL) {
|
|||||||
}
|
}
|
||||||
TAILQ_INIT(&head);
|
TAILQ_INIT(&head);
|
||||||
.Ed
|
.Ed
|
||||||
|
.Sh DIAGNOSTICS
|
||||||
|
When debugging
|
||||||
|
.Nm queue(3) ,
|
||||||
|
it can be useful to trace queue changes.
|
||||||
|
To enable tracing, define the macro
|
||||||
|
.Va QUEUE_MACRO_DEBUG_TRACE
|
||||||
|
at compile time.
|
||||||
|
.Pp
|
||||||
|
It can also be useful to trash pointers that have been unlinked from a queue,
|
||||||
|
to detect use after removal.
|
||||||
|
To enable pointer trashing, define the macro
|
||||||
|
.Va QUEUE_MACRO_DEBUG_TRASH
|
||||||
|
at compile time.
|
||||||
|
The macro
|
||||||
|
.Fn QMD_IS_TRASHED "void *ptr"
|
||||||
|
returns true if
|
||||||
|
.Fa ptr
|
||||||
|
has been trashed by the
|
||||||
|
.Va QUEUE_MACRO_DEBUG_TRASH
|
||||||
|
option.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr tree 3bsd
|
.Xr tree 3bsd
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
||||||
.\"
|
.\"
|
||||||
.Dd January 27, 1994
|
.Dd January 27, 1994
|
||||||
.Dt RADIXSORT 3bsd
|
.Dt radixsort 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm radixsort ,
|
.Nm radixsort ,
|
||||||
@ -38,6 +38,7 @@
|
|||||||
.Nd radix sort
|
.Nd radix sort
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In limits.h
|
.In limits.h
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.\" $OpenBSD: readpassphrase.3,v 1.16 2005/07/22 03:16:58 jaredy Exp $
|
.\" $OpenBSD: readpassphrase.3,v 1.20 2014/03/06 23:03:18 millert Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
.\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
.\"
|
.\"
|
||||||
@ -18,14 +18,15 @@
|
|||||||
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
|
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||||
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.Dd $Mdocdate: March 6 2014 $
|
||||||
.Dt READPASSPHRASE 3bsd
|
.Dt readpassphrase 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm readpassphrase
|
.Nm readpassphrase
|
||||||
.Nd get a passphrase from the user
|
.Nd get a passphrase from the user
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In readpassphrase.h
|
.In readpassphrase.h
|
||||||
@ -55,9 +56,11 @@ Up to
|
|||||||
Any additional
|
Any additional
|
||||||
characters and the terminating newline (or return) character are discarded.
|
characters and the terminating newline (or return) character are discarded.
|
||||||
.Pp
|
.Pp
|
||||||
.Fn readpassphrase
|
The
|
||||||
takes the following optional
|
.Fa flags
|
||||||
.Fa flags :
|
argument is the bitwise
|
||||||
|
.Tn OR
|
||||||
|
of zero or more of the following values:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
RPP_ECHO_OFF turn off echo (default behavior)
|
RPP_ECHO_OFF turn off echo (default behavior)
|
||||||
RPP_ECHO_ON leave echo on
|
RPP_ECHO_ON leave echo on
|
||||||
@ -65,7 +68,7 @@ RPP_REQUIRE_TTY fail if there is no tty
|
|||||||
RPP_FORCELOWER force input to lower case
|
RPP_FORCELOWER force input to lower case
|
||||||
RPP_FORCEUPPER force input to upper case
|
RPP_FORCEUPPER force input to upper case
|
||||||
RPP_SEVENBIT strip the high bit from input
|
RPP_SEVENBIT strip the high bit from input
|
||||||
RPP_STDIN force read of passphrase from stdin
|
RPP_STDIN read passphrase from stdin; ignore prompt
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The calling process should zero the passphrase as soon as possible to
|
The calling process should zero the passphrase as soon as possible to
|
||||||
@ -100,7 +103,7 @@ if (compare(transform(passbuf), epass) != 0)
|
|||||||
|
|
||||||
\&...
|
\&...
|
||||||
|
|
||||||
memset(passbuf, 0, sizeof(passbuf));
|
explicit_bzero(passbuf, sizeof(passbuf));
|
||||||
.Ed
|
.Ed
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
.Bl -tag -width Er
|
.Bl -tag -width Er
|
||||||
@ -162,10 +165,12 @@ will reprint the prompt and the user may then enter a passphrase.
|
|||||||
The
|
The
|
||||||
.Fn readpassphrase
|
.Fn readpassphrase
|
||||||
function is an
|
function is an
|
||||||
.Ox
|
.Bx
|
||||||
extension and should not be used if portability is desired.
|
extension and should not be used if portability is desired.
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Fn readpassphrase
|
.Fn readpassphrase
|
||||||
function first appeared in
|
function first appeared in
|
||||||
.Ox 2.9 .
|
.Ox 2.9
|
||||||
|
and
|
||||||
|
.Fx 4.6 .
|
||||||
|
@ -30,16 +30,19 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" $OpenBSD: malloc.3,v 1.78 2014/05/01 18:41:59 jmc Exp $
|
.\" $OpenBSD: malloc.3,v 1.126 2019/09/14 13:16:50 otto Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 1 2014 $
|
.Dd $Mdocdate: September 14 2019 $
|
||||||
.Dt REALLOCARRAY 3bsd
|
.Dt reallocarray 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm reallocarray
|
.Nm reallocarray ,
|
||||||
|
.Nm recallocarray ,
|
||||||
|
.Nm freezero
|
||||||
.Nd memory allocation and deallocation
|
.Nd memory allocation and deallocation
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
@ -48,59 +51,250 @@
|
|||||||
for include usage.)
|
for include usage.)
|
||||||
.Ft void *
|
.Ft void *
|
||||||
.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
|
.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
|
||||||
|
.Ft void *
|
||||||
|
.Fn recallocarray "void *ptr" "size_t oldnmemb" "size_t nmemb" "size_t size"
|
||||||
|
.Ft void
|
||||||
|
.Fn freezero "void *ptr" "size_t size"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Pp
|
.Pp
|
||||||
When using
|
Designed for safe allocation of arrays,
|
||||||
.Fn malloc
|
the
|
||||||
be careful to avoid the following idiom:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
if ((p = malloc(num * size)) == NULL)
|
|
||||||
err(1, "malloc");
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
The multiplication may lead to an integer overflow, which can
|
|
||||||
be avoided using the extension
|
|
||||||
.Fn reallocarray ,
|
|
||||||
as follows:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
if ((p = reallocarray(NULL, num, size)) == NULL)
|
|
||||||
err(1, "malloc");
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
Alternatively
|
|
||||||
.Fn calloc
|
|
||||||
is a more portable solution which comes with the cost of clearing memory.
|
|
||||||
.Pp
|
|
||||||
If
|
|
||||||
.Fn malloc
|
|
||||||
must be used, be sure to test for overflow:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
if (size && num > SIZE_MAX / size) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
err(1, "overflow");
|
|
||||||
}
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
The use of
|
|
||||||
.Fn reallocarray
|
.Fn reallocarray
|
||||||
or
|
function is similar to
|
||||||
.Fn calloc
|
.Fn realloc
|
||||||
is strongly encouraged when allocating multiple sized objects
|
except it operates on
|
||||||
in order to avoid possible integer overflows.
|
.Fa nmemb
|
||||||
|
members of size
|
||||||
|
.Fa size
|
||||||
|
and checks for integer overflow in the calculation
|
||||||
|
.Fa nmemb
|
||||||
|
*
|
||||||
|
.Fa size .
|
||||||
|
.Pp
|
||||||
|
Used for the allocation of memory holding sensitive data,
|
||||||
|
the
|
||||||
|
.Fn recallocarray
|
||||||
|
function guarantees that memory becoming unallocated is explicitly
|
||||||
|
.Em discarded ,
|
||||||
|
meaning cached free objects are cleared with
|
||||||
|
.Xr explicit_bzero 3 .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn recallocarray
|
||||||
|
function is similar to
|
||||||
|
.Fn reallocarray
|
||||||
|
except it ensures newly allocated memory is cleared similar to
|
||||||
|
.Fn calloc .
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is
|
||||||
|
.Dv NULL ,
|
||||||
|
.Fa oldnmemb
|
||||||
|
is ignored and the call is equivalent to
|
||||||
|
.Fn calloc .
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is not
|
||||||
|
.Dv NULL ,
|
||||||
|
.Fa oldnmemb
|
||||||
|
must be a value such that
|
||||||
|
.Fa oldnmemb
|
||||||
|
*
|
||||||
|
.Fa size
|
||||||
|
is the size of the earlier allocation that returned
|
||||||
|
.Fa ptr ,
|
||||||
|
otherwise the behavior is undefined.
|
||||||
|
The
|
||||||
|
.Fn freezero
|
||||||
|
function is similar to the
|
||||||
|
.Fn free
|
||||||
|
function except it ensures memory is explicitly discarded.
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is
|
||||||
|
.Dv NULL ,
|
||||||
|
no action occurs.
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is not
|
||||||
|
.Dv NULL ,
|
||||||
|
the
|
||||||
|
.Fa size
|
||||||
|
argument must be equal to or smaller than the size of the earlier allocation
|
||||||
|
that returned
|
||||||
|
.Fa ptr .
|
||||||
|
.Fn freezero
|
||||||
|
guarantees the memory range starting at
|
||||||
|
.Fa ptr
|
||||||
|
with length
|
||||||
|
.Fa size
|
||||||
|
is discarded while deallocating the whole object originally allocated.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
The
|
The
|
||||||
.Fn reallocarray
|
.Fn reallocarray
|
||||||
function returns a pointer to the allocated space if successful; otherwise,
|
and
|
||||||
|
.Fn recallocarray
|
||||||
|
functions return a pointer to the allocated space if successful; otherwise,
|
||||||
a null pointer is returned and
|
a null pointer is returned and
|
||||||
.Va errno
|
.Va errno
|
||||||
is set to
|
is set to
|
||||||
.Er ENOMEM .
|
.Er ENOMEM .
|
||||||
|
.Pp
|
||||||
|
If multiplying
|
||||||
|
.Fa nmemb
|
||||||
|
and
|
||||||
|
.Fa size
|
||||||
|
results in integer overflow,
|
||||||
|
.Fn reallocarray
|
||||||
|
and
|
||||||
|
.Fn recallocarray
|
||||||
|
return
|
||||||
|
.Dv NULL
|
||||||
|
and set
|
||||||
|
.Va errno
|
||||||
|
to
|
||||||
|
.Er ENOMEM .
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is not
|
||||||
|
.Dv NULL
|
||||||
|
and multiplying
|
||||||
|
.Fa oldnmemb
|
||||||
|
and
|
||||||
|
.Fa size
|
||||||
|
results in integer overflow
|
||||||
|
.Fn recallocarray
|
||||||
|
returns
|
||||||
|
.Dv NULL
|
||||||
|
and sets
|
||||||
|
.Va errno
|
||||||
|
to
|
||||||
|
.Er EINVAL .
|
||||||
|
.Sh IDIOMS
|
||||||
|
Consider
|
||||||
|
.Fn calloc
|
||||||
|
or the extensions
|
||||||
|
.Fn reallocarray
|
||||||
|
and
|
||||||
|
.Fn recallocarray
|
||||||
|
when there is multiplication in the
|
||||||
|
.Fa size
|
||||||
|
argument of
|
||||||
|
.Fn malloc
|
||||||
|
or
|
||||||
|
.Fn realloc .
|
||||||
|
For example, avoid this common idiom as it may lead to integer overflow:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
if ((p = malloc(num * size)) == NULL)
|
||||||
|
err(1, NULL);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
A drop-in replacement is
|
||||||
|
.Fn reallocarray :
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
if ((p = reallocarray(NULL, num, size)) == NULL)
|
||||||
|
err(1, NULL);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Alternatively,
|
||||||
|
.Fn calloc
|
||||||
|
may be used at the cost of initialization overhead.
|
||||||
|
.Pp
|
||||||
|
When using
|
||||||
|
.Fn realloc ,
|
||||||
|
be careful to avoid the following idiom:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
size += 50;
|
||||||
|
if ((p = realloc(p, size)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Do not adjust the variable describing how much memory has been allocated
|
||||||
|
until the allocation has been successful.
|
||||||
|
This can cause aberrant program behavior if the incorrect size value is used.
|
||||||
|
In most cases, the above sample will also result in a leak of memory.
|
||||||
|
As stated earlier, a return value of
|
||||||
|
.Dv NULL
|
||||||
|
indicates that the old object still remains allocated.
|
||||||
|
Better code looks like this:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
newsize = size + 50;
|
||||||
|
if ((newp = realloc(p, newsize)) == NULL) {
|
||||||
|
free(p);
|
||||||
|
p = NULL;
|
||||||
|
size = 0;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
p = newp;
|
||||||
|
size = newsize;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
As with
|
||||||
|
.Fn malloc ,
|
||||||
|
it is important to ensure the new size value will not overflow;
|
||||||
|
i.e. avoid allocations like the following:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
if ((newp = realloc(p, num * size)) == NULL) {
|
||||||
|
...
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Instead, use
|
||||||
|
.Fn reallocarray :
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
if ((newp = reallocarray(p, num, size)) == NULL) {
|
||||||
|
...
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Calling
|
||||||
|
.Fn realloc
|
||||||
|
with a
|
||||||
|
.Dv NULL
|
||||||
|
.Fa ptr
|
||||||
|
is equivalent to calling
|
||||||
|
.Fn malloc .
|
||||||
|
Instead of this idiom:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
if (p == NULL)
|
||||||
|
newp = malloc(newsize);
|
||||||
|
else
|
||||||
|
newp = realloc(p, newsize);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Use the following:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
newp = realloc(p, newsize);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn recallocarray
|
||||||
|
function should be used for resizing objects containing sensitive data like
|
||||||
|
keys.
|
||||||
|
To avoid leaking information,
|
||||||
|
it guarantees memory is cleared before placing it on the internal free list.
|
||||||
|
Deallocation of such an object should be done by calling
|
||||||
|
.Fn freezero .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr malloc 3 ,
|
.Xr malloc 3 ,
|
||||||
.Xr calloc 3 ,
|
.Xr calloc 3 ,
|
||||||
.Xr alloca 3
|
.Xr alloca 3
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
The
|
||||||
.Fn reallocarray
|
.Fn reallocarray
|
||||||
appeared in
|
function appeared in
|
||||||
.Ox 5.6 ,
|
.Ox 5.6 ,
|
||||||
glibc 2.26.
|
.Dx 5.5
|
||||||
|
and glibc 2.26.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn recallocarray
|
||||||
|
function appeared in
|
||||||
|
.Ox 6.1
|
||||||
|
and
|
||||||
|
.Dx 5.5 .
|
||||||
|
The
|
||||||
|
.Fn freezero
|
||||||
|
function appeared in
|
||||||
|
.Ox 6.2
|
||||||
|
and
|
||||||
|
.Dx 5.5 .
|
||||||
|
@ -33,13 +33,14 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd September 26, 2009
|
.Dd September 26, 2009
|
||||||
.Dt REALLOCF 3bsd
|
.Dt reallocf 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm reallocf
|
.Nm reallocf
|
||||||
.Nd general purpose memory allocation functions
|
.Nd general purpose memory allocation functions
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
|
1
man/recallocarray.3bsd
Normal file
1
man/recallocarray.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/reallocarray.3bsd
|
@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd January 4, 2009
|
.Dd January 4, 2009
|
||||||
.Dt SETMODE 3bsd
|
.Dt setmode 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getmode ,
|
.Nm getmode ,
|
||||||
@ -39,6 +39,7 @@
|
|||||||
.Nd modify mode bits
|
.Nd modify mode bits
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In unistd.h
|
.In unistd.h
|
||||||
|
@ -20,17 +20,17 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.\" The following requests are required for all man pages.
|
.\" The following requests are required for all man pages.
|
||||||
.Dd December 16, 1995
|
.Dd December 7, 2022
|
||||||
.Dt SETPROCTITLE 3bsd
|
.Dt setproctitle 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm setproctitle
|
.Nm setproctitle
|
||||||
.Nd set process title
|
.Nd set process title
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/types.h
|
|
||||||
.In unistd.h
|
.In unistd.h
|
||||||
(See
|
(See
|
||||||
.Xr libbsd 7
|
.Xr libbsd 7
|
||||||
@ -53,7 +53,7 @@ library routine only needs to be called (before any call to
|
|||||||
and with
|
and with
|
||||||
.Fn main
|
.Fn main
|
||||||
arguments), if the automatic constructor support has not
|
arguments), if the automatic constructor support has not
|
||||||
been linked in through the libbsd-ctor pkg-config file.
|
been linked in through the libbsd-ctor pkgconf file.
|
||||||
.Pp
|
.Pp
|
||||||
The title is set from the executable's name, followed by the
|
The title is set from the executable's name, followed by the
|
||||||
result of a
|
result of a
|
||||||
@ -112,13 +112,15 @@ The
|
|||||||
.Fn setproctitle
|
.Fn setproctitle
|
||||||
function
|
function
|
||||||
first appeared in
|
first appeared in
|
||||||
|
.Nx 1.0
|
||||||
|
and
|
||||||
.Fx 2.2 .
|
.Fx 2.2 .
|
||||||
Other operating systems have
|
Other operating systems have
|
||||||
similar functions.
|
similar functions.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn setproctitle_init
|
.Fn setproctitle_init
|
||||||
function is a libbsd extension not present on the BSDs, avoid using it
|
function is a libbsd extension not present on the BSDs; avoid using it
|
||||||
in portable code.
|
in portable code.
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.An -nosplit
|
.An -nosplit
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd May 6, 2010
|
.Dd May 6, 2010
|
||||||
.Dt STRINGLIST 3bsd
|
.Dt stringlist 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm stringlist ,
|
.Nm stringlist ,
|
||||||
@ -39,6 +39,7 @@
|
|||||||
.Nd stringlist manipulation functions
|
.Nd stringlist manipulation functions
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stringlist.h
|
.In stringlist.h
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.Dd $Mdocdate: January 7 2024 $
|
||||||
.Dt STRLCPY 3bsd
|
.Dt strlcpy 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strlcpy ,
|
.Nm strlcpy ,
|
||||||
@ -23,6 +23,7 @@
|
|||||||
.Nd size-bounded string copying and concatenation
|
.Nd size-bounded string copying and concatenation
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In string.h
|
||||||
@ -191,4 +192,7 @@ and
|
|||||||
functions first appeared in
|
functions first appeared in
|
||||||
.Ox 2.4 ,
|
.Ox 2.4 ,
|
||||||
and made their appearance in
|
and made their appearance in
|
||||||
.Fx 3.3 .
|
.Nx 1.4.3 ,
|
||||||
|
.Fx 3.3
|
||||||
|
and
|
||||||
|
glibc 2.38.
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
|
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd July 28, 1994
|
.Dd July 28, 1994
|
||||||
.Dt STRMODE 3bsd
|
.Dt strmode 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strmode
|
.Nm strmode
|
||||||
.Nd convert inode status information into a symbolic string
|
.Nd convert inode status information into a symbolic string
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In string.h
|
||||||
|
@ -34,13 +34,14 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd October 11, 2001
|
.Dd October 11, 2001
|
||||||
.Dt STRSTR 3bsd
|
.Dt strstr 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strnstr
|
.Nm strnstr
|
||||||
.Nd locate a substring in a string
|
.Nd locate a substring in a string
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In string.h
|
||||||
@ -111,3 +112,8 @@ ptr = strnstr(largestring, smallstring, 4);
|
|||||||
.Xr strspn 3 ,
|
.Xr strspn 3 ,
|
||||||
.Xr strtok 3 ,
|
.Xr strtok 3 ,
|
||||||
.Xr wcsstr 3
|
.Xr wcsstr 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn strnstr
|
||||||
|
function originated in
|
||||||
|
.Fx .
|
||||||
|
246
man/strtoi.3bsd
Normal file
246
man/strtoi.3bsd
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
.\" $NetBSD: strtoi.3,v 1.10 2024/02/10 18:43:51 andvar Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" from: @(#)strtol.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\"
|
||||||
|
.\" Created by Kamil Rytarowski, based on ID:
|
||||||
|
.\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
|
||||||
|
.\"
|
||||||
|
.Dd January 20, 2024
|
||||||
|
.Dt strtoi 3bsd
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm strtoi
|
||||||
|
.Nd convert a string value to an intmax_t integer
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In inttypes.h
|
||||||
|
(See
|
||||||
|
.Xr libbsd 7
|
||||||
|
for include usage.)
|
||||||
|
.Ft intmax_t
|
||||||
|
.Fo strtoi
|
||||||
|
.Fa "const char * restrict nptr"
|
||||||
|
.Fa "char ** restrict endptr"
|
||||||
|
.Fa "int base"
|
||||||
|
.Fa "intmax_t lo"
|
||||||
|
.Fa "intmax_t hi"
|
||||||
|
.Fa "int *rstatus"
|
||||||
|
.Fc
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function converts the string in
|
||||||
|
.Fa nptr
|
||||||
|
to an
|
||||||
|
.Ft intmax_t
|
||||||
|
value.
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function uses internally
|
||||||
|
.Xr strtoimax 3
|
||||||
|
and ensures that the result is always in the range [
|
||||||
|
.Fa lo ..
|
||||||
|
.Fa hi
|
||||||
|
].
|
||||||
|
In addition it always places
|
||||||
|
.Dv 0
|
||||||
|
on success or a conversion status in the
|
||||||
|
.Fa rstatus
|
||||||
|
argument, avoiding the
|
||||||
|
.Dv errno
|
||||||
|
gymnastics the other functions require.
|
||||||
|
The
|
||||||
|
.Fa rstatus
|
||||||
|
argument can be
|
||||||
|
.Dv NULL
|
||||||
|
if conversion status is to be ignored.
|
||||||
|
.Pp
|
||||||
|
The string may begin with an arbitrary amount of white space
|
||||||
|
(as determined by
|
||||||
|
.Xr isspace 3 )
|
||||||
|
followed by a single optional
|
||||||
|
.Ql +
|
||||||
|
or
|
||||||
|
.Ql -
|
||||||
|
sign.
|
||||||
|
If
|
||||||
|
.Fa base
|
||||||
|
is zero or 16,
|
||||||
|
the string may then include a
|
||||||
|
.Ql 0x
|
||||||
|
or
|
||||||
|
.Ql 0X
|
||||||
|
prefix,
|
||||||
|
and the number will be read in base 16; otherwise,
|
||||||
|
.\" if the
|
||||||
|
.\" .Fa base
|
||||||
|
.\" is zero or 2,
|
||||||
|
.\" the string may then include a
|
||||||
|
.\" .Ql 0b
|
||||||
|
.\" or
|
||||||
|
.\" .Ql 0B
|
||||||
|
.\" prefix,
|
||||||
|
.\" and the number will be read in base 2; otherwise,
|
||||||
|
a zero
|
||||||
|
.Fa base
|
||||||
|
is taken as 10 (decimal) unless the next character is
|
||||||
|
.Ql 0 ,
|
||||||
|
in which case it is taken as 8 (octal).
|
||||||
|
.Pp
|
||||||
|
The remainder of the string is converted to an
|
||||||
|
.Em intmax_t
|
||||||
|
value in the obvious manner,
|
||||||
|
stopping at the end of the string
|
||||||
|
or at the first character which is not a valid digit
|
||||||
|
in the given base.
|
||||||
|
(In bases above 10, the letter
|
||||||
|
.Ql A
|
||||||
|
in either upper or lower case
|
||||||
|
represents 10,
|
||||||
|
.Ql B
|
||||||
|
represents 11, and so forth, with
|
||||||
|
.Ql Z
|
||||||
|
representing 35.)
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fa endptr
|
||||||
|
is non-nil,
|
||||||
|
.Fn strtoi
|
||||||
|
stores the address of the first invalid character in
|
||||||
|
.Fa *endptr .
|
||||||
|
If there were no digits at all, however,
|
||||||
|
.Fn strtoi
|
||||||
|
stores the original value of
|
||||||
|
.Fa nptr
|
||||||
|
in
|
||||||
|
.Fa *endptr .
|
||||||
|
(Thus, if
|
||||||
|
.Fa *nptr
|
||||||
|
is not
|
||||||
|
.Ql \e0
|
||||||
|
but
|
||||||
|
.Fa **endptr
|
||||||
|
is
|
||||||
|
.Ql \e0
|
||||||
|
on return, the entire string was valid.)
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function
|
||||||
|
always returns the closest value in the range specified by
|
||||||
|
the
|
||||||
|
.Fa lo
|
||||||
|
and
|
||||||
|
.Fa hi
|
||||||
|
arguments.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Va errno
|
||||||
|
value is guaranteed to be left unchanged.
|
||||||
|
.Pp
|
||||||
|
Errors are stored as the conversion status in the
|
||||||
|
.Fa rstatus
|
||||||
|
argument.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
The following example will always return a number in
|
||||||
|
.Dv [1..99]
|
||||||
|
range no matter what the input is, and warn if the conversion failed.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
int e;
|
||||||
|
intmax_t lval = strtoi(buf, NULL, 0, 1, 99, &e);
|
||||||
|
if (e)
|
||||||
|
warnc(e, "conversion of `%s' to a number failed, using %jd",
|
||||||
|
buf, lval);
|
||||||
|
.Ed
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er ECANCELED
|
||||||
|
The string did not contain any characters that were converted.
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The
|
||||||
|
.Ar base
|
||||||
|
is not between 2 and 36 and does not contain the special value 0.
|
||||||
|
.It Bq Er ENOTSUP
|
||||||
|
The string contained non-numeric characters that did not get converted.
|
||||||
|
In this case,
|
||||||
|
.Fa endptr
|
||||||
|
points to the first unconverted character.
|
||||||
|
.It Bq Er ERANGE
|
||||||
|
The given string was out of range; the value converted has been clamped;
|
||||||
|
or the range given was invalid, i.e.
|
||||||
|
.Fa lo
|
||||||
|
>
|
||||||
|
.Fa hi .
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The range check is more important than the unconverted characters check,
|
||||||
|
and it is performed first.
|
||||||
|
If a program needs to know if there were unconverted characters when an
|
||||||
|
out of range number has been provided, it needs to supply and test
|
||||||
|
.Fa endptr.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr atof 3 ,
|
||||||
|
.Xr atoi 3 ,
|
||||||
|
.Xr atol 3 ,
|
||||||
|
.Xr atoll 3 ,
|
||||||
|
.Xr strtod 3 ,
|
||||||
|
.Xr strtoimax 3 ,
|
||||||
|
.Xr strtol 3 ,
|
||||||
|
.Xr strtoll 3 ,
|
||||||
|
.Xr strtou 3bsd ,
|
||||||
|
.Xr strtoul 3 ,
|
||||||
|
.Xr strtoull 3 ,
|
||||||
|
.Xr strtoumax 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function is a
|
||||||
|
.Nx
|
||||||
|
extension.
|
||||||
|
.Sh HISTORY
|
||||||
|
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function first appeared in
|
||||||
|
.Nx 7.0 .
|
||||||
|
.Ox
|
||||||
|
introduced the
|
||||||
|
.Xr strtonum 3bsd
|
||||||
|
function for the same purpose, but the interface makes it impossible to
|
||||||
|
properly differentiate illegal returns.
|
||||||
|
.Sh BUGS
|
||||||
|
Ignores the current locale.
|
@ -1,3 +1,6 @@
|
|||||||
|
.\" $NetBSD: strtonum.3,v 1.2 2015/01/19 11:47:41 wiz Exp $
|
||||||
|
.\" $OpenBSD: strtonum.3,v 1.17 2013/08/14 06:32:28 jmc Exp $
|
||||||
|
.\"
|
||||||
.\" Copyright (c) 2004 Ted Unangst
|
.\" Copyright (c) 2004 Ted Unangst
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" Permission to use, copy, modify, and distribute this software for any
|
||||||
@ -12,17 +15,15 @@
|
|||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
.\"
|
.\"
|
||||||
.\" $OpenBSD: strtonum.3,v 1.12 2005/10/26 11:37:58 jmc Exp $
|
.Dd January 18, 2015
|
||||||
.\" $FreeBSD$
|
.Dt strtonum 3bsd
|
||||||
.\"
|
|
||||||
.Dd April 29, 2004
|
|
||||||
.Dt STRTONUM 3bsd
|
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strtonum
|
.Nm strtonum
|
||||||
.Nd reliably convert string value to an integer
|
.Nd reliably convert string value to an integer
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In limits.h
|
.In limits.h
|
||||||
@ -45,14 +46,6 @@ function converts the string in
|
|||||||
to a
|
to a
|
||||||
.Vt "long long"
|
.Vt "long long"
|
||||||
value.
|
value.
|
||||||
The
|
|
||||||
.Fn strtonum
|
|
||||||
function was designed to facilitate safe, robust programming
|
|
||||||
and overcome the shortcomings of the
|
|
||||||
.Xr atoi 3
|
|
||||||
and
|
|
||||||
.Xr strtol 3
|
|
||||||
family of interfaces.
|
|
||||||
.Pp
|
.Pp
|
||||||
The string may begin with an arbitrary amount of whitespace
|
The string may begin with an arbitrary amount of whitespace
|
||||||
(as determined by
|
(as determined by
|
||||||
@ -112,15 +105,13 @@ The above example will guarantee that the value of iterations is between
|
|||||||
1 and 64 (inclusive).
|
1 and 64 (inclusive).
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
.Bl -tag -width Er
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The given string did not consist solely of digit characters; or
|
||||||
|
.Ar minval
|
||||||
|
was larger than
|
||||||
|
.Ar maxval .
|
||||||
.It Bq Er ERANGE
|
.It Bq Er ERANGE
|
||||||
The given string was out of range.
|
The given string was out of range.
|
||||||
.It Bq Er EINVAL
|
|
||||||
The given string did not consist solely of digit characters.
|
|
||||||
.It Bq Er EINVAL
|
|
||||||
The supplied
|
|
||||||
.Fa minval
|
|
||||||
was larger than
|
|
||||||
.Fa maxval .
|
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
If an error occurs,
|
If an error occurs,
|
||||||
@ -142,21 +133,59 @@ The string did not consist solely of digit characters.
|
|||||||
.Xr atoll 3 ,
|
.Xr atoll 3 ,
|
||||||
.Xr sscanf 3 ,
|
.Xr sscanf 3 ,
|
||||||
.Xr strtod 3 ,
|
.Xr strtod 3 ,
|
||||||
|
.Xr strtoi 3bsd ,
|
||||||
.Xr strtol 3 ,
|
.Xr strtol 3 ,
|
||||||
.Xr strtoul 3
|
.Xr strtoll 3 ,
|
||||||
|
.Xr strtou 3bsd ,
|
||||||
|
.Xr strtoul 3 ,
|
||||||
|
.Xr strtoull 3
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
|
||||||
.Fn strtonum
|
.Fn strtonum
|
||||||
function is a
|
is a
|
||||||
.Bx
|
.Bx
|
||||||
extension.
|
extension.
|
||||||
The existing alternatives, such as
|
|
||||||
.Xr atoi 3
|
|
||||||
and
|
|
||||||
.Xr strtol 3 ,
|
|
||||||
are either impossible or difficult to use safely.
|
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
.ds doc-operating-system-NetBSD-8.0 8.0
|
||||||
The
|
The
|
||||||
.Fn strtonum
|
.Fn strtonum
|
||||||
function first appeared in
|
function first appeared in
|
||||||
.Ox 3.6 .
|
.Ox 3.6 .
|
||||||
|
.Fn strtonum
|
||||||
|
was redesigned in
|
||||||
|
.Nx 8.0
|
||||||
|
as
|
||||||
|
.Xr strtoi 3bsd
|
||||||
|
and
|
||||||
|
.Xr strtou 3bsd .
|
||||||
|
.Sh CAVEATS
|
||||||
|
The
|
||||||
|
.Fn strtonum
|
||||||
|
function was designed to facilitate safe,
|
||||||
|
robust programming and overcome the shortcomings of the
|
||||||
|
.Xr atoi 3
|
||||||
|
and
|
||||||
|
.Xr strtol 3
|
||||||
|
family of interfaces, however there are problems with the
|
||||||
|
.Fn strtonum
|
||||||
|
API:
|
||||||
|
.Bl -dash
|
||||||
|
.It
|
||||||
|
will return 0 on failure; 0 might not be in range, so that necessitates
|
||||||
|
an error check even if you want to avoid it
|
||||||
|
.It
|
||||||
|
does not differentiate 'illegal' returns, so we can't tell the
|
||||||
|
difference between partial and no conversions
|
||||||
|
.It
|
||||||
|
returns english strings
|
||||||
|
.It
|
||||||
|
can't set the base, or find where the conversion ended
|
||||||
|
.It
|
||||||
|
hardcodes long long integer type
|
||||||
|
.El
|
||||||
|
To overcome the shortcomings of
|
||||||
|
.Fn strtonum
|
||||||
|
.Nx
|
||||||
|
provides
|
||||||
|
.Xr strtou 3bsd
|
||||||
|
and
|
||||||
|
.Xr strtoi 3bsd .
|
||||||
|
246
man/strtou.3bsd
Normal file
246
man/strtou.3bsd
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
.\" $NetBSD: strtou.3,v 1.8 2024/01/20 16:13:39 christos Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" from: @(#)strtoul.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\"
|
||||||
|
.\" Created by Kamil Rytarowski, based on ID:
|
||||||
|
.\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
|
||||||
|
.\"
|
||||||
|
.Dd January 20, 2024
|
||||||
|
.Dt strtou 3bsd
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm strtou
|
||||||
|
.Nd convert a string value to an uintmax_t integer
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In inttypes.h
|
||||||
|
(See
|
||||||
|
.Xr libbsd 7
|
||||||
|
for include usage.)
|
||||||
|
.Ft uintmax_t
|
||||||
|
.Fo strtou
|
||||||
|
.Fa "const char * restrict nptr"
|
||||||
|
.Fa "char ** restrict endptr"
|
||||||
|
.Fa "int base"
|
||||||
|
.Fa "uintmax_t lo"
|
||||||
|
.Fa "uintmax_t hi"
|
||||||
|
.Fa "int *rstatus"
|
||||||
|
.Fc
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function converts the string in
|
||||||
|
.Fa nptr
|
||||||
|
to an
|
||||||
|
.Ft uintmax_t
|
||||||
|
value.
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function uses internally
|
||||||
|
.Xr strtoumax 3
|
||||||
|
and ensures that the result is always in the range [
|
||||||
|
.Fa lo ..
|
||||||
|
.Fa hi
|
||||||
|
].
|
||||||
|
In addition it always places
|
||||||
|
.Dv 0
|
||||||
|
on success or a conversion status in the
|
||||||
|
.Fa rstatus
|
||||||
|
argument, avoiding the
|
||||||
|
.Dv errno
|
||||||
|
gymnastics the other functions require.
|
||||||
|
The
|
||||||
|
.Fa rstatus
|
||||||
|
argument can be
|
||||||
|
.Dv NULL
|
||||||
|
if conversion status is to be ignored.
|
||||||
|
.Pp
|
||||||
|
The string may begin with an arbitrary amount of white space
|
||||||
|
(as determined by
|
||||||
|
.Xr isspace 3 )
|
||||||
|
followed by a single optional
|
||||||
|
.Ql +
|
||||||
|
or
|
||||||
|
.Ql -
|
||||||
|
sign.
|
||||||
|
If
|
||||||
|
.Fa base
|
||||||
|
is zero or 16,
|
||||||
|
the string may then include a
|
||||||
|
.Ql 0x
|
||||||
|
or
|
||||||
|
.Ql 0X
|
||||||
|
prefix,
|
||||||
|
and the number will be read in base 16; otherwise,
|
||||||
|
.\" if the
|
||||||
|
.\" .Fa base
|
||||||
|
.\" is zero or 2,
|
||||||
|
.\" the string may then include a
|
||||||
|
.\" .Ql 0b
|
||||||
|
.\" or
|
||||||
|
.\" .Ql 0B
|
||||||
|
.\" prefix,
|
||||||
|
.\" and the number will be read in base 2; otherwise,
|
||||||
|
a zero
|
||||||
|
.Fa base
|
||||||
|
is taken as 10 (decimal) unless the next character is
|
||||||
|
.Ql 0 ,
|
||||||
|
in which case it is taken as 8 (octal).
|
||||||
|
.Pp
|
||||||
|
The remainder of the string is converted to an
|
||||||
|
.Em uintmax_t
|
||||||
|
value in the obvious manner,
|
||||||
|
stopping at the end of the string
|
||||||
|
or at the first character which is not a valid digit
|
||||||
|
in the given base.
|
||||||
|
(In bases above 10, the letter
|
||||||
|
.Ql A
|
||||||
|
in either upper or lower case
|
||||||
|
represents 10,
|
||||||
|
.Ql B
|
||||||
|
represents 11, and so forth, with
|
||||||
|
.Ql Z
|
||||||
|
representing 35.)
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fa endptr
|
||||||
|
is non-nil,
|
||||||
|
.Fn strtou
|
||||||
|
stores the address of the first invalid character in
|
||||||
|
.Fa *endptr .
|
||||||
|
If there were no digits at all, however,
|
||||||
|
.Fn strtou
|
||||||
|
stores the original value of
|
||||||
|
.Fa nptr
|
||||||
|
in
|
||||||
|
.Fa *endptr .
|
||||||
|
(Thus, if
|
||||||
|
.Fa *nptr
|
||||||
|
is not
|
||||||
|
.Ql \e0
|
||||||
|
but
|
||||||
|
.Fa **endptr
|
||||||
|
is
|
||||||
|
.Ql \e0
|
||||||
|
on return, the entire string was valid.)
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function
|
||||||
|
always returns the closest value in the range specified by
|
||||||
|
the
|
||||||
|
.Fa lo
|
||||||
|
and
|
||||||
|
.Fa hi
|
||||||
|
arguments.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Va errno
|
||||||
|
value is guaranteed to be left unchanged.
|
||||||
|
.Pp
|
||||||
|
Errors are stored as the conversion status in the
|
||||||
|
.Fa rstatus
|
||||||
|
argument.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
The following example will always return a number in
|
||||||
|
.Dv [1..99]
|
||||||
|
range no matter what the input is, and warn if the conversion failed.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
int e;
|
||||||
|
uintmax_t lval = strtou(buf, NULL, 0, 1, 99, &e);
|
||||||
|
if (e)
|
||||||
|
warnc(e, "conversion of `%s' to a number failed, using %ju",
|
||||||
|
buf, lval);
|
||||||
|
.Ed
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er ECANCELED
|
||||||
|
The string did not contain any characters that were converted.
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The
|
||||||
|
.Ar base
|
||||||
|
is not between 2 and 36 and does not contain the special value 0.
|
||||||
|
.It Bq Er ENOTSUP
|
||||||
|
The string contained non-numeric characters that did not get converted.
|
||||||
|
In this case,
|
||||||
|
.Fa endptr
|
||||||
|
points to the first unconverted character.
|
||||||
|
.It Bq Er ERANGE
|
||||||
|
The given string was out of range; the value converted has been clamped;
|
||||||
|
or the range given was invalid, i.e.
|
||||||
|
.Fa lo
|
||||||
|
>
|
||||||
|
.Fa hi .
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The range check is more important than the unconverted characters check,
|
||||||
|
and it is performed first.
|
||||||
|
If a program needs to know if there were unconverted characters when an
|
||||||
|
out of range number has been provided, it needs to supply and test
|
||||||
|
.Fa endptr.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr atof 3 ,
|
||||||
|
.Xr atoi 3 ,
|
||||||
|
.Xr atol 3 ,
|
||||||
|
.Xr atoll 3 ,
|
||||||
|
.Xr strtod 3 ,
|
||||||
|
.Xr strtoi 3bsd ,
|
||||||
|
.Xr strtoimax 3 ,
|
||||||
|
.Xr strtol 3 ,
|
||||||
|
.Xr strtoll 3 ,
|
||||||
|
.Xr strtoul 3 ,
|
||||||
|
.Xr strtoull 3 ,
|
||||||
|
.Xr strtoumax 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function is a
|
||||||
|
.Nx
|
||||||
|
extension.
|
||||||
|
.Sh HISTORY
|
||||||
|
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function first appeared in
|
||||||
|
.Nx 7.0 .
|
||||||
|
.Ox
|
||||||
|
introduced the
|
||||||
|
.Xr strtonum 3bsd
|
||||||
|
function for the same purpose, but the interface makes it impossible to
|
||||||
|
properly differentiate illegal returns.
|
||||||
|
.Sh BUGS
|
||||||
|
Ignores the current locale.
|
@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
|
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd June 7, 2010
|
.Dd June 7, 2010
|
||||||
.Dt TIMERADD 3bsd
|
.Dt timeradd 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm timeradd ,
|
.Nm timeradd ,
|
||||||
@ -47,6 +47,7 @@
|
|||||||
.Nd operations on time structure
|
.Nd operations on time structure
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/time.h
|
.In sys/time.h
|
||||||
|
133
man/timeval.3bsd
133
man/timeval.3bsd
@ -1,133 +0,0 @@
|
|||||||
.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
|
|
||||||
.\"
|
|
||||||
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
|
|
||||||
.\" All rights reserved.
|
|
||||||
.\"
|
|
||||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
||||||
.\" by Jukka Ruohonen.
|
|
||||||
.\"
|
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
|
||||||
.\" modification, are permitted provided that the following conditions
|
|
||||||
.\" are met:
|
|
||||||
.\" 1. Redistributions of source code must retain the above copyright
|
|
||||||
.\" notice, this list of conditions and the following disclaimer.
|
|
||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
|
||||||
.\"
|
|
||||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
||||||
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
||||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
.\"
|
|
||||||
.Dd April 12, 2011
|
|
||||||
.Dt TIMEVAL 3bsd
|
|
||||||
.Os
|
|
||||||
.Sh NAME
|
|
||||||
.Nm timeval ,
|
|
||||||
.Nm timespec
|
|
||||||
.Nd time structures
|
|
||||||
.Sh LIBRARY
|
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
|
||||||
.Lb libbsd
|
|
||||||
.Sh SYNOPSIS
|
|
||||||
.In sys/time.h
|
|
||||||
(See
|
|
||||||
.Xr libbsd 7
|
|
||||||
for include usage.)
|
|
||||||
.Ft void
|
|
||||||
.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
|
|
||||||
.Ft void
|
|
||||||
.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
|
|
||||||
.Sh DESCRIPTION
|
|
||||||
The
|
|
||||||
.In sys/time.h
|
|
||||||
header, included by
|
|
||||||
.In time.h ,
|
|
||||||
defines various structures related to time and timers.
|
|
||||||
.Bl -enum -offset 1n
|
|
||||||
.It
|
|
||||||
The following structure is used by
|
|
||||||
.Xr gettimeofday 2 ,
|
|
||||||
among others:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
struct timeval {
|
|
||||||
time_t tv_sec;
|
|
||||||
suseconds_t tv_usec;
|
|
||||||
};
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
The
|
|
||||||
.Va tv_sec
|
|
||||||
member represents the elapsed time, in whole seconds.
|
|
||||||
The
|
|
||||||
.Va tv_usec
|
|
||||||
member captures rest of the elapsed time,
|
|
||||||
represented as the number of microseconds.
|
|
||||||
.It
|
|
||||||
The following structure is used by
|
|
||||||
.Xr nanosleep 2 ,
|
|
||||||
among others:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
struct timespec {
|
|
||||||
time_t tv_sec;
|
|
||||||
long tv_nsec;
|
|
||||||
};
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
The
|
|
||||||
.Va tv_sec
|
|
||||||
member is again the elapsed time in whole seconds.
|
|
||||||
The
|
|
||||||
.Va tv_nsec
|
|
||||||
member represents the rest of the elapsed time in nanoseconds.
|
|
||||||
.Pp
|
|
||||||
A microsecond is equal to one millionth of a second,
|
|
||||||
1000 nanoseconds, or 1/1000 milliseconds.
|
|
||||||
To ease the conversions, the macros
|
|
||||||
.Fn TIMEVAL_TO_TIMESPEC
|
|
||||||
and
|
|
||||||
.Fn TIMESPEC_TO_TIMEVAL
|
|
||||||
can be used to convert between
|
|
||||||
.Em struct timeval
|
|
||||||
and
|
|
||||||
.Em struct timespec .
|
|
||||||
.El
|
|
||||||
.Sh EXAMPLES
|
|
||||||
It can be stressed that the traditional
|
|
||||||
.Tn UNIX
|
|
||||||
.Va timeval
|
|
||||||
and
|
|
||||||
.Va timespec
|
|
||||||
structures represent elapsed time, measured by the system clock.
|
|
||||||
The following sketch implements a function suitable
|
|
||||||
for use in a context where the
|
|
||||||
.Va timespec
|
|
||||||
structure is required for a conditional timeout:
|
|
||||||
.Bd -literal -offset indent
|
|
||||||
static void
|
|
||||||
example(struct timespec *spec, time_t minutes)
|
|
||||||
{
|
|
||||||
struct timeval elapsed;
|
|
||||||
|
|
||||||
(void)gettimeofday(&elapsed, NULL);
|
|
||||||
|
|
||||||
_DIAGASSERT(spec != NULL);
|
|
||||||
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
|
|
||||||
|
|
||||||
/* Add the offset for timeout in minutes. */
|
|
||||||
spec->tv_sec = spec->tv_sec + minutes * 60;
|
|
||||||
}
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
A better alternative would use the more precise
|
|
||||||
.Xr clock_gettime 2 .
|
|
||||||
.Sh SEE ALSO
|
|
||||||
.Xr timeradd 3bsd
|
|
400
man/tree.3bsd
400
man/tree.3bsd
@ -1,37 +1,30 @@
|
|||||||
.\" $OpenBSD: tree.3,v 1.7 2002/06/12 01:09:20 provos Exp $
|
.\" $OpenBSD: tree.3,v 1.30 2019/05/10 13:13:14 florian Exp $
|
||||||
.\"
|
.\"/*
|
||||||
.\" Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
.\" * Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
.\" All rights reserved.
|
.\" * All rights reserved.
|
||||||
.\"
|
.\" *
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" * Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" * modification, are permitted provided that the following conditions
|
||||||
.\" are met:
|
.\" * are met:
|
||||||
.\" 1. Redistributions of source code must retain the above copyright
|
.\" * 1. Redistributions of source code must retain the above copyright
|
||||||
.\" notice, this list of conditions and the following disclaimer.
|
.\" * notice, this list of conditions and the following disclaimer.
|
||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
.\" * 2. Redistributions in binary form must reproduce the above copyright
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
.\" * notice, this list of conditions and the following disclaimer in the
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
.\" * documentation and/or other materials provided with the distribution.
|
||||||
.\" 3. All advertising materials mentioning features or use of this software
|
.\" *
|
||||||
.\" must display the following acknowledgement:
|
.\" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
.\" This product includes software developed by Niels Provos.
|
.\" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
.\" 4. The name of the author may not be used to endorse or promote products
|
.\" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
.\" derived from this software without specific prior written permission.
|
.\" * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
.\"
|
.\" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
.\" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
.\" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
.\" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
.\" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
.\" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
.\" */
|
||||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
.Dd May 10, 2019
|
||||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
.Dt tree 3bsd
|
||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
.\"
|
|
||||||
.\" $FreeBSD$
|
|
||||||
.\"
|
|
||||||
.Dd December 27, 2007
|
|
||||||
.Dt TREE 3bsd
|
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm SPLAY_PROTOTYPE ,
|
.Nm SPLAY_PROTOTYPE ,
|
||||||
@ -70,98 +63,108 @@
|
|||||||
.Nm RB_RIGHT ,
|
.Nm RB_RIGHT ,
|
||||||
.Nm RB_PARENT ,
|
.Nm RB_PARENT ,
|
||||||
.Nm RB_FOREACH ,
|
.Nm RB_FOREACH ,
|
||||||
|
.Nm RB_FOREACH_SAFE ,
|
||||||
.Nm RB_FOREACH_REVERSE ,
|
.Nm RB_FOREACH_REVERSE ,
|
||||||
|
.Nm RB_FOREACH_REVERSE_SAFE ,
|
||||||
.Nm RB_INIT ,
|
.Nm RB_INIT ,
|
||||||
.Nm RB_INSERT ,
|
.Nm RB_INSERT ,
|
||||||
.Nm RB_REMOVE
|
.Nm RB_REMOVE
|
||||||
.Nd implementations of splay and red-black trees
|
.Nd implementations of splay and red-black trees
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/tree.h
|
.In sys/tree.h
|
||||||
(See
|
(See
|
||||||
.Xr libbsd 7
|
.Xr libbsd 7
|
||||||
for include usage.)
|
for include usage.)
|
||||||
.Fn SPLAY_PROTOTYPE NAME TYPE FIELD CMP
|
.Pp
|
||||||
.Fn SPLAY_GENERATE NAME TYPE FIELD CMP
|
.Fn SPLAY_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn SPLAY_ENTRY TYPE
|
.Fn SPLAY_GENERATE "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn SPLAY_HEAD HEADNAME TYPE
|
.Fn SPLAY_ENTRY "TYPE"
|
||||||
|
.Fn SPLAY_HEAD "HEADNAME" "TYPE"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_INITIALIZER "SPLAY_HEAD *head"
|
.Fn SPLAY_INITIALIZER "SPLAY_HEAD *head"
|
||||||
.Fn SPLAY_ROOT "SPLAY_HEAD *head"
|
.Fn SPLAY_ROOT "SPLAY_HEAD *head"
|
||||||
.Ft bool
|
.Ft "int"
|
||||||
.Fn SPLAY_EMPTY "SPLAY_HEAD *head"
|
.Fn SPLAY_EMPTY "SPLAY_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_NEXT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
.Fn SPLAY_NEXT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_MIN NAME "SPLAY_HEAD *head"
|
.Fn SPLAY_MIN "NAME" "SPLAY_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_MAX NAME "SPLAY_HEAD *head"
|
.Fn SPLAY_MAX "NAME" "SPLAY_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_FIND NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
.Fn SPLAY_FIND "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
.Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
.Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
||||||
.Fn SPLAY_FOREACH VARNAME NAME "SPLAY_HEAD *head"
|
.Fn SPLAY_FOREACH "VARNAME" "NAME" "SPLAY_HEAD *head"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn SPLAY_INIT "SPLAY_HEAD *head"
|
.Fn SPLAY_INIT "SPLAY_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_INSERT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
.Fn SPLAY_INSERT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn SPLAY_REMOVE NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
.Fn SPLAY_REMOVE "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
.Fn RB_PROTOTYPE NAME TYPE FIELD CMP
|
.Pp
|
||||||
.Fn RB_PROTOTYPE_STATIC NAME TYPE FIELD CMP
|
.Fn RB_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn RB_GENERATE NAME TYPE FIELD CMP
|
.Fn RB_PROTOTYPE_STATIC "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn RB_GENERATE_STATIC NAME TYPE FIELD CMP
|
.Fn RB_GENERATE "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn RB_ENTRY TYPE
|
.Fn RB_GENERATE_STATIC "NAME" "TYPE" "FIELD" "CMP"
|
||||||
.Fn RB_HEAD HEADNAME TYPE
|
.Fn RB_ENTRY "TYPE"
|
||||||
|
.Fn RB_HEAD "HEADNAME" "TYPE"
|
||||||
.Fn RB_INITIALIZER "RB_HEAD *head"
|
.Fn RB_INITIALIZER "RB_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_ROOT "RB_HEAD *head"
|
.Fn RB_ROOT "RB_HEAD *head"
|
||||||
.Ft "bool"
|
.Ft "int"
|
||||||
.Fn RB_EMPTY "RB_HEAD *head"
|
.Fn RB_EMPTY "RB_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_NEXT NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_NEXT "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_PREV NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_PREV "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_MIN NAME "RB_HEAD *head"
|
.Fn RB_MIN "NAME" "RB_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_MAX NAME "RB_HEAD *head"
|
.Fn RB_MAX "NAME" "RB_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_FIND NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_FIND "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_NFIND NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_NFIND "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME"
|
.Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME"
|
.Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME"
|
.Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
.Fn RB_FOREACH VARNAME NAME "RB_HEAD *head"
|
.Fn RB_FOREACH "VARNAME" "NAME" "RB_HEAD *head"
|
||||||
.Fn RB_FOREACH_REVERSE VARNAME NAME "RB_HEAD *head"
|
.Fn RB_FOREACH_SAFE "VARNAME" "NAME" "RB_HEAD *head" "TEMP_VARNAME"
|
||||||
|
.Fn RB_FOREACH_REVERSE "VARNAME" "NAME" "RB_HEAD *head"
|
||||||
|
.Fn RB_FOREACH_REVERSE_SAFE "VARNAME" "NAME" "RB_HEAD *head" "TEMP_VARNAME"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn RB_INIT "RB_HEAD *head"
|
.Fn RB_INIT "RB_HEAD *head"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_INSERT NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_INSERT "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Ft "struct TYPE *"
|
.Ft "struct TYPE *"
|
||||||
.Fn RB_REMOVE NAME "RB_HEAD *head" "struct TYPE *elm"
|
.Fn RB_REMOVE "NAME" "RB_HEAD *head" "struct TYPE *elm"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
These macros define data structures for different types of trees:
|
These macros define data structures for different types of trees:
|
||||||
splay trees and red-black trees.
|
splay trees and red-black trees.
|
||||||
.Pp
|
.Pp
|
||||||
In the macro definitions,
|
In the macro definitions,
|
||||||
.Fa TYPE
|
.Fa TYPE
|
||||||
is the name tag of a user defined structure that must contain a field of type
|
is the name tag of a user defined structure that must contain a field named
|
||||||
.Vt SPLAY_ENTRY ,
|
.Fa FIELD ,
|
||||||
|
of type
|
||||||
|
.Li SPLAY_ENTRY
|
||||||
or
|
or
|
||||||
.Vt RB_ENTRY ,
|
.Li RB_ENTRY .
|
||||||
named
|
|
||||||
.Fa ENTRYNAME .
|
|
||||||
The argument
|
The argument
|
||||||
.Fa HEADNAME
|
.Fa HEADNAME
|
||||||
is the name tag of a user defined structure that must be declared
|
is the name tag of a user defined structure that must be declared
|
||||||
using the macros
|
using the macros
|
||||||
.Fn SPLAY_HEAD ,
|
.Fn SPLAY_HEAD
|
||||||
or
|
or
|
||||||
.Fn RB_HEAD .
|
.Fn RB_HEAD .
|
||||||
The argument
|
The argument
|
||||||
@ -169,46 +172,38 @@ The argument
|
|||||||
has to be a unique name prefix for every tree that is defined.
|
has to be a unique name prefix for every tree that is defined.
|
||||||
.Pp
|
.Pp
|
||||||
The function prototypes are declared with
|
The function prototypes are declared with
|
||||||
.Fn SPLAY_PROTOTYPE ,
|
.Li SPLAY_PROTOTYPE ,
|
||||||
.Fn RB_PROTOTYPE ,
|
.Li RB_PROTOTYPE ,
|
||||||
or
|
or
|
||||||
.Fn RB_PROTOTYPE_STATIC .
|
.Li RB_PROTOTYPE_STATIC .
|
||||||
The function bodies are generated with
|
The function bodies are generated with
|
||||||
.Fn SPLAY_GENERATE ,
|
.Li SPLAY_GENERATE ,
|
||||||
.Fn RB_GENERATE ,
|
.Li RB_GENERATE ,
|
||||||
or
|
or
|
||||||
.Fn RB_GENERATE_STATIC .
|
.Li RB_GENERATE_STATIC .
|
||||||
See the examples below for further explanation of how these macros are used.
|
See the examples below for further explanation of how these macros are used.
|
||||||
.Sh SPLAY TREES
|
.Sh SPLAY TREES
|
||||||
A splay tree is a self-organizing data structure.
|
A splay tree is a self-organizing data structure.
|
||||||
Every operation on the tree causes a splay to happen.
|
Every operation on the tree causes a splay to happen.
|
||||||
The splay moves the requested
|
The splay moves the requested node to the root of the tree and partly
|
||||||
node to the root of the tree and partly rebalances it.
|
rebalances it.
|
||||||
.Pp
|
.Pp
|
||||||
This has the benefit that request locality causes faster lookups as
|
This has the benefit that request locality causes faster lookups as
|
||||||
the requested nodes move to the top of the tree.
|
the requested nodes move to the top of the tree.
|
||||||
On the other hand, every lookup causes memory writes.
|
On the other hand, every lookup causes memory writes.
|
||||||
.Pp
|
.Pp
|
||||||
The Balance Theorem bounds the total access time for
|
The Balance Theorem bounds the total access time for m operations
|
||||||
.Ar m
|
and n inserts on an initially empty tree as O((m + n)lg n).
|
||||||
operations and
|
The amortized cost for a sequence of m accesses to a splay tree is O(lg n).
|
||||||
.Ar n
|
|
||||||
inserts on an initially empty tree as
|
|
||||||
.Fn O "\*[lp]m + n\*[rp]lg n" .
|
|
||||||
The
|
|
||||||
amortized cost for a sequence of
|
|
||||||
.Ar m
|
|
||||||
accesses to a splay tree is
|
|
||||||
.Fn O "lg n" .
|
|
||||||
.Pp
|
.Pp
|
||||||
A splay tree is headed by a structure defined by the
|
A splay tree is headed by a structure defined by the
|
||||||
.Fn SPLAY_HEAD
|
.Fn SPLAY_HEAD
|
||||||
macro.
|
macro.
|
||||||
A
|
A
|
||||||
|
.Fa SPLAY_HEAD
|
||||||
structure is declared as follows:
|
structure is declared as follows:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn SPLAY_HEAD HEADNAME TYPE
|
SPLAY_HEAD(HEADNAME, TYPE) head;
|
||||||
.Va head ;
|
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
where
|
where
|
||||||
@ -247,16 +242,15 @@ macro, but should be used only once.
|
|||||||
Finally,
|
Finally,
|
||||||
the
|
the
|
||||||
.Fa CMP
|
.Fa CMP
|
||||||
argument is the name of a function used to compare tree nodes
|
argument is the name of a function used to compare trees' nodes
|
||||||
with each other.
|
with each other.
|
||||||
The function takes two arguments of type
|
The function takes two arguments of type
|
||||||
.Vt "struct TYPE *" .
|
.Fa "struct TYPE *" .
|
||||||
If the first argument is smaller than the second, the function returns a
|
If the first argument is smaller than the second, the function returns a
|
||||||
value smaller than zero.
|
value smaller than zero.
|
||||||
If they are equal, the function returns zero.
|
If they are equal, the function returns zero.
|
||||||
Otherwise, it should return a value greater than zero.
|
Otherwise, it should return a value greater than zero.
|
||||||
The compare
|
The compare function defines the order of the tree elements.
|
||||||
function defines the order of the tree elements.
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn SPLAY_INIT
|
.Fn SPLAY_INIT
|
||||||
@ -266,11 +260,8 @@ macro initializes the tree referenced by
|
|||||||
The splay tree can also be initialized statically by using the
|
The splay tree can also be initialized statically by using the
|
||||||
.Fn SPLAY_INITIALIZER
|
.Fn SPLAY_INITIALIZER
|
||||||
macro like this:
|
macro like this:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn SPLAY_HEAD HEADNAME TYPE
|
SPLAY_HEAD(HEADNAME, TYPE) head = SPLAY_INITIALIZER(&head);
|
||||||
.Va head
|
|
||||||
=
|
|
||||||
.Fn SPLAY_INITIALIZER &head ;
|
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -278,6 +269,11 @@ The
|
|||||||
macro inserts the new element
|
macro inserts the new element
|
||||||
.Fa elm
|
.Fa elm
|
||||||
into the tree.
|
into the tree.
|
||||||
|
Upon success,
|
||||||
|
.Va NULL
|
||||||
|
is returned.
|
||||||
|
If a matching element already exists in the tree, the insertion is
|
||||||
|
aborted, and a pointer to the existing element is returned.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn SPLAY_REMOVE
|
.Fn SPLAY_REMOVE
|
||||||
@ -285,6 +281,11 @@ macro removes the element
|
|||||||
.Fa elm
|
.Fa elm
|
||||||
from the tree pointed by
|
from the tree pointed by
|
||||||
.Fa head .
|
.Fa head .
|
||||||
|
Upon success, a pointer to the removed element is returned.
|
||||||
|
.Va NULL
|
||||||
|
is returned if
|
||||||
|
.Fa elm
|
||||||
|
is not present in the tree.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn SPLAY_FIND
|
.Fn SPLAY_FIND
|
||||||
@ -292,7 +293,7 @@ macro can be used to find a particular element in the tree.
|
|||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
struct TYPE find, *res;
|
struct TYPE find, *res;
|
||||||
find.key = 30;
|
find.key = 30;
|
||||||
res = SPLAY_FIND(NAME, head, &find);
|
res = SPLAY_FIND(NAME, &head, &find);
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -309,8 +310,8 @@ for (np = SPLAY_MIN(NAME, &head); np != NULL; np = SPLAY_NEXT(NAME, &head, np))
|
|||||||
Or, for simplicity, one can use the
|
Or, for simplicity, one can use the
|
||||||
.Fn SPLAY_FOREACH
|
.Fn SPLAY_FOREACH
|
||||||
macro:
|
macro:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn SPLAY_FOREACH np NAME head
|
SPLAY_FOREACH(np, NAME, &head)
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -320,29 +321,28 @@ macro should be used to check whether a splay tree is empty.
|
|||||||
A red-black tree is a binary search tree with the node color as an
|
A red-black tree is a binary search tree with the node color as an
|
||||||
extra attribute.
|
extra attribute.
|
||||||
It fulfills a set of conditions:
|
It fulfills a set of conditions:
|
||||||
.Bl -enum -offset indent
|
.Pp
|
||||||
|
.Bl -enum -compact -offset indent
|
||||||
.It
|
.It
|
||||||
Every search path from the root to a leaf consists of the same number of
|
every search path from the root to a leaf consists of the same number of
|
||||||
black nodes.
|
black nodes,
|
||||||
.It
|
.It
|
||||||
Each red node (except for the root) has a black parent.
|
each red node (except for the root) has a black parent,
|
||||||
.It
|
.It
|
||||||
Each leaf node is black.
|
each leaf node is black.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Every operation on a red-black tree is bounded as
|
Every operation on a red-black tree is bounded as O(lg n).
|
||||||
.Fn O "lg n" .
|
The maximum height of a red-black tree is 2lg (n+1).
|
||||||
The maximum height of a red-black tree is
|
|
||||||
.Fn 2lg "n + 1" .
|
|
||||||
.Pp
|
.Pp
|
||||||
A red-black tree is headed by a structure defined by the
|
A red-black tree is headed by a structure defined by the
|
||||||
.Fn RB_HEAD
|
.Fn RB_HEAD
|
||||||
macro.
|
macro.
|
||||||
A
|
A
|
||||||
|
.Fa RB_HEAD
|
||||||
structure is declared as follows:
|
structure is declared as follows:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn RB_HEAD HEADNAME TYPE
|
RB_HEAD(HEADNAME, TYPE) head;
|
||||||
.Va head ;
|
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
where
|
where
|
||||||
@ -360,7 +360,7 @@ their prototypes need to be declared with the
|
|||||||
.Fn RB_PROTOTYPE
|
.Fn RB_PROTOTYPE
|
||||||
or
|
or
|
||||||
.Fn RB_PROTOTYPE_STATIC
|
.Fn RB_PROTOTYPE_STATIC
|
||||||
macro,
|
macros,
|
||||||
where
|
where
|
||||||
.Fa NAME
|
.Fa NAME
|
||||||
is a unique identifier for this particular tree.
|
is a unique identifier for this particular tree.
|
||||||
@ -377,7 +377,7 @@ The function bodies are generated with the
|
|||||||
.Fn RB_GENERATE
|
.Fn RB_GENERATE
|
||||||
or
|
or
|
||||||
.Fn RB_GENERATE_STATIC
|
.Fn RB_GENERATE_STATIC
|
||||||
macro.
|
macros.
|
||||||
These macros take the same arguments as the
|
These macros take the same arguments as the
|
||||||
.Fn RB_PROTOTYPE
|
.Fn RB_PROTOTYPE
|
||||||
and
|
and
|
||||||
@ -387,16 +387,15 @@ macros, but should be used only once.
|
|||||||
Finally,
|
Finally,
|
||||||
the
|
the
|
||||||
.Fa CMP
|
.Fa CMP
|
||||||
argument is the name of a function used to compare tree nodes
|
argument is the name of a function used to compare trees' nodes
|
||||||
with each other.
|
with each other.
|
||||||
The function takes two arguments of type
|
The function takes two arguments of type
|
||||||
.Vt "struct TYPE *" .
|
.Fa "struct TYPE *" .
|
||||||
If the first argument is smaller than the second, the function returns a
|
If the first argument is smaller than the second, the function returns a
|
||||||
value smaller than zero.
|
value smaller than zero.
|
||||||
If they are equal, the function returns zero.
|
If they are equal, the function returns zero.
|
||||||
Otherwise, it should return a value greater than zero.
|
Otherwise, it should return a value greater than zero.
|
||||||
The compare
|
The compare function defines the order of the tree elements.
|
||||||
function defines the order of the tree elements.
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn RB_INIT
|
.Fn RB_INIT
|
||||||
@ -406,11 +405,8 @@ macro initializes the tree referenced by
|
|||||||
The red-black tree can also be initialized statically by using the
|
The red-black tree can also be initialized statically by using the
|
||||||
.Fn RB_INITIALIZER
|
.Fn RB_INITIALIZER
|
||||||
macro like this:
|
macro like this:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn RB_HEAD HEADNAME TYPE
|
RB_HEAD(HEADNAME, TYPE) head = RB_INITIALIZER(&head);
|
||||||
.Va head
|
|
||||||
=
|
|
||||||
.Fn RB_INITIALIZER &head ;
|
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -418,6 +414,11 @@ The
|
|||||||
macro inserts the new element
|
macro inserts the new element
|
||||||
.Fa elm
|
.Fa elm
|
||||||
into the tree.
|
into the tree.
|
||||||
|
Upon success,
|
||||||
|
.Va NULL
|
||||||
|
is returned.
|
||||||
|
If a matching element already exists in the tree, the insertion is
|
||||||
|
aborted, and a pointer to the existing element is returned.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn RB_REMOVE
|
.Fn RB_REMOVE
|
||||||
@ -425,16 +426,24 @@ macro removes the element
|
|||||||
.Fa elm
|
.Fa elm
|
||||||
from the tree pointed by
|
from the tree pointed by
|
||||||
.Fa head .
|
.Fa head .
|
||||||
|
.Fn RB_REMOVE
|
||||||
|
returns
|
||||||
|
.Fa elm .
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn RB_FIND
|
.Fn RB_FIND
|
||||||
and
|
and
|
||||||
.Fn RB_NFIND
|
.Fn RB_NFIND
|
||||||
macros can be used to find a particular element in the tree.
|
macros can be used to find a particular element in the tree.
|
||||||
|
.Fn RB_FIND
|
||||||
|
finds the node with the same key as
|
||||||
|
.Fa elm .
|
||||||
|
.Fn RB_NFIND
|
||||||
|
finds the first node greater than or equal to the search key.
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
struct TYPE find, *res;
|
struct TYPE find, *res;
|
||||||
find.key = 30;
|
find.key = 30;
|
||||||
res = RB_FIND(NAME, head, &find);
|
res = RB_FIND(NAME, &head, &find);
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
@ -445,26 +454,122 @@ The
|
|||||||
and
|
and
|
||||||
.Fn RB_PREV
|
.Fn RB_PREV
|
||||||
macros can be used to traverse the tree:
|
macros can be used to traverse the tree:
|
||||||
.Pp
|
.Bd -literal -offset indent
|
||||||
.Dl "for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))"
|
for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Or, for simplicity, one can use the
|
Or, for simplicity, one can use the
|
||||||
.Fn RB_FOREACH
|
.Fn RB_FOREACH
|
||||||
or
|
or
|
||||||
.Fn RB_FOREACH_REVERSE
|
.Fn RB_FOREACH_REVERSE
|
||||||
macro:
|
macros:
|
||||||
.Bd -ragged -offset indent
|
.Bd -literal -offset indent
|
||||||
.Fn RB_FOREACH np NAME head
|
RB_FOREACH(np, NAME, &head)
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
|
The macros
|
||||||
|
.Fn RB_FOREACH_SAFE
|
||||||
|
and
|
||||||
|
.Fn RB_FOREACH_REVERSE_SAFE
|
||||||
|
traverse the tree referenced by head
|
||||||
|
in a forward or reverse direction respectively,
|
||||||
|
assigning each element in turn to np.
|
||||||
|
However, unlike their unsafe counterparts,
|
||||||
|
they permit both the removal of np
|
||||||
|
as well as freeing it from within the loop safely
|
||||||
|
without interfering with the traversal.
|
||||||
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn RB_EMPTY
|
.Fn RB_EMPTY
|
||||||
macro should be used to check whether a red-black tree is empty.
|
macro should be used to check whether a red-black tree is empty.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
The following example demonstrates how to declare a red-black tree
|
||||||
|
holding integers.
|
||||||
|
Values are inserted into it and the contents of the tree are printed
|
||||||
|
in order.
|
||||||
|
Lastly, the internal structure of the tree is printed.
|
||||||
|
.Bd -literal -offset 3n
|
||||||
|
#include <sys/tree.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct node {
|
||||||
|
RB_ENTRY(node) entry;
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
int intcmp(struct node *, struct node *);
|
||||||
|
void print_tree(struct node *);
|
||||||
|
|
||||||
|
int
|
||||||
|
intcmp(struct node *e1, struct node *e2)
|
||||||
|
{
|
||||||
|
return (e1->i < e2->i ? -1 : e1->i > e2->i);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_HEAD(inttree, node) head = RB_INITIALIZER(&head);
|
||||||
|
RB_PROTOTYPE(inttree, node, entry, intcmp)
|
||||||
|
RB_GENERATE(inttree, node, entry, intcmp)
|
||||||
|
|
||||||
|
int testdata[] = {
|
||||||
|
20, 16, 17, 13, 3, 6, 1, 8, 2, 4, 10, 19, 5, 9, 12, 15, 18,
|
||||||
|
7, 11, 14
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
print_tree(struct node *n)
|
||||||
|
{
|
||||||
|
struct node *left, *right;
|
||||||
|
|
||||||
|
if (n == NULL) {
|
||||||
|
printf("nil");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
left = RB_LEFT(n, entry);
|
||||||
|
right = RB_RIGHT(n, entry);
|
||||||
|
if (left == NULL && right == NULL)
|
||||||
|
printf("%d", n->i);
|
||||||
|
else {
|
||||||
|
printf("%d(", n->i);
|
||||||
|
print_tree(left);
|
||||||
|
printf(",");
|
||||||
|
print_tree(right);
|
||||||
|
printf(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct node *n;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
|
||||||
|
if ((n = malloc(sizeof(struct node))) == NULL)
|
||||||
|
err(1, NULL);
|
||||||
|
n->i = testdata[i];
|
||||||
|
RB_INSERT(inttree, &head, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_FOREACH(n, inttree, &head) {
|
||||||
|
printf("%d\en", n->i);
|
||||||
|
}
|
||||||
|
print_tree(RB_ROOT(&head));
|
||||||
|
printf("\en");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
.Ed
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr queue 3bsd
|
||||||
|
.Sh HISTORY
|
||||||
|
The tree macros first appeared in
|
||||||
|
.Fx 4.6 .
|
||||||
.Sh NOTES
|
.Sh NOTES
|
||||||
Trying to free a tree in the following way is a common error:
|
Trying to free a tree in the following way is a common error:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
SPLAY_FOREACH(var, NAME, head) {
|
SPLAY_FOREACH(var, NAME, &head) {
|
||||||
SPLAY_REMOVE(NAME, head, var);
|
SPLAY_REMOVE(NAME, &head, var);
|
||||||
free(var);
|
free(var);
|
||||||
}
|
}
|
||||||
free(head);
|
free(head);
|
||||||
@ -472,36 +577,17 @@ free(head);
|
|||||||
.Pp
|
.Pp
|
||||||
Since
|
Since
|
||||||
.Va var
|
.Va var
|
||||||
is freed, the
|
is free'd, the
|
||||||
.Fn FOREACH
|
.Fn FOREACH
|
||||||
macro refers to a pointer that may have been reallocated already.
|
macro refers to a pointer that may have been reallocated already.
|
||||||
Proper code needs a second variable.
|
Proper code needs a second variable.
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) {
|
for (var = SPLAY_MIN(NAME, &head); var != NULL; var = nxt) {
|
||||||
nxt = SPLAY_NEXT(NAME, head, var);
|
nxt = SPLAY_NEXT(NAME, &head, var);
|
||||||
SPLAY_REMOVE(NAME, head, var);
|
SPLAY_REMOVE(NAME, &head, var);
|
||||||
free(var);
|
free(var);
|
||||||
}
|
}
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
|
||||||
Both
|
|
||||||
.Fn RB_INSERT
|
|
||||||
and
|
|
||||||
.Fn SPLAY_INSERT
|
|
||||||
return
|
|
||||||
.Dv NULL
|
|
||||||
if the element was inserted in the tree successfully, otherwise they
|
|
||||||
return a pointer to the element with the colliding key.
|
|
||||||
.Pp
|
|
||||||
Accordingly,
|
|
||||||
.Fn RB_REMOVE
|
|
||||||
and
|
|
||||||
.Fn SPLAY_REMOVE
|
|
||||||
return the pointer to the removed element otherwise they return
|
|
||||||
.Dv NULL
|
|
||||||
to indicate an error.
|
|
||||||
.Sh SEE ALSO
|
|
||||||
.Xr queue 3bsd
|
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
The author of the tree macros is
|
The author of the tree macros is
|
||||||
.An Niels Provos .
|
.An Niels Provos .
|
||||||
|
1
man/uid_from_user.3bsd
Normal file
1
man/uid_from_user.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/pwcache.3bsd
|
204
man/unvis.3bsd
204
man/unvis.3bsd
@ -1,4 +1,4 @@
|
|||||||
.\" $OpenBSD: unvis.3,v 1.15 2005/07/22 03:16:58 jaredy Exp $
|
.\" $NetBSD: unvis.3,v 1.29 2017/10/24 19:14:55 abhinav Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1989, 1991, 1993
|
.\" Copyright (c) 1989, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
@ -27,16 +27,21 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
|
||||||
.Dt UNVIS 3bsd
|
.\"
|
||||||
|
.Dd March 12, 2011
|
||||||
|
.Dt unvis 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm unvis ,
|
.Nm unvis ,
|
||||||
.Nm strunvis ,
|
.Nm strunvis ,
|
||||||
.Nm strnunvis
|
.Nm strnunvis ,
|
||||||
|
.Nm strunvisx ,
|
||||||
|
.Nm strnunvisx
|
||||||
.Nd decode a visual representation of characters
|
.Nd decode a visual representation of characters
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In vis.h
|
.In vis.h
|
||||||
@ -44,88 +49,91 @@
|
|||||||
.Xr libbsd 7
|
.Xr libbsd 7
|
||||||
for include usage.)
|
for include usage.)
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn unvis "char *cp" "char c" "int *astate" "int flag"
|
.Fn unvis "char *cp" "int c" "int *astate" "int flag"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn strunvis "char *dst" "char *src"
|
.Fn strunvis "char *dst" "const char *src"
|
||||||
.Ft ssize_t
|
.Ft int
|
||||||
.Fn strnunvis "char *dst" "char *src" "size_t size"
|
.Fn strnunvis "char *dst" "size_t dlen" "const char *src"
|
||||||
|
.Ft int
|
||||||
|
.Fn strunvisx "char *dst" "const char *src" "int flag"
|
||||||
|
.Ft int
|
||||||
|
.Fn strnunvisx "char *dst" "size_t dlen" "const char *src" "int flag"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn unvis ,
|
.Fn unvis ,
|
||||||
.Fn strunvis
|
.Fn strunvis
|
||||||
and
|
and
|
||||||
.Fn strnunvis
|
.Fn strunvisx
|
||||||
functions are used to decode a visual representation of characters,
|
functions
|
||||||
as produced by the
|
are used to decode a visual representation of characters, as produced
|
||||||
|
by the
|
||||||
.Xr vis 3bsd
|
.Xr vis 3bsd
|
||||||
function, back into the original form.
|
function, back into
|
||||||
|
the original form.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
is called with successive characters in
|
function is called with successive characters in
|
||||||
.Fa c
|
.Ar c
|
||||||
until a valid
|
until a valid sequence is recognized, at which time the decoded
|
||||||
sequence is recognized, at which time the decoded character is
|
character is available at the character pointed to by
|
||||||
available at the character pointed to by
|
.Ar cp .
|
||||||
.Fa cp .
|
|
||||||
.Pp
|
.Pp
|
||||||
|
The
|
||||||
.Fn strunvis
|
.Fn strunvis
|
||||||
decodes the characters pointed to by
|
function decodes the characters pointed to by
|
||||||
.Fa src
|
.Ar src
|
||||||
into the buffer pointed to by
|
into the buffer pointed to by
|
||||||
.Fa dst .
|
.Ar dst .
|
||||||
.Pp
|
|
||||||
.Fn strnunvis
|
|
||||||
decodes the characters pointed to by
|
|
||||||
.Fa src
|
|
||||||
into the buffer pointed to by
|
|
||||||
.Fa dst ,
|
|
||||||
writing a maximum of
|
|
||||||
.Fa size
|
|
||||||
bytes.
|
|
||||||
The
|
The
|
||||||
.Fn strunvis
|
.Fn strunvis
|
||||||
function simply copies
|
function simply copies
|
||||||
.Fa src
|
.Ar src
|
||||||
to
|
to
|
||||||
.Fa dst ,
|
.Ar dst ,
|
||||||
decoding any escape sequences along the way,
|
decoding any escape sequences along the way,
|
||||||
and returns the number of characters placed into
|
and returns the number of characters placed into
|
||||||
.Fa dst ,
|
.Ar dst ,
|
||||||
or \-1 if an
|
or \-1 if an
|
||||||
invalid escape sequence was detected.
|
invalid escape sequence was detected.
|
||||||
The size of
|
The size of
|
||||||
.Fa dst
|
.Ar dst
|
||||||
should be
|
should be equal to the size of
|
||||||
equal to the size of
|
.Ar src
|
||||||
.Fa src
|
|
||||||
(that is, no expansion takes place during decoding).
|
(that is, no expansion takes place during decoding).
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn strunvisx
|
||||||
|
function does the same as the
|
||||||
.Fn strunvis
|
.Fn strunvis
|
||||||
terminates the destination string with a trailing NUL byte;
|
function,
|
||||||
.Fn strnunvis
|
but it allows you to add a flag that specifies the style the string
|
||||||
does so if
|
.Ar src
|
||||||
.Fa size
|
is encoded with.
|
||||||
is larger than 0.
|
Currently, the supported flags are:
|
||||||
|
.Dv VIS_HTTPSTYLE
|
||||||
|
and
|
||||||
|
.Dv VIS_MIMESTYLE .
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
function implements a state machine that can be used to decode an arbitrary
|
function implements a state machine that can be used to decode an
|
||||||
stream of bytes.
|
arbitrary stream of bytes.
|
||||||
All state associated with the bytes being decoded is stored outside the
|
All state associated with the bytes being decoded is stored outside the
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
function (that is, a pointer to the state is passed in), so
|
function (that is, a pointer to the state is passed in), so
|
||||||
calls decoding different streams can be freely intermixed.
|
calls decoding different streams can be freely intermixed.
|
||||||
To start decoding a stream of bytes, first initialize an integer
|
To start decoding a stream of bytes, first initialize an integer to zero.
|
||||||
to zero.
|
|
||||||
Call
|
Call
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
with each successive byte, along with a pointer
|
with each successive byte, along with a pointer
|
||||||
to this integer, and a pointer to a destination character.
|
to this integer, and a pointer to a destination character.
|
||||||
.Sh RETURN VALUES
|
|
||||||
The
|
The
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
function has several return codes that must be handled properly.
|
function has several return codes that must be handled properly.
|
||||||
They are:
|
They are:
|
||||||
.Bl -tag -width UNVIS_VALIDPUSH
|
.Bl -tag -width UNVIS_VALIDPUSH
|
||||||
.It Li \&0 (zero)
|
.It Li \&0 No (zero)
|
||||||
Another character is necessary; nothing has been recognized yet.
|
Another character is necessary; nothing has been recognized yet.
|
||||||
.It Dv UNVIS_VALID
|
.It Dv UNVIS_VALID
|
||||||
A valid character has been recognized and is available at the location
|
A valid character has been recognized and is available at the location
|
||||||
@ -140,30 +148,41 @@ however, the character currently passed in should be passed in again.
|
|||||||
A valid sequence was detected, but no character was produced.
|
A valid sequence was detected, but no character was produced.
|
||||||
This return code is necessary to indicate a logical break between characters.
|
This return code is necessary to indicate a logical break between characters.
|
||||||
.It Dv UNVIS_SYNBAD
|
.It Dv UNVIS_SYNBAD
|
||||||
An invalid escape sequence was detected, or the decoder is in an
|
An invalid escape sequence was detected, or the decoder is in an unknown state.
|
||||||
unknown state.
|
|
||||||
The decoder is placed into the starting state.
|
The decoder is placed into the starting state.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
When all bytes in the stream have been processed, call
|
When all bytes in the stream have been processed, call
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
one more time with
|
one more time with flag set to
|
||||||
.Fa flag
|
|
||||||
set to
|
|
||||||
.Dv UNVIS_END
|
.Dv UNVIS_END
|
||||||
to extract any remaining character (the character passed in is ignored).
|
to extract any remaining character (the character passed in is ignored).
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn strunvis
|
.Fa flag
|
||||||
function returns the number of bytes written (not counting
|
argument is also used to specify the encoding style of the source.
|
||||||
the trailing NUL byte) or \-1 if an error occurred.
|
If set to
|
||||||
|
.Dv VIS_HTTPSTYLE
|
||||||
|
or
|
||||||
|
.Dv VIS_HTTP1808 ,
|
||||||
|
.Fn unvis
|
||||||
|
will decode URI strings as specified in RFC 1808.
|
||||||
|
If set to
|
||||||
|
.Dv VIS_HTTP1866 ,
|
||||||
|
.Fn unvis
|
||||||
|
will decode entity references and numeric character references
|
||||||
|
as specified in RFC 1866.
|
||||||
|
If set to
|
||||||
|
.Dv VIS_MIMESTYLE ,
|
||||||
|
.Fn unvis
|
||||||
|
will decode MIME Quoted-Printable strings as specified in RFC 2045.
|
||||||
|
If set to
|
||||||
|
.Dv VIS_NOESCAPE ,
|
||||||
|
.Fn unvis
|
||||||
|
will not decode
|
||||||
|
.Ql \e
|
||||||
|
quoted characters.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
|
||||||
.Fn strnunvis
|
|
||||||
function returns the number of bytes (not counting the trailing NUL byte)
|
|
||||||
that would be needed to fully convert the input string, or \-1 if an
|
|
||||||
error occurred.
|
|
||||||
.Sh EXAMPLES
|
|
||||||
The following code fragment illustrates a proper use of
|
The following code fragment illustrates a proper use of
|
||||||
.Fn unvis .
|
.Fn unvis .
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
@ -177,25 +196,72 @@ again:
|
|||||||
case UNVIS_NOCHAR:
|
case UNVIS_NOCHAR:
|
||||||
break;
|
break;
|
||||||
case UNVIS_VALID:
|
case UNVIS_VALID:
|
||||||
(void) putchar(out);
|
(void)putchar(out);
|
||||||
break;
|
break;
|
||||||
case UNVIS_VALIDPUSH:
|
case UNVIS_VALIDPUSH:
|
||||||
(void) putchar(out);
|
(void)putchar(out);
|
||||||
goto again;
|
goto again;
|
||||||
case UNVIS_SYNBAD:
|
case UNVIS_SYNBAD:
|
||||||
(void)fprintf(stderr, "bad sequence!\en");
|
errx(EXIT_FAILURE, "Bad character sequence!");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
|
if (unvis(&out, '\e0', &state, UNVIS_END) == UNVIS_VALID)
|
||||||
(void) putchar(out);
|
(void)putchar(out);
|
||||||
.Ed
|
.Ed
|
||||||
|
.Sh ERRORS
|
||||||
|
The functions
|
||||||
|
.Fn strunvis ,
|
||||||
|
.Fn strnunvis ,
|
||||||
|
.Fn strunvisx ,
|
||||||
|
and
|
||||||
|
.Fn strnunvisx
|
||||||
|
will return \-1 on error and set
|
||||||
|
.Va errno
|
||||||
|
to:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
An invalid escape sequence was detected, or the decoder is in an unknown state.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
In addition the functions
|
||||||
|
.Fn strnunvis
|
||||||
|
and
|
||||||
|
.Fn strnunvisx
|
||||||
|
will can also set
|
||||||
|
.Va errno
|
||||||
|
on error to:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er ENOSPC
|
||||||
|
Not enough space to perform the conversion.
|
||||||
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr unvis 1 ,
|
.Xr unvis 1 ,
|
||||||
.Xr vis 1 ,
|
.Xr vis 1 ,
|
||||||
.Xr vis 3bsd
|
.Xr vis 3bsd
|
||||||
|
.Rs
|
||||||
|
.%A R. Fielding
|
||||||
|
.%T Relative Uniform Resource Locators
|
||||||
|
.%O RFC1808
|
||||||
|
.Re
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Fn unvis
|
.Fn unvis
|
||||||
function first appeared in
|
function
|
||||||
|
first appeared in
|
||||||
.Bx 4.4 .
|
.Bx 4.4 .
|
||||||
|
The
|
||||||
|
.Fn strnunvis
|
||||||
|
and
|
||||||
|
.Fn strnunvisx
|
||||||
|
functions appeared in
|
||||||
|
.Nx 6.0 .
|
||||||
|
.Sh BUGS
|
||||||
|
The names
|
||||||
|
.Dv VIS_HTTP1808
|
||||||
|
and
|
||||||
|
.Dv VIS_HTTP1866
|
||||||
|
are wrong.
|
||||||
|
Percent-encoding was defined in RFC 1738, the original RFC for URL.
|
||||||
|
RFC 1866 defines HTML 2.0, an application of SGML, from which it
|
||||||
|
inherits concepts of numeric character references and entity
|
||||||
|
references.
|
||||||
|
1
man/user_from_uid.3bsd
Normal file
1
man/user_from_uid.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/pwcache.3bsd
|
1
man/verrc.3bsd
Normal file
1
man/verrc.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/errc.3bsd
|
448
man/vis.3bsd
448
man/vis.3bsd
@ -1,4 +1,4 @@
|
|||||||
.\" $OpenBSD: vis.3,v 1.23 2005/08/28 19:51:27 millert Exp $
|
.\" $NetBSD: vis.3,v 1.49 2017/08/05 20:22:29 wiz Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1989, 1991, 1993
|
.\" Copyright (c) 1989, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
@ -27,53 +27,88 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
|
||||||
.Dt VIS 3bsd
|
.\"
|
||||||
|
.Dd April 22, 2017
|
||||||
|
.Dt vis 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm vis ,
|
.Nm vis ,
|
||||||
|
.Nm nvis ,
|
||||||
.Nm strvis ,
|
.Nm strvis ,
|
||||||
|
.Nm stravis ,
|
||||||
.Nm strnvis ,
|
.Nm strnvis ,
|
||||||
.Nm strvisx
|
.Nm strvisx ,
|
||||||
|
.Nm strnvisx ,
|
||||||
|
.Nm strenvisx ,
|
||||||
|
.Nm svis ,
|
||||||
|
.Nm snvis ,
|
||||||
|
.Nm strsvis ,
|
||||||
|
.Nm strsnvis ,
|
||||||
|
.Nm strsvisx ,
|
||||||
|
.Nm strsnvisx ,
|
||||||
|
.Nm strsenvisx
|
||||||
.Nd visually encode characters
|
.Nd visually encode characters
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
|
||||||
.In vis.h
|
.In vis.h
|
||||||
(See
|
(See
|
||||||
.Xr libbsd 7
|
.Xr libbsd 7
|
||||||
for include usage.)
|
for include usage.)
|
||||||
.Ft char *
|
.Ft char *
|
||||||
.Fn vis "char *dst" "int c" "int flag" "int nextc"
|
.Fn vis "char *dst" "int c" "int flag" "int nextc"
|
||||||
|
.Ft char *
|
||||||
|
.Fn nvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn strvis "char *dst" "const char *src" "int flag"
|
.Fn strvis "char *dst" "const char *src" "int flag"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn strnvis "char *dst" "const char *src" "size_t size" "int flag"
|
.Fn stravis "char **dst" "const char *src" "int flag"
|
||||||
|
.Ft int
|
||||||
|
.Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
|
.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
|
||||||
|
.Ft int
|
||||||
|
.Fn strnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag"
|
||||||
|
.Ft int
|
||||||
|
.Fn strenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "int *cerr_ptr"
|
||||||
|
.Ft char *
|
||||||
|
.Fn svis "char *dst" "int c" "int flag" "int nextc" "const char *extra"
|
||||||
|
.Ft char *
|
||||||
|
.Fn snvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" "const char *extra"
|
||||||
|
.Ft int
|
||||||
|
.Fn strsvis "char *dst" "const char *src" "int flag" "const char *extra"
|
||||||
|
.Ft int
|
||||||
|
.Fn strsnvis "char *dst" "size_t dlen" "const char *src" "int flag" "const char *extra"
|
||||||
|
.Ft int
|
||||||
|
.Fn strsvisx "char *dst" "const char *src" "size_t len" "int flag" "const char *extra"
|
||||||
|
.Ft int
|
||||||
|
.Fn strsnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra"
|
||||||
|
.Ft int
|
||||||
|
.Fn strsenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra" "int *cerr_ptr"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn vis
|
.Fn vis
|
||||||
function copies into
|
function
|
||||||
|
copies into
|
||||||
.Fa dst
|
.Fa dst
|
||||||
a string which represents the character
|
a string which represents the character
|
||||||
.Fa c .
|
.Fa c .
|
||||||
If
|
If
|
||||||
.Fa c
|
.Fa c
|
||||||
needs no encoding, it is copied in unaltered.
|
needs no encoding, it is copied in unaltered.
|
||||||
The string is NUL terminated and a pointer to the end of the string is
|
The string is null terminated, and a pointer to the end of the string is
|
||||||
returned.
|
returned.
|
||||||
The maximum length of any encoding is four
|
The maximum length of any encoding is four
|
||||||
characters (not including the trailing NUL);
|
bytes (not including the trailing
|
||||||
|
.Dv NUL ) ;
|
||||||
thus, when
|
thus, when
|
||||||
encoding a set of characters into a buffer, the size of the buffer should
|
encoding a set of characters into a buffer, the size of the buffer should
|
||||||
be four times the number of characters encoded, plus one for the trailing
|
be four times the number of bytes encoded, plus one for the trailing
|
||||||
NUL.
|
.Dv NUL .
|
||||||
The
|
The flag parameter is used for altering the default range of
|
||||||
.Fa flag
|
|
||||||
parameter is used for altering the default range of
|
|
||||||
characters considered for encoding and for altering the visual
|
characters considered for encoding and for altering the visual
|
||||||
representation.
|
representation.
|
||||||
The additional character,
|
The additional character,
|
||||||
@ -84,9 +119,11 @@ encoding format (explained below).
|
|||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn strvis ,
|
.Fn strvis ,
|
||||||
.Fn strnvis
|
.Fn stravis ,
|
||||||
|
.Fn strnvis ,
|
||||||
|
.Fn strvisx ,
|
||||||
and
|
and
|
||||||
.Fn strvisx
|
.Fn strnvisx
|
||||||
functions copy into
|
functions copy into
|
||||||
.Fa dst
|
.Fa dst
|
||||||
a visual representation of
|
a visual representation of
|
||||||
@ -94,89 +131,153 @@ the string
|
|||||||
.Fa src .
|
.Fa src .
|
||||||
The
|
The
|
||||||
.Fn strvis
|
.Fn strvis
|
||||||
function encodes characters from
|
and
|
||||||
.Fa src
|
|
||||||
up to the first NUL.
|
|
||||||
The
|
|
||||||
.Fn strnvis
|
.Fn strnvis
|
||||||
function encodes characters from
|
functions encode characters from
|
||||||
.Fa src
|
.Fa src
|
||||||
up to the first NUL or the end of
|
up to the
|
||||||
.Fa dst ,
|
first
|
||||||
as indicated by
|
.Dv NUL .
|
||||||
.Fa size .
|
|
||||||
The
|
The
|
||||||
.Fn strvisx
|
.Fn strvisx
|
||||||
function encodes exactly
|
and
|
||||||
|
.Fn strnvisx
|
||||||
|
functions encode exactly
|
||||||
.Fa len
|
.Fa len
|
||||||
characters from
|
characters from
|
||||||
.Fa src
|
.Fa src
|
||||||
(this
|
(this
|
||||||
is useful for encoding a block of data that may contain NULs).
|
is useful for encoding a block of data that may contain
|
||||||
All three forms NUL terminate
|
.Dv NUL Ns 's ) .
|
||||||
.Fa dst ,
|
Both forms
|
||||||
except for
|
.Dv NUL
|
||||||
.Fn strnvis
|
terminate
|
||||||
when
|
.Fa dst .
|
||||||
.Fa size
|
The size of
|
||||||
is zero, in which case
|
|
||||||
.Fa dst
|
|
||||||
is not touched.
|
|
||||||
For
|
|
||||||
.Fn strvis
|
|
||||||
and
|
|
||||||
.Fn strvisx ,
|
|
||||||
the size of
|
|
||||||
.Fa dst
|
.Fa dst
|
||||||
must be four times the number
|
must be four times the number
|
||||||
of characters encoded from
|
of bytes encoded from
|
||||||
.Fa src
|
.Fa src
|
||||||
(plus one for the NUL).
|
(plus one for the
|
||||||
.Fn strvis
|
.Dv NUL ) .
|
||||||
|
Both
|
||||||
|
forms return the number of characters in
|
||||||
|
.Fa dst
|
||||||
|
(not including the trailing
|
||||||
|
.Dv NUL ) .
|
||||||
|
The
|
||||||
|
.Fn stravis
|
||||||
|
function allocates space dynamically to hold the string.
|
||||||
|
The
|
||||||
|
.Dq Nm n
|
||||||
|
versions of the functions also take an additional argument
|
||||||
|
.Fa dlen
|
||||||
|
that indicates the length of the
|
||||||
|
.Fa dst
|
||||||
|
buffer.
|
||||||
|
If
|
||||||
|
.Fa dlen
|
||||||
|
is not large enough to fit the converted string then the
|
||||||
|
.Fn strnvis
|
||||||
and
|
and
|
||||||
.Fn strvisx
|
.Fn strnvisx
|
||||||
return the number of characters in
|
functions return \-1 and set
|
||||||
.Fa dst
|
.Va errno
|
||||||
(not including the trailing NUL).
|
to
|
||||||
.Fn strnvis
|
.Dv ENOSPC .
|
||||||
returns the length that
|
The
|
||||||
.Fa dst
|
.Fn strenvisx
|
||||||
would become if it were of unlimited size (similar to
|
function takes an additional argument,
|
||||||
.Xr snprintf 3
|
.Fa cerr_ptr ,
|
||||||
or
|
that is used to pass in and out a multibyte conversion error flag.
|
||||||
.Xr strlcpy 3bsd ) .
|
This is useful when processing single characters at a time when
|
||||||
This can be used to detect truncation but it also means that
|
it is possible that the locale may be set to something other
|
||||||
the return value of
|
than the locale of the characters in the input data.
|
||||||
.Fn strnvis
|
.Pp
|
||||||
must not be used without checking it against
|
The functions
|
||||||
.Fa size .
|
.Fn svis ,
|
||||||
|
.Fn snvis ,
|
||||||
|
.Fn strsvis ,
|
||||||
|
.Fn strsnvis ,
|
||||||
|
.Fn strsvisx ,
|
||||||
|
.Fn strsnvisx ,
|
||||||
|
and
|
||||||
|
.Fn strsenvisx
|
||||||
|
correspond to
|
||||||
|
.Fn vis ,
|
||||||
|
.Fn nvis ,
|
||||||
|
.Fn strvis ,
|
||||||
|
.Fn strnvis ,
|
||||||
|
.Fn strvisx ,
|
||||||
|
.Fn strnvisx ,
|
||||||
|
and
|
||||||
|
.Fn strenvisx
|
||||||
|
but have an additional argument
|
||||||
|
.Fa extra ,
|
||||||
|
pointing to a
|
||||||
|
.Dv NUL
|
||||||
|
terminated list of characters.
|
||||||
|
These characters will be copied encoded or backslash-escaped into
|
||||||
|
.Fa dst .
|
||||||
|
These functions are useful e.g. to remove the special meaning
|
||||||
|
of certain characters to shells.
|
||||||
.Pp
|
.Pp
|
||||||
The encoding is a unique, invertible representation composed entirely of
|
The encoding is a unique, invertible representation composed entirely of
|
||||||
graphic characters; it can be decoded back into the original form using
|
graphic characters; it can be decoded back into the original form using
|
||||||
the
|
the
|
||||||
.Xr unvis 3bsd
|
.Xr unvis 3bsd ,
|
||||||
or
|
|
||||||
.Xr strunvis 3bsd
|
.Xr strunvis 3bsd
|
||||||
|
or
|
||||||
|
.Xr strnunvis 3bsd
|
||||||
functions.
|
functions.
|
||||||
.Pp
|
.Pp
|
||||||
There are two parameters that can be controlled: the range of
|
There are two parameters that can be controlled: the range of
|
||||||
characters that are encoded, and the type
|
characters that are encoded (applies only to
|
||||||
of representation used.
|
.Fn vis ,
|
||||||
By default, all non-graphic characters
|
.Fn nvis ,
|
||||||
except space, tab, and newline are encoded
|
.Fn strvis ,
|
||||||
(see
|
.Fn strnvis ,
|
||||||
|
.Fn strvisx ,
|
||||||
|
and
|
||||||
|
.Fn strnvisx ) ,
|
||||||
|
and the type of representation used.
|
||||||
|
By default, all non-graphic characters,
|
||||||
|
except space, tab, and newline are encoded (see
|
||||||
.Xr isgraph 3 ) .
|
.Xr isgraph 3 ) .
|
||||||
The following flags
|
The following flags
|
||||||
alter this:
|
alter this:
|
||||||
.Bl -tag -width VIS_WHITEX
|
.Bl -tag -width VIS_WHITEX
|
||||||
|
.It Dv VIS_DQ
|
||||||
|
Also encode double quotes
|
||||||
.It Dv VIS_GLOB
|
.It Dv VIS_GLOB
|
||||||
Also encode magic characters recognized by
|
Also encode the magic characters
|
||||||
.Xr glob 3
|
.Ql ( * ,
|
||||||
.Pf ( Ql * ,
|
|
||||||
.Ql \&? ,
|
.Ql \&? ,
|
||||||
.Ql \&[ )
|
.Ql \&[ ,
|
||||||
and
|
and
|
||||||
.Ql # .
|
.Ql # )
|
||||||
|
recognized by
|
||||||
|
.Xr glob 3 .
|
||||||
|
.It Dv VIS_SHELL
|
||||||
|
Also encode the meta characters used by shells (in addition to the glob
|
||||||
|
characters):
|
||||||
|
.Ql ( ' ,
|
||||||
|
.Ql ` ,
|
||||||
|
.Ql \&" ,
|
||||||
|
.Ql \&; ,
|
||||||
|
.Ql & ,
|
||||||
|
.Ql < ,
|
||||||
|
.Ql > ,
|
||||||
|
.Ql \&( ,
|
||||||
|
.Ql \&) ,
|
||||||
|
.Ql \&| ,
|
||||||
|
.Ql \&] ,
|
||||||
|
.Ql \e ,
|
||||||
|
.Ql $ ,
|
||||||
|
.Ql \&! ,
|
||||||
|
.Ql \&^ ,
|
||||||
|
and
|
||||||
|
.Ql ~ ) .
|
||||||
.It Dv VIS_SP
|
.It Dv VIS_SP
|
||||||
Also encode space.
|
Also encode space.
|
||||||
.It Dv VIS_TAB
|
.It Dv VIS_TAB
|
||||||
@ -185,34 +286,56 @@ Also encode tab.
|
|||||||
Also encode newline.
|
Also encode newline.
|
||||||
.It Dv VIS_WHITE
|
.It Dv VIS_WHITE
|
||||||
Synonym for
|
Synonym for
|
||||||
.Dv VIS_SP
|
.Dv VIS_SP | VIS_TAB | VIS_NL .
|
||||||
\&|
|
.It Dv VIS_META
|
||||||
.Dv VIS_TAB
|
Synonym for
|
||||||
\&|
|
.Dv VIS_WHITE | VIS_GLOB | VIS_SHELL .
|
||||||
.Dv VIS_NL .
|
|
||||||
.It Dv VIS_SAFE
|
.It Dv VIS_SAFE
|
||||||
Only encode
|
Only encode
|
||||||
.Dq unsafe
|
.Dq unsafe
|
||||||
characters.
|
characters.
|
||||||
These are control characters which may cause common terminals to perform
|
Unsafe means control characters which may cause common terminals to perform
|
||||||
unexpected functions.
|
unexpected functions.
|
||||||
Currently this form allows space,
|
Currently this form allows space, tab, newline, backspace, bell, and
|
||||||
tab, newline, backspace, bell, and return -- in addition
|
return \(em in addition to all graphic characters \(em unencoded.
|
||||||
to all graphic characters -- unencoded.
|
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
There are three forms of encoding.
|
(The above flags have no effect for
|
||||||
All forms use the backslash
|
.Fn svis ,
|
||||||
|
.Fn snvis ,
|
||||||
|
.Fn strsvis ,
|
||||||
|
.Fn strsnvis ,
|
||||||
|
.Fn strsvisx ,
|
||||||
|
and
|
||||||
|
.Fn strsnvisx .
|
||||||
|
When using these functions, place all graphic characters to be
|
||||||
|
encoded in an array pointed to by
|
||||||
|
.Fa extra .
|
||||||
|
In general, the backslash character should be included in this array, see the
|
||||||
|
warning on the use of the
|
||||||
|
.Dv VIS_NOSLASH
|
||||||
|
flag below).
|
||||||
|
.Pp
|
||||||
|
There are six forms of encoding.
|
||||||
|
All forms use the backslash character
|
||||||
.Ql \e
|
.Ql \e
|
||||||
character to introduce a special
|
to introduce a special
|
||||||
sequence; two backslashes are used to represent a real backslash.
|
sequence; two backslashes are used to represent a real backslash,
|
||||||
|
except
|
||||||
|
.Dv VIS_HTTPSTYLE
|
||||||
|
that uses
|
||||||
|
.Ql % ,
|
||||||
|
or
|
||||||
|
.Dv VIS_MIMESTYLE
|
||||||
|
that uses
|
||||||
|
.Ql = .
|
||||||
These are the visual formats:
|
These are the visual formats:
|
||||||
.Bl -tag -width VIS_CSTYLE
|
.Bl -tag -width VIS_CSTYLE
|
||||||
.It (default)
|
.It (default)
|
||||||
Use an
|
Use an
|
||||||
.Ql M
|
.Ql M
|
||||||
to represent meta characters (characters with the 8th
|
to represent meta characters (characters with the 8th
|
||||||
bit set), and use a caret
|
bit set), and use caret
|
||||||
.Ql ^
|
.Ql ^
|
||||||
to represent control characters (see
|
to represent control characters (see
|
||||||
.Xr iscntrl 3 ) .
|
.Xr iscntrl 3 ) .
|
||||||
@ -256,27 +379,27 @@ space.
|
|||||||
.It Dv \e240
|
.It Dv \e240
|
||||||
Represents Meta-space.
|
Represents Meta-space.
|
||||||
.El
|
.El
|
||||||
.Pp
|
|
||||||
.It Dv VIS_CSTYLE
|
.It Dv VIS_CSTYLE
|
||||||
Use C-style backslash sequences to represent standard non-printable
|
Use C-style backslash sequences to represent standard non-printable
|
||||||
characters.
|
characters.
|
||||||
The following sequences are used to represent the indicated characters:
|
The following sequences are used to represent the indicated characters:
|
||||||
.Bd -unfilled -offset indent
|
.Bd -unfilled -offset indent
|
||||||
.Li \ea Tn - BEL No (007)
|
.Li \ea Tn \(em BEL No (007)
|
||||||
.Li \eb Tn - BS No (010)
|
.Li \eb Tn \(em BS No (010)
|
||||||
.Li \ef Tn - NP No (014)
|
.Li \ef Tn \(em NP No (014)
|
||||||
.Li \en Tn - NL No (012)
|
.Li \en Tn \(em NL No (012)
|
||||||
.Li \er Tn - CR No (015)
|
.Li \er Tn \(em CR No (015)
|
||||||
.Li \es Tn - SP No (040)
|
.Li \es Tn \(em SP No (040)
|
||||||
.Li \et Tn - HT No (011)
|
.Li \et Tn \(em HT No (011)
|
||||||
.Li \ev Tn - VT No (013)
|
.Li \ev Tn \(em VT No (013)
|
||||||
.Li \e0 Tn - NUL No (000)
|
.Li \e0 Tn \(em NUL No (000)
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
When using this format, the
|
When using this format, the
|
||||||
.Fa nextc
|
.Fa nextc
|
||||||
parameter is looked at to determine
|
parameter is looked at to determine if a
|
||||||
if a NUL character can be encoded as
|
.Dv NUL
|
||||||
|
character can be encoded as
|
||||||
.Ql \e0
|
.Ql \e0
|
||||||
instead of
|
instead of
|
||||||
.Ql \e000 .
|
.Ql \e000 .
|
||||||
@ -284,13 +407,36 @@ If
|
|||||||
.Fa nextc
|
.Fa nextc
|
||||||
is an octal digit, the latter representation is used to
|
is an octal digit, the latter representation is used to
|
||||||
avoid ambiguity.
|
avoid ambiguity.
|
||||||
|
.Pp
|
||||||
|
Non-printable characters without C-style
|
||||||
|
backslash sequences use the default representation.
|
||||||
.It Dv VIS_OCTAL
|
.It Dv VIS_OCTAL
|
||||||
Use a three digit octal sequence.
|
Use a three digit octal sequence.
|
||||||
The form is
|
The form is
|
||||||
.Ql \eddd
|
.Ql \eddd
|
||||||
where
|
where
|
||||||
.Ar d
|
.Em d
|
||||||
represents an octal digit.
|
represents an octal digit.
|
||||||
|
.It Dv VIS_CSTYLE \&| Dv VIS_OCTAL
|
||||||
|
Same as
|
||||||
|
.Dv VIS_CSTYLE
|
||||||
|
except that non-printable characters without C-style
|
||||||
|
backslash sequences use a three digit octal sequence.
|
||||||
|
.It Dv VIS_HTTPSTYLE
|
||||||
|
Use URI encoding as described in RFC 1738.
|
||||||
|
The form is
|
||||||
|
.Ql %xx
|
||||||
|
where
|
||||||
|
.Em x
|
||||||
|
represents a lower case hexadecimal digit.
|
||||||
|
.It Dv VIS_MIMESTYLE
|
||||||
|
Use MIME Quoted-Printable encoding as described in RFC 2045, only don't
|
||||||
|
break lines and don't handle CRLF.
|
||||||
|
The form is
|
||||||
|
.Ql =XX
|
||||||
|
where
|
||||||
|
.Em X
|
||||||
|
represents an upper case hexadecimal digit.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
There is one additional flag,
|
There is one additional flag,
|
||||||
@ -304,21 +450,113 @@ meta characters as
|
|||||||
.Ql M-C ) .
|
.Ql M-C ) .
|
||||||
With this flag set, the encoding is
|
With this flag set, the encoding is
|
||||||
ambiguous and non-invertible.
|
ambiguous and non-invertible.
|
||||||
|
.Sh MULTIBYTE CHARACTER SUPPORT
|
||||||
|
These functions support multibyte character input.
|
||||||
|
The encoding conversion is influenced by the setting of the
|
||||||
|
.Ev LC_CTYPE
|
||||||
|
environment variable which defines the set of characters
|
||||||
|
that can be copied without encoding.
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Dv VIS_NOLOCALE
|
||||||
|
is set, processing is done assuming the C locale and overriding
|
||||||
|
any other environment settings.
|
||||||
|
.Pp
|
||||||
|
When 8-bit data is present in the input,
|
||||||
|
.Ev LC_CTYPE
|
||||||
|
must be set to the correct locale or to the C locale.
|
||||||
|
If the locales of the data and the conversion are mismatched,
|
||||||
|
multibyte character recognition may fail and encoding will be performed
|
||||||
|
byte-by-byte instead.
|
||||||
|
.Pp
|
||||||
|
As noted above,
|
||||||
|
.Fa dst
|
||||||
|
must be four times the number of bytes processed from
|
||||||
|
.Fa src .
|
||||||
|
But note that each multibyte character can be up to
|
||||||
|
.Dv MB_LEN_MAX
|
||||||
|
bytes
|
||||||
|
.\" (see
|
||||||
|
.\" .Xr multibyte 3 )
|
||||||
|
so in terms of multibyte characters,
|
||||||
|
.Fa dst
|
||||||
|
must be four times
|
||||||
|
.Dv MB_LEN_MAX
|
||||||
|
times the number of characters processed from
|
||||||
|
.Fa src .
|
||||||
|
.Sh ENVIRONMENT
|
||||||
|
.Bl -tag -width ".Ev LC_CTYPE"
|
||||||
|
.It Ev LC_CTYPE
|
||||||
|
Specify the locale of the input data.
|
||||||
|
Set to C if the input data locale is unknown.
|
||||||
|
.El
|
||||||
|
.Sh ERRORS
|
||||||
|
The functions
|
||||||
|
.Fn nvis
|
||||||
|
and
|
||||||
|
.Fn snvis
|
||||||
|
will return
|
||||||
|
.Dv NULL
|
||||||
|
and the functions
|
||||||
|
.Fn strnvis ,
|
||||||
|
.Fn strnvisx ,
|
||||||
|
.Fn strsnvis ,
|
||||||
|
and
|
||||||
|
.Fn strsnvisx ,
|
||||||
|
will return \-1 when the
|
||||||
|
.Fa dlen
|
||||||
|
destination buffer size is not enough to perform the conversion while
|
||||||
|
setting
|
||||||
|
.Va errno
|
||||||
|
to:
|
||||||
|
.Bl -tag -width ".Bq Er ENOSPC"
|
||||||
|
.It Bq Er ENOSPC
|
||||||
|
The destination buffer size is not large enough to perform the conversion.
|
||||||
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr unvis 1 ,
|
.Xr unvis 1 ,
|
||||||
.Xr vis 1 ,
|
.Xr vis 1 ,
|
||||||
.Xr snprintf 3 ,
|
.Xr glob 3 ,
|
||||||
.Xr strlcpy 3bsd ,
|
.\" .Xr multibyte 3 ,
|
||||||
.Xr unvis 3bsd
|
.Xr unvis 3bsd
|
||||||
|
.Rs
|
||||||
|
.%A T. Berners-Lee
|
||||||
|
.%T Uniform Resource Locators (URL)
|
||||||
|
.%O "RFC 1738"
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%T "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"
|
||||||
|
.%O "RFC 2045"
|
||||||
|
.Re
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||||
The
|
The
|
||||||
.Fn vis ,
|
.Fn vis ,
|
||||||
.Fn strvis
|
.Fn strvis ,
|
||||||
and
|
and
|
||||||
.Fn strvisx
|
.Fn strvisx
|
||||||
functions first appeared in
|
functions first appeared in
|
||||||
.Bx 4.4 .
|
.Bx 4.4 .
|
||||||
The
|
The
|
||||||
.Fn strnvis
|
.Fn svis ,
|
||||||
function first appeared in
|
.Fn strsvis ,
|
||||||
.Ox 2.9 .
|
and
|
||||||
|
.Fn strsvisx
|
||||||
|
functions appeared in
|
||||||
|
.Nx 1.5 .
|
||||||
|
The buffer size limited versions of the functions
|
||||||
|
.Po Fn nvis ,
|
||||||
|
.Fn strnvis ,
|
||||||
|
.Fn strnvisx ,
|
||||||
|
.Fn snvis ,
|
||||||
|
.Fn strsnvis ,
|
||||||
|
and
|
||||||
|
.Fn strsnvisx Pc
|
||||||
|
appeared in
|
||||||
|
.Nx 6.0
|
||||||
|
and
|
||||||
|
.Fx 9.2 .
|
||||||
|
Multibyte character support was added in
|
||||||
|
.Nx 7.0
|
||||||
|
and
|
||||||
|
.Fx 9.2 .
|
||||||
|
1
man/vwarnc.3bsd
Normal file
1
man/vwarnc.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/errc.3bsd
|
1
man/warnc.3bsd
Normal file
1
man/warnc.3bsd
Normal file
@ -0,0 +1 @@
|
|||||||
|
.so man3/errc.3bsd
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user