mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-19 21:16:55 +02:00
Compare commits
100 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 | ||
![]() |
0b61c5ffed | ||
![]() |
9ceac74e91 | ||
![]() |
9afc7100a1 | ||
![]() |
22fbd62368 | ||
![]() |
b4f7c065ba |
9
.gitlab-ci.yml
Normal file
9
.gitlab-ci.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
image: debian:stretch
|
||||||
|
|
||||||
|
test:
|
||||||
|
before_script:
|
||||||
|
- apt update -qq
|
||||||
|
- apt install -qq -y --no-install-recommends git gcc make autoconf automake libtool
|
||||||
|
script:
|
||||||
|
- ./autogen && ./configure
|
||||||
|
- make check
|
232
COPYING
232
COPYING
@@ -3,7 +3,7 @@ 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-2006, 2008-2021 Guillem Jover <guillem@hadrons.org>
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
@@ -74,16 +74,18 @@ License: BSD-4-clause-Christopher-G-Demetriou
|
|||||||
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 +105,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 +113,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 +122,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 +161,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 +179,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
|
||||||
@@ -271,8 +243,11 @@ 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.
|
||||||
.
|
.
|
||||||
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
||||||
@@ -293,26 +268,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 +278,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
|
||||||
@@ -367,7 +320,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
|
||||||
@@ -403,25 +356,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 +363,13 @@ Files:
|
|||||||
man/strlcpy.3bsd
|
man/strlcpy.3bsd
|
||||||
man/strtonum.3bsd
|
man/strtonum.3bsd
|
||||||
src/arc4random.c
|
src/arc4random.c
|
||||||
|
src/arc4random_linux.h
|
||||||
src/arc4random_openbsd.h
|
src/arc4random_openbsd.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 +377,12 @@ 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
|
|
||||||
Copyright:
|
Copyright:
|
||||||
Copyright © 2004 Ted Unangst and Todd Miller
|
Copyright © 2004 Ted Unangst and Todd Miller
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
@@ -454,7 +392,7 @@ Copyright:
|
|||||||
Todd C. Miller <Todd.Miller@courtesan.com>
|
Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
Copyright © 2004 Ted Unangst
|
Copyright © 2004 Ted Unangst
|
||||||
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>
|
||||||
@@ -518,17 +456,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 +466,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 +474,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 +547,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
|
||||||
|
3
README
3
README
@@ -5,6 +5,9 @@ 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
|
||||||
--------
|
--------
|
||||||
|
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
|
||||||
|
66
configure.ac
66
configure.ac
@@ -12,8 +12,8 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
|||||||
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||||
|
|
||||||
LIBBSD_ABI_MAJOR=0
|
LIBBSD_ABI_MAJOR=0
|
||||||
LIBBSD_ABI_MINOR=8
|
LIBBSD_ABI_MINOR=11
|
||||||
LIBBSD_ABI_PATCH=6
|
LIBBSD_ABI_PATCH=1
|
||||||
|
|
||||||
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
||||||
AC_SUBST([LIBBSD_ABI])
|
AC_SUBST([LIBBSD_ABI])
|
||||||
@@ -27,6 +27,25 @@ AC_SYS_LARGEFILE
|
|||||||
|
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
|
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([], [])
|
||||||
|
], [
|
||||||
|
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"])
|
||||||
|
|
||||||
# Checks for programs.
|
# Checks for programs.
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
@@ -44,11 +63,27 @@ 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"
|
||||||
|
AC_SEARCH_LIBS([MD5Update], [md], [
|
||||||
|
AC_SEARCH_LIBS([SHA512Update], [md], [
|
||||||
|
MD_LIBS="-lmd"
|
||||||
|
])
|
||||||
|
], [
|
||||||
|
AC_MSG_ERROR([cannot find required message digest functions in libc or libmd])
|
||||||
|
])
|
||||||
|
AC_SUBST([MD_LIBS])
|
||||||
|
LIBS="$saved_LIBS"
|
||||||
|
|
||||||
|
is_windows=no
|
||||||
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], [
|
||||||
|
AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
|
||||||
|
CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
|
||||||
|
])
|
||||||
|
])
|
||||||
AC_SUBST([CLOCK_GETTIME_LIBS])
|
AC_SUBST([CLOCK_GETTIME_LIBS])
|
||||||
LIBS="$saved_LIBS"
|
LIBS="$saved_LIBS"
|
||||||
],
|
],
|
||||||
@@ -56,10 +91,14 @@ AS_CASE([$host_os],
|
|||||||
# Upstream refuses to define this, we will do it ourselves then.
|
# Upstream refuses to define this, we will do it ourselves then.
|
||||||
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
|
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
|
||||||
],
|
],
|
||||||
|
[mingw*], [
|
||||||
|
is_windows=yes
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
|
||||||
|
|
||||||
# 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])
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_C_INLINE
|
AC_C_INLINE
|
||||||
@@ -87,7 +126,7 @@ AC_CACHE_CHECK(
|
|||||||
[[
|
[[
|
||||||
static int rc = 1;
|
static int rc = 1;
|
||||||
static void init(int argc) { if (argc == 1) rc = 0; }
|
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||||
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
|
void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
|
||||||
int main() { return rc; }
|
int main() { return rc; }
|
||||||
]]
|
]]
|
||||||
)],
|
)],
|
||||||
@@ -141,6 +180,23 @@ AC_LINK_IFELSE(
|
|||||||
AC_MSG_RESULT([yes])],
|
AC_MSG_RESULT([yes])],
|
||||||
[AC_MSG_RESULT([no])])
|
[AC_MSG_RESULT([no])])
|
||||||
|
|
||||||
|
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])],
|
||||||
|
[ARC4RANDOM_ATFORK_LIBS="-pthread"
|
||||||
|
AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
|
||||||
|
AC_MSG_RESULT([no])
|
||||||
|
])
|
||||||
|
|
||||||
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
|
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
|
||||||
getauxval getentropy getexecname getline \
|
getauxval getentropy getexecname getline \
|
||||||
pstat_getproc sysconf])
|
pstat_getproc sysconf])
|
||||||
|
@@ -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 \
|
||||||
@@ -13,9 +14,12 @@ nobase_include_HEADERS = \
|
|||||||
bsd/bsd.h \
|
bsd/bsd.h \
|
||||||
bsd/err.h \
|
bsd/err.h \
|
||||||
bsd/getopt.h \
|
bsd/getopt.h \
|
||||||
|
bsd/grp.h \
|
||||||
|
bsd/inttypes.h \
|
||||||
bsd/libutil.h \
|
bsd/libutil.h \
|
||||||
bsd/md5.h \
|
bsd/md5.h \
|
||||||
bsd/nlist.h \
|
bsd/nlist.h \
|
||||||
|
bsd/pwd.h \
|
||||||
bsd/readpassphrase.h \
|
bsd/readpassphrase.h \
|
||||||
bsd/stdio.h \
|
bsd/stdio.h \
|
||||||
bsd/stdlib.h \
|
bsd/stdlib.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
|
||||||
|
51
include/bsd/grp.h
Normal file
51
include/bsd/grp.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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 *);
|
||||||
|
const char *
|
||||||
|
group_from_gid(gid_t, int);
|
||||||
|
__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,31 @@
|
|||||||
/* $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
|
#ifdef LIBBSD_OVERLAY
|
||||||
#define LIBBSD_MD5_H
|
#include_next <md5.h>
|
||||||
|
#else
|
||||||
#include <stdint.h>
|
#include <md5.h>
|
||||||
|
#endif
|
||||||
#define MD5_BLOCK_LENGTH 64
|
|
||||||
#define MD5_DIGEST_LENGTH 16
|
|
||||||
#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;
|
||||||
|
51
include/bsd/pwd.h
Normal file
51
include/bsd/pwd.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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 *);
|
||||||
|
const char *
|
||||||
|
user_from_uid(uid_t, int);
|
||||||
|
__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
|
||||||
|
@@ -42,7 +42,11 @@
|
|||||||
#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>
|
||||||
|
|
||||||
@@ -58,7 +62,7 @@ int dehumanize_number(const char *str, int64_t *size);
|
|||||||
const char *getprogname(void);
|
const char *getprogname(void);
|
||||||
void setprogname(const char *);
|
void setprogname(const char *);
|
||||||
|
|
||||||
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,7 +71,12 @@ 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(__GLIBC__) || \
|
||||||
|
(defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
|
||||||
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
|
#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,7 +33,11 @@
|
|||||||
#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
|
||||||
@@ -42,7 +46,10 @@ size_t strlcat(char *dst, const char *src, size_t siz);
|
|||||||
char *strnstr(const char *str, const char *find, size_t str_len);
|
char *strnstr(const char *str, const char *find, size_t str_len);
|
||||||
void strmode(mode_t mode, char *str);
|
void strmode(mode_t mode, char *str);
|
||||||
|
|
||||||
|
#if !defined(__GLIBC__) || \
|
||||||
|
(defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
|
||||||
void explicit_bzero(void *buf, size_t len);
|
void explicit_bzero(void *buf, size_t len);
|
||||||
|
#endif
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -25,10 +25,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __has_include
|
#ifndef __has_include
|
||||||
#define __has_include 1
|
#define __has_include(x) 1
|
||||||
#endif
|
#endif
|
||||||
#ifndef __has_include_next
|
#ifndef __has_include_next
|
||||||
#define __has_include_next 1
|
#define __has_include_next(x) 1
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
@@ -58,6 +65,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 +83,31 @@
|
|||||||
#define _SYS_CDEFS_H
|
#define _SYS_CDEFS_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#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 >= 0x0405 || __has_attribute(__deprecated__)
|
||||||
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x)))
|
#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 +115,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 +123,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 +131,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)
|
||||||
@@ -120,7 +144,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
#ifndef __unused
|
#ifndef __unused
|
||||||
# if LIBBSD_GCC_VERSION >= 0x0300
|
# if LIBBSD_GCC_VERSION >= 0x0300
|
||||||
# define __unused __attribute__((unused))
|
# define __unused __attribute__((__unused__))
|
||||||
# else
|
# else
|
||||||
# define __unused
|
# define __unused
|
||||||
# endif
|
# endif
|
||||||
@@ -128,15 +152,15 @@
|
|||||||
#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,12 +171,18 @@
|
|||||||
# 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 || !__is_identifier(__builtin_offsetof)
|
||||||
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
||||||
# else
|
# else
|
||||||
# ifndef __cplusplus
|
# ifndef __cplusplus
|
||||||
@@ -177,9 +207,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
|
||||||
|
@@ -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
|
@@ -33,7 +33,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,
|
||||||
|
@@ -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:
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
|
@@ -26,22 +26,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
|
@@ -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,7 +40,11 @@
|
|||||||
#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
|
||||||
|
@@ -165,6 +165,7 @@ dist_man_MANS = \
|
|||||||
fgetln.3bsd \
|
fgetln.3bsd \
|
||||||
fgetwln.3bsd \
|
fgetwln.3bsd \
|
||||||
flopen.3bsd \
|
flopen.3bsd \
|
||||||
|
freezero.3bsd \
|
||||||
fmtcheck.3bsd \
|
fmtcheck.3bsd \
|
||||||
fparseln.3bsd \
|
fparseln.3bsd \
|
||||||
fpurge.3bsd \
|
fpurge.3bsd \
|
||||||
@@ -173,6 +174,8 @@ dist_man_MANS = \
|
|||||||
getmode.3bsd \
|
getmode.3bsd \
|
||||||
getpeereid.3bsd \
|
getpeereid.3bsd \
|
||||||
getprogname.3bsd \
|
getprogname.3bsd \
|
||||||
|
gid_from_group.3bsd \
|
||||||
|
group_from_gid.3bsd \
|
||||||
heapsort.3bsd \
|
heapsort.3bsd \
|
||||||
humanize_number.3bsd \
|
humanize_number.3bsd \
|
||||||
le16dec.3bsd \
|
le16dec.3bsd \
|
||||||
@@ -190,11 +193,13 @@ dist_man_MANS = \
|
|||||||
pidfile_open.3bsd \
|
pidfile_open.3bsd \
|
||||||
pidfile_remove.3bsd \
|
pidfile_remove.3bsd \
|
||||||
pidfile_write.3bsd \
|
pidfile_write.3bsd \
|
||||||
|
pwcache.3bsd \
|
||||||
queue.3bsd \
|
queue.3bsd \
|
||||||
radixsort.3bsd \
|
radixsort.3bsd \
|
||||||
readpassphrase.3bsd \
|
readpassphrase.3bsd \
|
||||||
reallocarray.3bsd \
|
reallocarray.3bsd \
|
||||||
reallocf.3bsd \
|
reallocf.3bsd \
|
||||||
|
recallocarray.3bsd \
|
||||||
setmode.3bsd \
|
setmode.3bsd \
|
||||||
setproctitle.3bsd \
|
setproctitle.3bsd \
|
||||||
setproctitle_init.3bsd \
|
setproctitle_init.3bsd \
|
||||||
@@ -212,7 +217,9 @@ dist_man_MANS = \
|
|||||||
strnstr.3bsd \
|
strnstr.3bsd \
|
||||||
strnunvis.3bsd \
|
strnunvis.3bsd \
|
||||||
strnvis.3bsd \
|
strnvis.3bsd \
|
||||||
|
strtoi.3bsd \
|
||||||
strtonum.3bsd \
|
strtonum.3bsd \
|
||||||
|
strtou.3bsd \
|
||||||
strunvis.3bsd \
|
strunvis.3bsd \
|
||||||
strvis.3bsd \
|
strvis.3bsd \
|
||||||
strvisx.3bsd \
|
strvisx.3bsd \
|
||||||
@@ -221,6 +228,7 @@ dist_man_MANS = \
|
|||||||
timercmp.3bsd \
|
timercmp.3bsd \
|
||||||
timerisset.3bsd \
|
timerisset.3bsd \
|
||||||
timersub.3bsd \
|
timersub.3bsd \
|
||||||
|
timespec.3bsd \
|
||||||
timespecadd.3bsd \
|
timespecadd.3bsd \
|
||||||
timespecclear.3bsd \
|
timespecclear.3bsd \
|
||||||
timespeccmp.3bsd \
|
timespeccmp.3bsd \
|
||||||
@@ -228,7 +236,9 @@ dist_man_MANS = \
|
|||||||
timespecsub.3bsd \
|
timespecsub.3bsd \
|
||||||
timeval.3bsd \
|
timeval.3bsd \
|
||||||
tree.3bsd \
|
tree.3bsd \
|
||||||
|
uid_from_user.3bsd \
|
||||||
unvis.3bsd \
|
unvis.3bsd \
|
||||||
|
user_from_uid.3bsd \
|
||||||
vis.3bsd \
|
vis.3bsd \
|
||||||
wcslcat.3bsd \
|
wcslcat.3bsd \
|
||||||
wcslcpy.3bsd \
|
wcslcpy.3bsd \
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
.Nd arc4 random number generator
|
.Nd arc4 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
|
||||||
@@ -129,7 +130,11 @@ reserved to indicate an error.
|
|||||||
.Xr random 3
|
.Xr random 3
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
These functions first appeared in
|
These functions first appeared in
|
||||||
.Ox 2.1 .
|
.Ox 2.1 ,
|
||||||
|
.Fx 3.0 ,
|
||||||
|
.Nx 1.6 ,
|
||||||
|
and
|
||||||
|
.Dx 1.0 .
|
||||||
.Pp
|
.Pp
|
||||||
The original version of this random number generator used the
|
The original version of this random number generator used the
|
||||||
RC4 (also known as ARC4) algorithm.
|
RC4 (also known as ARC4) algorithm.
|
||||||
|
@@ -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
|
||||||
|
@@ -31,6 +31,10 @@
|
|||||||
.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
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
.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
|
||||||
|
@@ -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 ,
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
.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
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
.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
|
||||||
@@ -72,4 +73,5 @@ pass, making it useful for clearing sensitive memory such as a password.
|
|||||||
The
|
The
|
||||||
.Fn explicit_bzero
|
.Fn explicit_bzero
|
||||||
function first appeared in
|
function first appeared in
|
||||||
.Ox 5.5 .
|
.Ox 5.5 ,
|
||||||
|
glibc 2.25.
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
.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
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
.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
|
|
||||||
.Os
|
|
||||||
.Dt FMTCHECK 3bsd
|
.Dt FMTCHECK 3bsd
|
||||||
|
.Os
|
||||||
.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.
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
.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
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
.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
|
@@ -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
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
.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
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
.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
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
.Nd get or set the program name
|
.Nd get or set the 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
|
||||||
|
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
|
@@ -40,6 +40,7 @@
|
|||||||
.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
|
||||||
|
@@ -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
|
||||||
|
62
man/libbsd.7
62
man/libbsd.7
@@ -1,6 +1,6 @@
|
|||||||
.\" libbsd man page
|
.\" libbsd man page
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright © 2017 Gullem Jover <guillem@hadrons.org>
|
.\" Copyright © 2017-2018 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,7 +24,7 @@
|
|||||||
.\" 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 May 21, 2018
|
||||||
.Dt LIBBSD 7
|
.Dt LIBBSD 7
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -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.
|
||||||
@@ -76,7 +76,7 @@ The package also provides a
|
|||||||
.Pa bsd-ctor
|
.Pa bsd-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
|
.Fn setproctitle_init 3
|
||||||
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 pkg-config 3
|
||||||
@@ -94,6 +94,7 @@ 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 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
|
||||||
@@ -133,7 +134,7 @@ 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 Fn fgetln 3
|
||||||
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
|
||||||
@@ -142,21 +143,56 @@ Use
|
|||||||
.Fn getline 3
|
.Fn 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 Fn fgetwln 3
|
||||||
|
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
|
||||||
|
.Fn fgetwc 3
|
||||||
|
instead, which is available in many systems and required by
|
||||||
|
.St -isoC-99
|
||||||
|
and
|
||||||
|
.St -p1003.1-2001 .
|
||||||
|
.It Fn funopen 3
|
||||||
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 GNU systems the
|
||||||
.Fn fopencookie
|
.Fn 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.
|
||||||
.El
|
.El
|
||||||
|
.Sh SUPERSEDED
|
||||||
|
Some functions have been superseded by implementations in other system
|
||||||
|
libraries, and might disappear on the next SONAME bump, assuming those
|
||||||
|
other implementation have widespread deployment, or the implementations
|
||||||
|
are present in all major
|
||||||
|
.Nm libc
|
||||||
|
for example.
|
||||||
.Pp
|
.Pp
|
||||||
In addition, the MD5 set of digest funtions are now provided by the
|
.Bl -tag -width 4m -compact
|
||||||
|
.It Fn MD5Init 3
|
||||||
|
.It Fn MD5Update 3
|
||||||
|
.It Fn MD5Pad 3
|
||||||
|
.It Fn MD5Final 3
|
||||||
|
.It Fn MD5Transform 3
|
||||||
|
.It Fn MD5End 3
|
||||||
|
.It Fn MD5File 3
|
||||||
|
.It Fn MD5FileChunk 3
|
||||||
|
.It Fn MD5Data 3
|
||||||
|
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, as the ones
|
companion library, so it is advised to switch to use that directly instead.
|
||||||
provided in
|
.It Fn explicit_bzero 3
|
||||||
.Nm libbsd
|
This function is provided by
|
||||||
might disappear on the next SONAME bump.
|
.Nm glibc
|
||||||
|
2.25.
|
||||||
|
.It Fn reallocarray 3
|
||||||
|
This function is provided by
|
||||||
|
.Nm glibc
|
||||||
|
2.26.
|
||||||
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr arc4random 3bsd ,
|
.Xr arc4random 3bsd ,
|
||||||
.Xr bitstring 3bsd ,
|
.Xr bitstring 3bsd ,
|
||||||
@@ -191,7 +227,9 @@ might disappear on the next SONAME bump.
|
|||||||
.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
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
.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,6 +278,16 @@ 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 ,
|
||||||
@@ -251,7 +297,7 @@ library function.
|
|||||||
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 were ported from
|
||||||
|
.Nx
|
||||||
|
and first appeared in
|
||||||
|
.Ox 6.4 .
|
@@ -112,6 +112,10 @@
|
|||||||
.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
|
||||||
|
@@ -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,7 +18,7 @@
|
|||||||
.\" 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
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
.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
|
||||||
|
@@ -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,58 +51,244 @@
|
|||||||
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 ,
|
||||||
|
and glibc 2.26.
|
||||||
|
The
|
||||||
|
.Fn recallocarray
|
||||||
|
function appeared in
|
||||||
|
.Ox 6.1 .
|
||||||
|
The
|
||||||
|
.Fn freezero
|
||||||
|
function appeared in
|
||||||
|
.Ox 6.2 .
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
.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
|
@@ -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
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
.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 sys/types.h
|
||||||
@@ -118,7 +119,7 @@ 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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
.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
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
.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
|
||||||
|
240
man/strtoi.3bsd
Normal file
240
man/strtoi.3bsd
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
.\" $NetBSD: strtoi.3,v 1.7 2017/07/03 21:32:50 wiz 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 November 13, 2015
|
||||||
|
.Dt STRTOI 3bsd
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm strtoi
|
||||||
|
.Nd convert 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 adddition 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 a
|
||||||
|
.Em intmax_t
|
||||||
|
value in the obvious manner,
|
||||||
|
stopping 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
|
||||||
|
.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
|
||||||
|
.Fn 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,10 +15,7 @@
|
|||||||
.\" 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$
|
|
||||||
.\"
|
|
||||||
.Dd April 29, 2004
|
|
||||||
.Dt STRTONUM 3bsd
|
.Dt STRTONUM 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
.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 an
|
||||||
.Bx
|
.Ox
|
||||||
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
|
||||||
|
.Fn strtoi 3bsd
|
||||||
|
and
|
||||||
|
.Fn 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
|
||||||
|
.Fn strtou 3bsd
|
||||||
|
and
|
||||||
|
.Fn strtoi 3bsd .
|
||||||
|
240
man/strtou.3bsd
Normal file
240
man/strtou.3bsd
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
.\" $NetBSD: strtou.3,v 1.7 2017/07/03 21:32:50 wiz 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 November 13, 2015
|
||||||
|
.Dt STRTOU 3bsd
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm strtou
|
||||||
|
.Nd convert a string 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 adddition 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 that does not produce 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
|
||||||
|
.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
|
||||||
|
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function is a
|
||||||
|
.Nx
|
||||||
|
extension.
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function first appeared in
|
||||||
|
.Nx 7.0 .
|
||||||
|
.Ox
|
||||||
|
introduced the
|
||||||
|
.Fn strtonum 3bsd
|
||||||
|
function for the same purpose, but the interface makes it impossible to
|
||||||
|
properly differentiate illegal returns.
|
||||||
|
.Sh BUGS
|
||||||
|
Ignores the current locale.
|
@@ -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
|
||||||
|
1
man/timespec.3bsd
Normal file
1
man/timespec.3bsd
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/timeval.3bsd
|
@@ -36,6 +36,7 @@
|
|||||||
.Nd time structures
|
.Nd time structures
|
||||||
.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
|
||||||
|
@@ -75,6 +75,10 @@
|
|||||||
.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
|
||||||
|
1
man/uid_from_user.3bsd
Normal file
1
man/uid_from_user.3bsd
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/pwcache.3bsd
|
202
man/unvis.3bsd
202
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
|
||||||
|
.\"
|
||||||
|
.Dd March 12, 2011
|
||||||
.Dt UNVIS 3bsd
|
.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
|
446
man/vis.3bsd
446
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
|
||||||
|
.\"
|
||||||
|
.Dd April 22, 2017
|
||||||
.Dt VIS 3bsd
|
.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 .
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
.Nd wide character string manipulation operations
|
.Nd wide character string manipulation operations
|
||||||
.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 wchar.h
|
.In wchar.h
|
||||||
|
@@ -7,8 +7,14 @@ AM_CPPFLAGS = \
|
|||||||
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
||||||
-D__REENTRANT
|
-D__REENTRANT
|
||||||
|
|
||||||
|
if OS_WINDOWS
|
||||||
|
AM_CPPFLAGS += \
|
||||||
|
-D_CRT_SECURE_NO_WARNINGS \
|
||||||
|
-D_CRT_NONSTDC_NO_WARNINGS \
|
||||||
|
$(nil)
|
||||||
|
endif
|
||||||
|
|
||||||
libbsd_la_included_sources = \
|
libbsd_la_included_sources = \
|
||||||
hash/helper.c \
|
|
||||||
getentropy_aix.c \
|
getentropy_aix.c \
|
||||||
getentropy_bsd.c \
|
getentropy_bsd.c \
|
||||||
getentropy_hpux.c \
|
getentropy_hpux.c \
|
||||||
@@ -16,6 +22,7 @@ libbsd_la_included_sources = \
|
|||||||
getentropy_linux.c \
|
getentropy_linux.c \
|
||||||
getentropy_osx.c \
|
getentropy_osx.c \
|
||||||
getentropy_solaris.c \
|
getentropy_solaris.c \
|
||||||
|
getentropy_win.c \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
@@ -26,10 +33,6 @@ EXTRA_DIST = \
|
|||||||
$(libbsd_la_included_sources) \
|
$(libbsd_la_included_sources) \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
CLEANFILES = \
|
|
||||||
hash/md5hl.c \
|
|
||||||
$(nil)
|
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = \
|
pkgconfig_DATA = \
|
||||||
libbsd.pc \
|
libbsd.pc \
|
||||||
@@ -45,24 +48,28 @@ pkgconfig_DATA += libbsd-ctor.pc
|
|||||||
lib_LIBRARIES += libbsd-ctor.a
|
lib_LIBRARIES += libbsd-ctor.a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
hash/md5hl.c: $(srcdir)/hash/helper.c
|
|
||||||
$(AM_V_at) $(MKDIR_P) hash
|
|
||||||
$(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
|
|
||||||
|
|
||||||
libbsd_la_DEPENDENCIES = \
|
libbsd_la_DEPENDENCIES = \
|
||||||
$(libbsd_la_included_sources) \
|
$(libbsd_la_included_sources) \
|
||||||
libbsd.map
|
libbsd.map
|
||||||
libbsd_la_LIBADD = \
|
libbsd_la_LIBADD = \
|
||||||
$(CLOCK_GETTIME_LIBS)
|
$(MD_LIBS) \
|
||||||
|
$(CLOCK_GETTIME_LIBS) \
|
||||||
|
$(ARC4RANDOM_ATFORK_LIBS) \
|
||||||
|
$(nil)
|
||||||
libbsd_la_LDFLAGS = \
|
libbsd_la_LDFLAGS = \
|
||||||
-Wl,--version-script=$(srcdir)/libbsd.map \
|
|
||||||
-version-number $(LIBBSD_ABI)
|
-version-number $(LIBBSD_ABI)
|
||||||
|
if HAVE_LINKER_VERSION_SCRIPT
|
||||||
|
libbsd_la_LDFLAGS += \
|
||||||
|
-Wl,--version-script=$(srcdir)/libbsd.map
|
||||||
|
endif
|
||||||
libbsd_la_SOURCES = \
|
libbsd_la_SOURCES = \
|
||||||
arc4random.c \
|
arc4random.c \
|
||||||
arc4random.h \
|
arc4random.h \
|
||||||
arc4random_unix.h \
|
arc4random_linux.h \
|
||||||
arc4random_openbsd.h \
|
arc4random_openbsd.h \
|
||||||
arc4random_uniform.c \
|
arc4random_uniform.c \
|
||||||
|
arc4random_unix.h \
|
||||||
|
arc4random_win.h \
|
||||||
bsd_getopt.c \
|
bsd_getopt.c \
|
||||||
chacha_private.h \
|
chacha_private.h \
|
||||||
closefrom.c \
|
closefrom.c \
|
||||||
@@ -71,6 +78,7 @@ libbsd_la_SOURCES = \
|
|||||||
expand_number.c \
|
expand_number.c \
|
||||||
explicit_bzero.c \
|
explicit_bzero.c \
|
||||||
fgetln.c \
|
fgetln.c \
|
||||||
|
freezero.c \
|
||||||
fgetwln.c \
|
fgetwln.c \
|
||||||
flopen.c \
|
flopen.c \
|
||||||
fmtcheck.c \
|
fmtcheck.c \
|
||||||
@@ -79,23 +87,22 @@ libbsd_la_SOURCES = \
|
|||||||
funopen.c \
|
funopen.c \
|
||||||
getbsize.c \
|
getbsize.c \
|
||||||
getpeereid.c \
|
getpeereid.c \
|
||||||
hash/md5.c \
|
|
||||||
hash/md5hl.c \
|
|
||||||
hash/sha512.h \
|
|
||||||
hash/sha512c.c \
|
|
||||||
heapsort.c \
|
heapsort.c \
|
||||||
humanize_number.c \
|
humanize_number.c \
|
||||||
inet_net_pton.c \
|
inet_net_pton.c \
|
||||||
local-elf.h \
|
local-elf.h \
|
||||||
local-link.h \
|
local-link.h \
|
||||||
|
md5.c \
|
||||||
merge.c \
|
merge.c \
|
||||||
nlist.c \
|
nlist.c \
|
||||||
pidfile.c \
|
pidfile.c \
|
||||||
progname.c \
|
progname.c \
|
||||||
|
pwcache.c \
|
||||||
radixsort.c \
|
radixsort.c \
|
||||||
readpassphrase.c \
|
readpassphrase.c \
|
||||||
reallocarray.c \
|
reallocarray.c \
|
||||||
reallocf.c \
|
reallocf.c \
|
||||||
|
recallocarray.c \
|
||||||
setmode.c \
|
setmode.c \
|
||||||
setproctitle.c \
|
setproctitle.c \
|
||||||
strlcat.c \
|
strlcat.c \
|
||||||
@@ -103,7 +110,9 @@ libbsd_la_SOURCES = \
|
|||||||
stringlist.c \
|
stringlist.c \
|
||||||
strmode.c \
|
strmode.c \
|
||||||
strnstr.c \
|
strnstr.c \
|
||||||
|
strtoi.c \
|
||||||
strtonum.c \
|
strtonum.c \
|
||||||
|
strtou.c \
|
||||||
timeconv.c \
|
timeconv.c \
|
||||||
unvis.c \
|
unvis.c \
|
||||||
vis.c \
|
vis.c \
|
||||||
|
@@ -39,11 +39,11 @@
|
|||||||
|
|
||||||
#define minimum(a, b) ((a) < (b) ? (a) : (b))
|
#define minimum(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(_MSC_VER)
|
#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
|
||||||
#define inline __inline
|
#define inline __inline
|
||||||
#else /* __GNUC__ || _MSC_VER */
|
#else /* __GNUC__ || __clang__ || _MSC_VER */
|
||||||
#define inline
|
#define inline
|
||||||
#endif /* !__GNUC__ && !_MSC_VER */
|
#endif /* !__GNUC__ && !__clang__ && !_MSC_VER */
|
||||||
|
|
||||||
#define KEYSZ 32
|
#define KEYSZ 32
|
||||||
#define IVSZ 8
|
#define IVSZ 8
|
||||||
|
@@ -34,6 +34,10 @@ getentropy(void *buf, size_t len);
|
|||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
#include "arc4random_openbsd.h"
|
#include "arc4random_openbsd.h"
|
||||||
|
#elif defined(__linux__)
|
||||||
|
#include "arc4random_linux.h"
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "arc4random_win.h"
|
||||||
#else
|
#else
|
||||||
#include "arc4random_unix.h"
|
#include "arc4random_unix.h"
|
||||||
#endif
|
#endif
|
||||||
|
88
src/arc4random_linux.h
Normal file
88
src/arc4random_linux.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/* $OpenBSD: arc4random_linux.h,v 1.11 2016/06/30 12:19:51 bcook Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
||||||
|
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
|
||||||
|
* Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
|
||||||
|
* Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stub functions for portability.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
|
||||||
|
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
|
||||||
|
|
||||||
|
#ifdef HAVE___REGISTER_ATFORK
|
||||||
|
extern void *__dso_handle;
|
||||||
|
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||||
|
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
|
||||||
|
#else
|
||||||
|
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_getentropy_fail(void)
|
||||||
|
{
|
||||||
|
raise(SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static volatile sig_atomic_t _rs_forked;
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rs_forkhandler(void)
|
||||||
|
{
|
||||||
|
_rs_forked = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rs_forkdetect(void)
|
||||||
|
{
|
||||||
|
static pid_t _rs_pid = 0;
|
||||||
|
pid_t pid = getpid();
|
||||||
|
|
||||||
|
/* XXX unusual calls to clone() can bypass checks */
|
||||||
|
if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) {
|
||||||
|
_rs_pid = pid;
|
||||||
|
_rs_forked = 0;
|
||||||
|
if (rs)
|
||||||
|
memset(rs, 0, sizeof(*rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
|
||||||
|
{
|
||||||
|
if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
|
||||||
|
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
|
||||||
|
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
|
||||||
|
munmap(*rsp, sizeof(**rsp));
|
||||||
|
*rsp = NULL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ARC4_ATFORK(_rs_forkhandler);
|
||||||
|
return (0);
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: arc4random_linux.h,v 1.8 2014/08/13 06:04:10 deraadt Exp $ */
|
/* $OpenBSD: arc4random_freebsd.h,v 1.4 2016/06/30 12:19:51 bcook Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
||||||
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
|
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
|
||||||
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
|
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef HAVE___REGISTER_ATFORK
|
||||||
extern void *__dso_handle;
|
extern void *__dso_handle;
|
||||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||||
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
|
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
|
||||||
@@ -84,6 +84,7 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
|
|||||||
if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
|
if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
|
||||||
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
|
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
|
||||||
munmap(*rsp, sizeof(**rsp));
|
munmap(*rsp, sizeof(**rsp));
|
||||||
|
*rsp = NULL;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
78
src/arc4random_win.h
Normal file
78
src/arc4random_win.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/* $OpenBSD: arc4random_win.h,v 1.6 2016/06/30 12:17:29 bcook Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1996, David Mazieres <dm@uun.org>
|
||||||
|
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
|
||||||
|
* Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
|
||||||
|
* Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stub functions for portability.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static volatile HANDLE arc4random_mtx = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize the mutex on the first lock attempt. On collision, each thread
|
||||||
|
* will attempt to allocate a mutex and compare-and-swap it into place as the
|
||||||
|
* global mutex. On failure to swap in the global mutex, the mutex is closed.
|
||||||
|
*/
|
||||||
|
#define _ARC4_LOCK() { \
|
||||||
|
if (!arc4random_mtx) { \
|
||||||
|
HANDLE p = CreateMutex(NULL, FALSE, NULL); \
|
||||||
|
if (InterlockedCompareExchangePointer((void **)&arc4random_mtx, (void *)p, NULL)) \
|
||||||
|
CloseHandle(p); \
|
||||||
|
} \
|
||||||
|
WaitForSingleObject(arc4random_mtx, INFINITE); \
|
||||||
|
} \
|
||||||
|
|
||||||
|
#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_getentropy_fail(void)
|
||||||
|
{
|
||||||
|
TerminateProcess(GetCurrentProcess(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
|
||||||
|
{
|
||||||
|
*rsp = VirtualAlloc(NULL, sizeof(**rsp),
|
||||||
|
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||||
|
if (*rsp == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
*rsxp = VirtualAlloc(NULL, sizeof(**rsxp),
|
||||||
|
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||||
|
if (*rsxp == NULL) {
|
||||||
|
VirtualFree(*rsp, 0, MEM_RELEASE);
|
||||||
|
*rsp = NULL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rs_forkhandler(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rs_forkdetect(void)
|
||||||
|
{
|
||||||
|
}
|
@@ -4,7 +4,7 @@ D. J. Bernstein
|
|||||||
Public domain.
|
Public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $OpenBSD$ */
|
/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
|
||||||
|
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
typedef unsigned int u32;
|
typedef unsigned int u32;
|
||||||
|
104
src/err.c
104
src/err.c
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
* Copyright © 2011, 2019 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
|
||||||
@@ -26,8 +26,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
vwarnc(int code, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", getprogname());
|
||||||
|
if (format) {
|
||||||
|
vfprintf(stderr, format, ap);
|
||||||
|
fprintf(stderr, ": ");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "%s\n", strerror(code));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
warnc(int code, const char *format, ...)
|
warnc(int code, const char *format, ...)
|
||||||
@@ -40,13 +56,15 @@ warnc(int code, const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
vwarnc(int code, const char *format, va_list ap)
|
verrc(int status, int code, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
int tmp = errno;
|
fprintf(stderr, "%s: ", getprogname());
|
||||||
|
if (format) {
|
||||||
errno = code;
|
vfprintf(stderr, format, ap);
|
||||||
vwarn(format, ap);
|
fprintf(stderr, ": ");
|
||||||
errno = tmp;
|
}
|
||||||
|
fprintf(stderr, "%s\n", strerror(code));
|
||||||
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -59,9 +77,75 @@ errc(int status, int code, const char *format, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||||
void
|
void
|
||||||
verrc(int status, int code, const char *format, va_list ap)
|
vwarn(const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
errno = code;
|
vwarnc(errno, format, ap);
|
||||||
verr(status, format, ap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
warn(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
vwarnc(errno, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vwarnx(const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", getprogname());
|
||||||
|
if (format)
|
||||||
|
vfprintf(stderr, format, ap);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
warnx(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
vwarnx(format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
verr(int status, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
verrc(status, errno, format, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
err(int status, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
verrc(status, errno, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
verrx(int eval, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", getprogname());
|
||||||
|
if (format)
|
||||||
|
vfprintf(stderr, format, ap);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
exit(eval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
errx(int eval, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
verrx(eval, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
__attribute__((weak)) void
|
__attribute__((__weak__)) void
|
||||||
__explicit_bzero_hook(void *buf, size_t len)
|
__explicit_bzero_hook(void *buf, size_t len)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ fgetln(FILE *stream, size_t *len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
libbsd_link_warning(fgetln,
|
libbsd_link_warning(fgetln,
|
||||||
"This functions cannot be safely ported, use getline(3) "
|
"This function cannot be safely ported, use getline(3) "
|
||||||
"instead, as it is supported by GNU and POSIX.1-2008.")
|
"instead, as it is supported by GNU and POSIX.1-2008.")
|
||||||
#else
|
#else
|
||||||
#error "Function fgetln() needs to be ported."
|
#error "Function fgetln() needs to be ported."
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#include "local-link.h"
|
||||||
|
|
||||||
struct filewbuf {
|
struct filewbuf {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
wchar_t *wbuf;
|
wchar_t *wbuf;
|
||||||
@@ -85,3 +87,6 @@ fgetwln(FILE *stream, size_t *lenp)
|
|||||||
*lenp = wused;
|
*lenp = wused;
|
||||||
return wused ? fb->wbuf : NULL;
|
return wused ? fb->wbuf : NULL;
|
||||||
}
|
}
|
||||||
|
libbsd_link_warning(fgetwln,
|
||||||
|
"This function cannot be safely ported, use fgetwc(3) "
|
||||||
|
"instead, as it is supported by C99 and POSIX.1-2001.")
|
||||||
|
61
src/flopen.c
61
src/flopen.c
@@ -1,5 +1,7 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007-2009 Dag-Erling Coïdan Smørgrav
|
||||||
* 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
|
||||||
@@ -33,10 +35,19 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
|
|
||||||
int
|
/*
|
||||||
flopen(const char *path, int flags, ...)
|
* Reliably open and lock a file.
|
||||||
|
*
|
||||||
|
* Please do not modify this code without first reading the revision history
|
||||||
|
* and discussing your changes with <des@freebsd.org>. Don't be fooled by the
|
||||||
|
* code's apparent simplicity; there would be no need for this function if it
|
||||||
|
* was easy to get right.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
vflopenat(int dirfd, const char *path, int flags, va_list ap)
|
||||||
{
|
{
|
||||||
int fd, operation, serrno, trunc;
|
int fd, operation, serrno, trunc;
|
||||||
struct stat sb, fsb;
|
struct stat sb, fsb;
|
||||||
@@ -48,11 +59,7 @@ flopen(const char *path, int flags, ...)
|
|||||||
|
|
||||||
mode = 0;
|
mode = 0;
|
||||||
if (flags & O_CREAT) {
|
if (flags & O_CREAT) {
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, flags);
|
|
||||||
mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
|
mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
|
||||||
va_end(ap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
operation = LOCK_EX;
|
operation = LOCK_EX;
|
||||||
@@ -63,7 +70,7 @@ flopen(const char *path, int flags, ...)
|
|||||||
flags &= ~O_TRUNC;
|
flags &= ~O_TRUNC;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((fd = open(path, flags, mode)) == -1)
|
if ((fd = openat(dirfd, path, flags, mode)) == -1)
|
||||||
/* non-existent or no access */
|
/* non-existent or no access */
|
||||||
return (-1);
|
return (-1);
|
||||||
if (flock(fd, operation) == -1) {
|
if (flock(fd, operation) == -1) {
|
||||||
@@ -73,7 +80,7 @@ flopen(const char *path, int flags, ...)
|
|||||||
errno = serrno;
|
errno = serrno;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (stat(path, &sb) == -1) {
|
if (fstatat(dirfd, path, &sb, 0) == -1) {
|
||||||
/* disappeared from under our feet */
|
/* disappeared from under our feet */
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
continue;
|
continue;
|
||||||
@@ -98,6 +105,42 @@ flopen(const char *path, int flags, ...)
|
|||||||
errno = serrno;
|
errno = serrno;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* The following change is provided as a specific example to
|
||||||
|
* avoid.
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
|
||||||
|
serrno = errno;
|
||||||
|
(void)close(fd);
|
||||||
|
errno = serrno;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
flopen(const char *path, int flags, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_start(ap, flags);
|
||||||
|
ret = vflopenat(AT_FDCWD, path, flags, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
flopenat(int dirfd, const char *path, int flags, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_start(ap, flags);
|
||||||
|
ret = vflopenat(dirfd, path, flags, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
174
src/fmtcheck.c
174
src/fmtcheck.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* $NetBSD: fmtcheck.c,v 1.16 2017/12/13 06:43:45 rin Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@@ -24,9 +26,6 @@
|
|||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
* 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
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
|
||||||
* from NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp
|
|
||||||
* from FreeBSD: fmtcheck.c,v 1.8 2005/03/21 08:00:55 das Exp
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
@@ -35,27 +34,33 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
/* __weak_reference(__fmtcheck, fmtcheck); */
|
#ifdef __weak_alias
|
||||||
|
__weak_alias(fmtcheck,__fmtcheck)
|
||||||
|
#endif
|
||||||
|
|
||||||
enum __e_fmtcheck_types {
|
enum __e_fmtcheck_types {
|
||||||
FMTCHECK_START,
|
FMTCHECK_START,
|
||||||
FMTCHECK_SHORT,
|
FMTCHECK_SHORT,
|
||||||
FMTCHECK_INT,
|
FMTCHECK_INT,
|
||||||
|
FMTCHECK_WINTT,
|
||||||
FMTCHECK_LONG,
|
FMTCHECK_LONG,
|
||||||
FMTCHECK_QUAD,
|
FMTCHECK_QUAD,
|
||||||
|
FMTCHECK_INTMAXT,
|
||||||
FMTCHECK_PTRDIFFT,
|
FMTCHECK_PTRDIFFT,
|
||||||
FMTCHECK_SIZET,
|
FMTCHECK_SIZET,
|
||||||
|
FMTCHECK_POINTER,
|
||||||
|
FMTCHECK_CHARPOINTER,
|
||||||
FMTCHECK_SHORTPOINTER,
|
FMTCHECK_SHORTPOINTER,
|
||||||
FMTCHECK_INTPOINTER,
|
FMTCHECK_INTPOINTER,
|
||||||
FMTCHECK_LONGPOINTER,
|
FMTCHECK_LONGPOINTER,
|
||||||
FMTCHECK_QUADPOINTER,
|
FMTCHECK_QUADPOINTER,
|
||||||
|
FMTCHECK_INTMAXTPOINTER,
|
||||||
FMTCHECK_PTRDIFFTPOINTER,
|
FMTCHECK_PTRDIFFTPOINTER,
|
||||||
FMTCHECK_SIZETPOINTER,
|
FMTCHECK_SIZETPOINTER,
|
||||||
#ifndef NO_FLOATING_POINT
|
|
||||||
FMTCHECK_DOUBLE,
|
FMTCHECK_DOUBLE,
|
||||||
FMTCHECK_LONGDOUBLE,
|
FMTCHECK_LONGDOUBLE,
|
||||||
#endif
|
|
||||||
FMTCHECK_STRING,
|
FMTCHECK_STRING,
|
||||||
|
FMTCHECK_WSTRING,
|
||||||
FMTCHECK_WIDTH,
|
FMTCHECK_WIDTH,
|
||||||
FMTCHECK_PRECISION,
|
FMTCHECK_PRECISION,
|
||||||
FMTCHECK_DONE,
|
FMTCHECK_DONE,
|
||||||
@@ -63,6 +68,18 @@ enum __e_fmtcheck_types {
|
|||||||
};
|
};
|
||||||
typedef enum __e_fmtcheck_types EFT;
|
typedef enum __e_fmtcheck_types EFT;
|
||||||
|
|
||||||
|
enum e_modifier {
|
||||||
|
MOD_NONE,
|
||||||
|
MOD_CHAR,
|
||||||
|
MOD_SHORT,
|
||||||
|
MOD_LONG,
|
||||||
|
MOD_QUAD,
|
||||||
|
MOD_INTMAXT,
|
||||||
|
MOD_LONGDOUBLE,
|
||||||
|
MOD_PTRDIFFT,
|
||||||
|
MOD_SIZET,
|
||||||
|
};
|
||||||
|
|
||||||
#define RETURN(pf,f,r) do { \
|
#define RETURN(pf,f,r) do { \
|
||||||
*(pf) = (f); \
|
*(pf) = (f); \
|
||||||
return r; \
|
return r; \
|
||||||
@@ -71,103 +88,168 @@ typedef enum __e_fmtcheck_types EFT;
|
|||||||
static EFT
|
static EFT
|
||||||
get_next_format_from_precision(const char **pf)
|
get_next_format_from_precision(const char **pf)
|
||||||
{
|
{
|
||||||
int sh, lg, quad, longdouble, ptrdifft, sizet;
|
enum e_modifier modifier;
|
||||||
const char *f;
|
const char *f;
|
||||||
|
|
||||||
sh = lg = quad = longdouble = ptrdifft = sizet = 0;
|
|
||||||
|
|
||||||
f = *pf;
|
f = *pf;
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
case 'h':
|
case 'h':
|
||||||
f++;
|
f++;
|
||||||
sh = 1;
|
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
if (*f == 'h') {
|
||||||
|
f++;
|
||||||
|
modifier = MOD_CHAR;
|
||||||
|
} else {
|
||||||
|
modifier = MOD_SHORT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'j':
|
||||||
|
f++;
|
||||||
|
modifier = MOD_INTMAXT;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
f++;
|
f++;
|
||||||
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
if (*f == 'l') {
|
if (*f == 'l') {
|
||||||
f++;
|
f++;
|
||||||
quad = 1;
|
modifier = MOD_QUAD;
|
||||||
} else {
|
} else {
|
||||||
lg = 1;
|
modifier = MOD_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
f++;
|
f++;
|
||||||
quad = 1;
|
modifier = MOD_QUAD;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
f++;
|
f++;
|
||||||
ptrdifft = 1;
|
modifier = MOD_PTRDIFFT;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
f++;
|
f++;
|
||||||
sizet = 1;
|
modifier = MOD_SIZET;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
f++;
|
f++;
|
||||||
longdouble = 1;
|
modifier = MOD_LONGDOUBLE;
|
||||||
break;
|
break;
|
||||||
|
#ifdef WIN32
|
||||||
|
case 'I':
|
||||||
|
f++;
|
||||||
|
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
if (*f == '3' && f[1] == '2') {
|
||||||
|
f += 2;
|
||||||
|
modifier = MOD_NONE;
|
||||||
|
} else if (*f == '6' && f[1] == '4') {
|
||||||
|
f += 2;
|
||||||
|
modifier = MOD_QUAD;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#ifdef _WIN64
|
||||||
|
modifier = MOD_QUAD;
|
||||||
|
#else
|
||||||
|
modifier = MOD_NONE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
|
modifier = MOD_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
if (strchr("diouxX", *f)) {
|
if (strchr("diouxX", *f)) {
|
||||||
if (longdouble)
|
switch (modifier) {
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
case MOD_LONG:
|
||||||
if (lg)
|
|
||||||
RETURN(pf,f,FMTCHECK_LONG);
|
RETURN(pf,f,FMTCHECK_LONG);
|
||||||
if (quad)
|
case MOD_QUAD:
|
||||||
RETURN(pf,f,FMTCHECK_QUAD);
|
RETURN(pf,f,FMTCHECK_QUAD);
|
||||||
if (ptrdifft)
|
case MOD_INTMAXT:
|
||||||
|
RETURN(pf,f,FMTCHECK_INTMAXT);
|
||||||
|
case MOD_PTRDIFFT:
|
||||||
RETURN(pf,f,FMTCHECK_PTRDIFFT);
|
RETURN(pf,f,FMTCHECK_PTRDIFFT);
|
||||||
if (sizet)
|
case MOD_SIZET:
|
||||||
RETURN(pf,f,FMTCHECK_SIZET);
|
RETURN(pf,f,FMTCHECK_SIZET);
|
||||||
RETURN(pf,f,FMTCHECK_INT);
|
case MOD_CHAR:
|
||||||
|
case MOD_SHORT:
|
||||||
|
case MOD_NONE:
|
||||||
|
RETURN(pf,f,FMTCHECK_INT);
|
||||||
|
default:
|
||||||
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (*f == 'n') {
|
if (*f == 'n') {
|
||||||
if (longdouble)
|
switch (modifier) {
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
case MOD_CHAR:
|
||||||
if (sh)
|
RETURN(pf,f,FMTCHECK_CHARPOINTER);
|
||||||
|
case MOD_SHORT:
|
||||||
RETURN(pf,f,FMTCHECK_SHORTPOINTER);
|
RETURN(pf,f,FMTCHECK_SHORTPOINTER);
|
||||||
if (lg)
|
case MOD_LONG:
|
||||||
RETURN(pf,f,FMTCHECK_LONGPOINTER);
|
RETURN(pf,f,FMTCHECK_LONGPOINTER);
|
||||||
if (quad)
|
case MOD_QUAD:
|
||||||
RETURN(pf,f,FMTCHECK_QUADPOINTER);
|
RETURN(pf,f,FMTCHECK_QUADPOINTER);
|
||||||
if (ptrdifft)
|
case MOD_INTMAXT:
|
||||||
|
RETURN(pf,f,FMTCHECK_INTMAXTPOINTER);
|
||||||
|
case MOD_PTRDIFFT:
|
||||||
RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER);
|
RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER);
|
||||||
if (sizet)
|
case MOD_SIZET:
|
||||||
RETURN(pf,f,FMTCHECK_SIZETPOINTER);
|
RETURN(pf,f,FMTCHECK_SIZETPOINTER);
|
||||||
RETURN(pf,f,FMTCHECK_INTPOINTER);
|
case MOD_NONE:
|
||||||
|
RETURN(pf,f,FMTCHECK_INTPOINTER);
|
||||||
|
default:
|
||||||
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (strchr("DOU", *f)) {
|
if (strchr("DOU", *f)) {
|
||||||
if (sh + lg + quad + longdouble + ptrdifft + sizet)
|
if (modifier != MOD_NONE)
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
RETURN(pf,f,FMTCHECK_LONG);
|
RETURN(pf,f,FMTCHECK_LONG);
|
||||||
}
|
}
|
||||||
#ifndef NO_FLOATING_POINT
|
|
||||||
if (strchr("aAeEfFgG", *f)) {
|
if (strchr("aAeEfFgG", *f)) {
|
||||||
if (longdouble)
|
switch (modifier) {
|
||||||
|
case MOD_LONGDOUBLE:
|
||||||
RETURN(pf,f,FMTCHECK_LONGDOUBLE);
|
RETURN(pf,f,FMTCHECK_LONGDOUBLE);
|
||||||
if (sh + lg + quad + ptrdifft + sizet)
|
case MOD_LONG:
|
||||||
|
case MOD_NONE:
|
||||||
|
RETURN(pf,f,FMTCHECK_DOUBLE);
|
||||||
|
default:
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
RETURN(pf,f,FMTCHECK_DOUBLE);
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (*f == 'c') {
|
if (*f == 'c') {
|
||||||
if (sh + lg + quad + longdouble + ptrdifft + sizet)
|
switch (modifier) {
|
||||||
|
case MOD_LONG:
|
||||||
|
RETURN(pf,f,FMTCHECK_WINTT);
|
||||||
|
case MOD_NONE:
|
||||||
|
RETURN(pf,f,FMTCHECK_INT);
|
||||||
|
default:
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
RETURN(pf,f,FMTCHECK_INT);
|
}
|
||||||
|
}
|
||||||
|
if (*f == 'C') {
|
||||||
|
if (modifier != MOD_NONE)
|
||||||
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
RETURN(pf,f,FMTCHECK_WINTT);
|
||||||
}
|
}
|
||||||
if (*f == 's') {
|
if (*f == 's') {
|
||||||
if (sh + lg + quad + longdouble + ptrdifft + sizet)
|
switch (modifier) {
|
||||||
|
case MOD_LONG:
|
||||||
|
RETURN(pf,f,FMTCHECK_WSTRING);
|
||||||
|
case MOD_NONE:
|
||||||
|
RETURN(pf,f,FMTCHECK_STRING);
|
||||||
|
default:
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
RETURN(pf,f,FMTCHECK_STRING);
|
}
|
||||||
|
}
|
||||||
|
if (*f == 'S') {
|
||||||
|
if (modifier != MOD_NONE)
|
||||||
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
|
RETURN(pf,f,FMTCHECK_WSTRING);
|
||||||
}
|
}
|
||||||
if (*f == 'p') {
|
if (*f == 'p') {
|
||||||
if (sh + lg + quad + longdouble + ptrdifft + sizet)
|
if (modifier != MOD_NONE)
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
RETURN(pf,f,FMTCHECK_LONG);
|
RETURN(pf,f,FMTCHECK_POINTER);
|
||||||
}
|
}
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
@@ -185,7 +267,7 @@ get_next_format_from_width(const char **pf)
|
|||||||
RETURN(pf,f,FMTCHECK_PRECISION);
|
RETURN(pf,f,FMTCHECK_PRECISION);
|
||||||
}
|
}
|
||||||
/* eat any precision (empty is allowed) */
|
/* eat any precision (empty is allowed) */
|
||||||
while (isdigit(*f)) f++;
|
while (isdigit((unsigned char)*f)) f++;
|
||||||
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
}
|
}
|
||||||
RETURN(pf,f,get_next_format_from_precision(pf));
|
RETURN(pf,f,get_next_format_from_precision(pf));
|
||||||
@@ -229,7 +311,7 @@ get_next_format(const char **pf, EFT eft)
|
|||||||
RETURN(pf,f,FMTCHECK_WIDTH);
|
RETURN(pf,f,FMTCHECK_WIDTH);
|
||||||
}
|
}
|
||||||
/* eat any width */
|
/* eat any width */
|
||||||
while (isdigit(*f)) f++;
|
while (isdigit((unsigned char)*f)) f++;
|
||||||
if (!*f) {
|
if (!*f) {
|
||||||
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
RETURN(pf,f,FMTCHECK_UNKNOWN);
|
||||||
}
|
}
|
||||||
@@ -238,7 +320,7 @@ get_next_format(const char **pf, EFT eft)
|
|||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
__const char *
|
const char *
|
||||||
fmtcheck(const char *f1, const char *f2)
|
fmtcheck(const char *f1, const char *f2)
|
||||||
{
|
{
|
||||||
const char *f1p, *f2p;
|
const char *f1p, *f2p;
|
||||||
|
30
src/freezero.c
Normal file
30
src/freezero.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* $OpenBSD: malloc.c,v 1.267 2020/11/23 15:42:11 otto Exp $ */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
freezero(void *ptr, size_t sz)
|
||||||
|
{
|
||||||
|
/* This is legal. */
|
||||||
|
if (ptr == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
explicit_bzero(ptr, sz);
|
||||||
|
free(ptr);
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2011, 2013, 2017 Guillem Jover
|
* Copyright © 2011, 2013, 2017, 2020 Guillem Jover
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -87,10 +87,10 @@ funopen_close(void *cookie)
|
|||||||
struct funopen_cookie *cookiewrap = cookie;
|
struct funopen_cookie *cookiewrap = cookie;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (cookiewrap->closefn == NULL)
|
if (cookiewrap->closefn)
|
||||||
return 0;
|
rc = cookiewrap->closefn(cookiewrap->orig_cookie);
|
||||||
|
else
|
||||||
rc = cookiewrap->closefn(cookiewrap->orig_cookie);
|
rc = 0;
|
||||||
|
|
||||||
free(cookiewrap);
|
free(cookiewrap);
|
||||||
|
|
||||||
|
@@ -40,6 +40,8 @@
|
|||||||
#include "getentropy_aix.c"
|
#include "getentropy_aix.c"
|
||||||
#elif defined(__hpux)
|
#elif defined(__hpux)
|
||||||
#include "getentropy_hpux.c"
|
#include "getentropy_hpux.c"
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "getentropy_win.c"
|
||||||
#else
|
#else
|
||||||
#error "No getentropy hooks defined for this platform."
|
#error "No getentropy hooks defined for this platform."
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getentropy_aix.c,v 1.3 2015/08/25 17:26:43 deraadt Exp $ */
|
/* $OpenBSD: getentropy_aix.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Michael Felt <aixtools@gmail.com>
|
* Copyright (c) 2015 Michael Felt <aixtools@gmail.com>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* Emulation of getentropy(2) as documented at:
|
* Emulation of getentropy(2) as documented at:
|
||||||
* http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
|
* http://man.openbsd.org/getentropy.2
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* -lperfstat is needed for the psuedo entropy data
|
* -lperfstat is needed for the psuedo entropy data
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
#include "hash/sha512.h"
|
#include <sha512.h>
|
||||||
|
|
||||||
#include <libperfstat.h>
|
#include <libperfstat.h>
|
||||||
|
|
||||||
@@ -54,9 +54,9 @@
|
|||||||
HD(b); \
|
HD(b); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
|
#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
|
||||||
#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
|
#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
|
||||||
#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
|
#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
|
||||||
|
|
||||||
int getentropy(void *buf, size_t len);
|
int getentropy(void *buf, size_t len);
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getentropy_freebsd.c,v 1.1 2014/11/03 06:23:30 bcook Exp $ */
|
/* $OpenBSD: getentropy_freebsd.c,v 1.3 2016/08/07 03:27:21 tb Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
* Copyright (c) 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* Emulation of getentropy(2) as documented at:
|
* Emulation of getentropy(2) as documented at:
|
||||||
* http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
|
* http://man.openbsd.org/getentropy.2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* Emulation of getentropy(2) as documented at:
|
* Emulation of getentropy(2) as documented at:
|
||||||
* http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
|
* http://man.openbsd.org/getentropy.2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "hash/sha512.h"
|
#include <sha512.h>
|
||||||
|
|
||||||
#include <sys/vfs.h>
|
#include <sys/vfs.h>
|
||||||
|
|
||||||
@@ -59,9 +59,9 @@
|
|||||||
HD(b); \
|
HD(b); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
|
#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
|
||||||
#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
|
#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
|
||||||
#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
|
#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
|
||||||
|
|
||||||
int getentropy(void *buf, size_t len);
|
int getentropy(void *buf, size_t len);
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* Emulation of getentropy(2) as documented at:
|
* Emulation of getentropy(2) as documented at:
|
||||||
* http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
|
* http://man.openbsd.org/getentropy.2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "hash/sha512.h"
|
#include <sha512.h>
|
||||||
|
|
||||||
#ifdef HAVE_GETAUXVAL
|
#ifdef HAVE_GETAUXVAL
|
||||||
#include <sys/auxv.h>
|
#include <sys/auxv.h>
|
||||||
@@ -62,9 +62,9 @@
|
|||||||
HD(b); \
|
HD(b); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
|
#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
|
||||||
#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
|
#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
|
||||||
#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
|
#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
|
||||||
|
|
||||||
int getentropy(void *buf, size_t len);
|
int getentropy(void *buf, size_t len);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ getentropy(void *buf, size_t len)
|
|||||||
* - Do the best under the circumstances....
|
* - Do the best under the circumstances....
|
||||||
*
|
*
|
||||||
* This code path exists to bring light to the issue that Hurd
|
* This code path exists to bring light to the issue that Hurd
|
||||||
* does not provide a failsafe API for entropy collection.
|
* still does not provide a failsafe API for entropy collection.
|
||||||
*
|
*
|
||||||
* We hope this demonstrates that Hurd should either get a
|
* We hope this demonstrates that Hurd should either get a
|
||||||
* sysctl ABI, or consider providing a new failsafe API which
|
* sysctl ABI, or consider providing a new failsafe API which
|
||||||
@@ -228,7 +228,7 @@ getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
|
|||||||
{
|
{
|
||||||
SHA512_CTX *ctx = data;
|
SHA512_CTX *ctx = data;
|
||||||
|
|
||||||
SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
|
SHA512_Update(ctx, (uint8_t *)&info->dlpi_addr, sizeof (info->dlpi_addr));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user