mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-19 21:16:55 +02:00
Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 | ||
![]() |
bbf90ac3cd | ||
![]() |
2a8514d8a5 | ||
![]() |
3b2b7938f7 | ||
![]() |
415e3cb266 | ||
![]() |
9532cb39f4 | ||
![]() |
a4dd754c8d | ||
![]() |
b480b7a3f8 | ||
![]() |
4cc20e23f5 | ||
![]() |
c4e58c0950 | ||
![]() |
736e12e8d8 |
206
COPYING
206
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-2018 Guillem Jover <guillem@hadrons.org>
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
@@ -110,6 +110,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
|
||||||
@@ -121,8 +123,9 @@ Files:
|
|||||||
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.
|
||||||
@@ -153,29 +156,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 +174,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 +238,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 +263,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
|
||||||
@@ -367,7 +317,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 +353,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,9 +360,11 @@ 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/getentropy_aix.c
|
src/getentropy_aix.c
|
||||||
src/getentropy_bsd.c
|
src/getentropy_bsd.c
|
||||||
@@ -440,11 +373,11 @@ 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/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.
|
||||||
@@ -549,6 +482,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 +555,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
|
||||||
|
@@ -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=9
|
||||||
LIBBSD_ABI_PATCH=4
|
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])
|
||||||
|
@@ -13,6 +13,7 @@ nobase_include_HEADERS = \
|
|||||||
bsd/bsd.h \
|
bsd/bsd.h \
|
||||||
bsd/err.h \
|
bsd/err.h \
|
||||||
bsd/getopt.h \
|
bsd/getopt.h \
|
||||||
|
bsd/inttypes.h \
|
||||||
bsd/libutil.h \
|
bsd/libutil.h \
|
||||||
bsd/md5.h \
|
bsd/md5.h \
|
||||||
bsd/nlist.h \
|
bsd/nlist.h \
|
||||||
|
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.
|
||||||
|
@@ -27,7 +27,11 @@ typedef struct MD5Context {
|
|||||||
uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
|
uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
|
||||||
} MD5_CTX;
|
} MD5_CTX;
|
||||||
|
|
||||||
|
#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
|
||||||
|
@@ -27,7 +27,11 @@
|
|||||||
#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 {
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
@@ -67,7 +71,10 @@ 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
|
||||||
|
|
||||||
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,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#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
|
#endif
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
@@ -58,6 +58,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,6 +76,9 @@
|
|||||||
#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
|
||||||
@@ -82,6 +93,12 @@
|
|||||||
#define LIBBSD_DEPRECATED(x)
|
#define LIBBSD_DEPRECATED(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LIBBSD_GCC_VERSION >= 0x0200
|
||||||
|
#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
|
||||||
# define __dead2 __attribute__((__noreturn__))
|
# define __dead2 __attribute__((__noreturn__))
|
||||||
@@ -147,6 +164,12 @@
|
|||||||
# 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.
|
||||||
|
@@ -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,
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
|
@@ -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,73 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
||||||
|
*/
|
||||||
|
#ifndef 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
|
||||||
|
@@ -181,6 +181,7 @@ dist_man_MANS = \
|
|||||||
le32enc.3bsd \
|
le32enc.3bsd \
|
||||||
le64dec.3bsd \
|
le64dec.3bsd \
|
||||||
le64enc.3bsd \
|
le64enc.3bsd \
|
||||||
|
libbsd.7 \
|
||||||
md5.3bsd \
|
md5.3bsd \
|
||||||
mergesort.3bsd \
|
mergesort.3bsd \
|
||||||
nlist.3bsd \
|
nlist.3bsd \
|
||||||
@@ -211,7 +212,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 \
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
.\" Manual page, using -mandoc macros
|
.\" Manual page, using -mandoc macros
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: July 19 2014 $
|
.Dd $Mdocdate: July 19 2014 $
|
||||||
.Dt ARC4RANDOM 3
|
.Dt ARC4RANDOM 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm arc4random ,
|
.Nm arc4random ,
|
||||||
@@ -129,7 +129,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.
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 19, 1993
|
.Dd July 19, 1993
|
||||||
.Dt BITSTRING 3
|
.Dt BITSTRING 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm bit_alloc ,
|
.Nm bit_alloc ,
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd April 29, 2002
|
.Dd April 29, 2002
|
||||||
.Dt BYTEORDER 3
|
.Dt BYTEORDER 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
|
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 12, 2009
|
.Dd June 12, 2009
|
||||||
.Dt CLOSEFROM 3
|
.Dt CLOSEFROM 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm closefrom
|
.Nm closefrom
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: April 23 2014 $
|
.Dd $Mdocdate: April 23 2014 $
|
||||||
.Dt ERRC 3
|
.Dt ERRC 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm errc ,
|
.Nm errc ,
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd August 15, 2010
|
.Dd August 15, 2010
|
||||||
.Dt EXPAND_NUMBER 3
|
.Dt EXPAND_NUMBER 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm expand_number
|
.Nm expand_number
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
|
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: January 22 2014 $
|
.Dd $Mdocdate: January 22 2014 $
|
||||||
.Dt BZERO 3
|
.Dt EXPLICIT_BZERO 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm explicit_bzero
|
.Nm explicit_bzero
|
||||||
@@ -72,4 +72,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.
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
|
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 19, 1994
|
.Dd April 19, 1994
|
||||||
.Dt FGETLN 3
|
.Dt FGETLN 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fgetln
|
.Nm fgetln
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 16, 2004
|
.Dd July 16, 2004
|
||||||
.Dt FGETWLN 3
|
.Dt FGETWLN 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fgetwln
|
.Nm fgetwln
|
||||||
|
@@ -25,12 +25,13 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 6, 2009
|
.Dd July 28, 2017
|
||||||
.Dt FLOPEN 3
|
.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)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
@@ -44,6 +45,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 +58,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 +70,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 +83,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 +128,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,15 +26,12 @@
|
|||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $
|
.Dd June 14, 2014
|
||||||
.Dd October 16, 2002
|
.Dt FMTCHECK 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Dt FMTCHECK 3
|
|
||||||
.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)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
@@ -45,8 +44,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 +59,45 @@ is a valid format string.
|
|||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Xr printf 3
|
.Xr printf 3
|
||||||
family of functions cannot verify the types of arguments that they are
|
family of functions can not verify the types of arguments that they are
|
||||||
passed at run-time.
|
passed at run-time.
|
||||||
In some cases, like
|
In some cases, like
|
||||||
.Xr catgets 3 ,
|
.Xr catgets 3 ,
|
||||||
it is useful or necessary to use a user-supplied format string with no
|
it is useful or necessary to use a user-supplied format string with no
|
||||||
guarantee that the format string matches the specified arguments.
|
guarantee that the format string matches the specified parameters.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn fmtcheck
|
.Nm
|
||||||
was designed to be used in these cases, as in:
|
function was designed to be used in these cases, as in:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
printf(fmtcheck(user_format, standard_format), arg1, arg2);
|
printf(fmtcheck(user_format, standard_format), arg1, arg2);
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In the check, field widths, fillers, precisions, etc.\& are ignored (unless
|
In the check, field widths, fillers, precisions, etc. are ignored (unless
|
||||||
the field width or precision is an asterisk
|
the field width or precision is an asterisk
|
||||||
.Ql *
|
.Ql *
|
||||||
instead of a digit string).
|
instead of a digit string).
|
||||||
Also, any text other than the format specifiers
|
Also, any text other than the format specifiers is completely ignored.
|
||||||
is completely ignored.
|
.Pp
|
||||||
|
Note that the formats may be quite different as long as they accept the
|
||||||
|
same parameters.
|
||||||
|
For example, "%ld %o %30s %#llx %-10.*e %n" is
|
||||||
|
compatible with "This number %lu %d%% and string %s has %qd numbers
|
||||||
|
and %.*g floats (%n)."
|
||||||
|
However, "%o" is not equivalent to "%lx" because
|
||||||
|
the first requires an integer and the second requires a long,
|
||||||
|
and "%p" is not equivalent to "%lu" because
|
||||||
|
the first requires a pointer and the second requires a long.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
If
|
If
|
||||||
.Fa fmt_suspect
|
.Fa fmt_suspect
|
||||||
is a valid format and consumes the same argument types as
|
is a valid format and consumes the same argument types as
|
||||||
.Fa fmt_default ,
|
.Fa fmt_default ,
|
||||||
then the
|
then the
|
||||||
.Fn fmtcheck
|
.Nm
|
||||||
will return
|
function will return
|
||||||
.Fa fmt_suspect .
|
.Fa fmt_suspect .
|
||||||
Otherwise, it will return
|
Otherwise, it will return
|
||||||
.Fa fmt_default .
|
.Fa fmt_default .
|
||||||
.Sh SECURITY CONSIDERATIONS
|
|
||||||
Note that the formats may be quite different as long as they accept the
|
|
||||||
same arguments.
|
|
||||||
For example,
|
|
||||||
.Qq Li "%p %o %30s %#llx %-10.*e %n"
|
|
||||||
is compatible with
|
|
||||||
.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
|
|
||||||
However,
|
|
||||||
.Qq Li %o
|
|
||||||
is not equivalent to
|
|
||||||
.Qq Li %lx
|
|
||||||
because
|
|
||||||
the first requires an integer and the second requires a long.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr printf 3
|
.Xr printf 3
|
||||||
.Sh BUGS
|
|
||||||
The
|
|
||||||
.Fn fmtcheck
|
|
||||||
function does not understand all of the conversions that
|
|
||||||
.Xr printf 3
|
|
||||||
does.
|
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd November 30, 2002
|
.Dd November 30, 2002
|
||||||
.Dt FPARSELN 3
|
.Dt FPARSELN 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fparseln
|
.Nm fparseln
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: November 4 2015 $
|
.Dd $Mdocdate: November 4 2015 $
|
||||||
.Dt FPURGE 3
|
.Dt FPURGE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm fpurge
|
.Nm fpurge
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 19, 2004
|
.Dd March 19, 2004
|
||||||
.Dt FUNOPEN 3
|
.Dt FUNOPEN 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm funopen ,
|
.Nm funopen ,
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd November 16, 2012
|
.Dd November 16, 2012
|
||||||
.Dt GETBSIZE 3
|
.Dt GETBSIZE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getbsize
|
.Nm getbsize
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 15, 2001
|
.Dd July 15, 2001
|
||||||
.Dt GETPEEREID 3
|
.Dt GETPEEREID 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getpeereid
|
.Nm getpeereid
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd May 1, 2001
|
.Dd May 1, 2001
|
||||||
.Dt GETPROGNAME 3
|
.Dt GETPROGNAME 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getprogname ,
|
.Nm getprogname ,
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd September 30, 2003
|
.Dd September 30, 2003
|
||||||
.Dt QSORT 3
|
.Dt HEAPSORT 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm heapsort , mergesort
|
.Nm heapsort , mergesort
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd February 9, 2008
|
.Dd February 9, 2008
|
||||||
.Dt HUMANIZE_NUMBER 3
|
.Dt HUMANIZE_NUMBER 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm dehumanize_number ,
|
.Nm dehumanize_number ,
|
||||||
|
51
man/libbsd.7
51
man/libbsd.7
@@ -1,6 +1,6 @@
|
|||||||
.\" libbsd man page
|
.\" libbsd man page
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright © 2017 Gullem Jover <guillem@hadrons.org>
|
.\" Copyright © 2017-2018 Gullem 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
|
||||||
@@ -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
|
||||||
@@ -142,6 +143,17 @@ 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 fgetwln
|
||||||
|
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
|
.It Fn funopen
|
||||||
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
|
||||||
@@ -150,13 +162,36 @@ 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
|
||||||
|
.It Fn MD5Update
|
||||||
|
.It Fn MD5Pad
|
||||||
|
.It Fn MD5Final
|
||||||
|
.It Fn MD5Transform
|
||||||
|
.It Fn MD5End
|
||||||
|
.It Fn MD5File
|
||||||
|
.It Fn MD5FileChunk
|
||||||
|
.It Fn MD5Data
|
||||||
|
The set of MD5 digest functions are now 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 use that instead.
|
||||||
provided in
|
.It Fn explicit_bzero
|
||||||
.Nm libbsd
|
This function is provided by
|
||||||
might disappear on the next SONAME bump.
|
.Nm glibc
|
||||||
|
2.25.
|
||||||
|
.It Fn reallocarray
|
||||||
|
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 +226,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 ,
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
|
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 19, 1994
|
.Dd April 19, 1994
|
||||||
.Dt NLIST 3
|
.Dt NLIST 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm nlist
|
.Nm nlist
|
||||||
|
@@ -24,15 +24,16 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd October 20, 2008
|
.Dd February 8, 2012
|
||||||
.Dt PIDFILE 3
|
.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)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
@@ -49,6 +50,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 +65,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 +83,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 +104,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 +121,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 +155,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 +198,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 +277,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 +296,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 .
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 17, 2013
|
.Dd June 17, 2013
|
||||||
.Dt QUEUE 3
|
.Dt QUEUE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm SLIST_EMPTY ,
|
.Nm SLIST_EMPTY ,
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
||||||
.\"
|
.\"
|
||||||
.Dd January 27, 1994
|
.Dd January 27, 1994
|
||||||
.Dt RADIXSORT 3
|
.Dt RADIXSORT 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm radixsort ,
|
.Nm radixsort ,
|
||||||
|
@@ -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,8 +18,8 @@
|
|||||||
.\" 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 3
|
.Dt READPASSPHRASE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm readpassphrase
|
.Nm readpassphrase
|
||||||
@@ -55,9 +55,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 +67,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 +102,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
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
.\" $OpenBSD: malloc.3,v 1.78 2014/05/01 18:41:59 jmc Exp $
|
.\" $OpenBSD: malloc.3,v 1.78 2014/05/01 18:41:59 jmc Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 1 2014 $
|
.Dd $Mdocdate: May 1 2014 $
|
||||||
.Dt MALLOC 3
|
.Dt REALLOCARRAY 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm reallocarray
|
.Nm reallocarray
|
||||||
@@ -102,4 +102,5 @@ is set to
|
|||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Fn reallocarray
|
.Fn reallocarray
|
||||||
appeared in
|
appeared in
|
||||||
.Ox 5.6 .
|
.Ox 5.6 ,
|
||||||
|
glibc 2.26.
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd September 26, 2009
|
.Dd September 26, 2009
|
||||||
.Dt MALLOC 3
|
.Dt REALLOCF 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm reallocf
|
.Nm reallocf
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd January 4, 2009
|
.Dd January 4, 2009
|
||||||
.Dt SETMODE 3
|
.Dt SETMODE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm getmode ,
|
.Nm getmode ,
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" The following requests are required for all man pages.
|
.\" The following requests are required for all man pages.
|
||||||
.Dd December 16, 1995
|
.Dd December 16, 1995
|
||||||
.Dt SETPROCTITLE 3
|
.Dt SETPROCTITLE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm setproctitle
|
.Nm setproctitle
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd May 6, 2010
|
.Dd May 6, 2010
|
||||||
.Dt STRINGLIST 3
|
.Dt STRINGLIST 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm stringlist ,
|
.Nm stringlist ,
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.Dd $Mdocdate: May 31 2007 $
|
||||||
.Dt STRLCPY 3
|
.Dt STRLCPY 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strlcpy ,
|
.Nm strlcpy ,
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
|
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd July 28, 1994
|
.Dd July 28, 1994
|
||||||
.Dt STRMODE 3
|
.Dt STRMODE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strmode
|
.Nm strmode
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd October 11, 2001
|
.Dd October 11, 2001
|
||||||
.Dt STRSTR 3
|
.Dt STRSTR 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strnstr
|
.Nm strnstr
|
||||||
|
238
man/strtoi.3bsd
Normal file
238
man/strtoi.3bsd
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
.\" $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)
|
||||||
|
.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
|
||||||
|
The
|
||||||
|
.Fn strtoi
|
||||||
|
function first appeared in
|
||||||
|
.Nx 7 .
|
||||||
|
.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,11 +15,8 @@
|
|||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
.\"
|
.\"
|
||||||
.\" $OpenBSD: strtonum.3,v 1.12 2005/10/26 11:37:58 jmc Exp $
|
.Dd January 18, 2015
|
||||||
.\" $FreeBSD$
|
.Dt STRTONUM 3bsd
|
||||||
.\"
|
|
||||||
.Dd April 29, 2004
|
|
||||||
.Dt STRTONUM 3
|
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strtonum
|
.Nm strtonum
|
||||||
@@ -45,14 +45,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 +104,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 +132,58 @@ 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
|
||||||
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
|
||||||
|
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 .
|
||||||
|
238
man/strtou.3bsd
Normal file
238
man/strtou.3bsd
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
.\" $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)
|
||||||
|
.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
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function is a
|
||||||
|
.Nx
|
||||||
|
extension.
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn strtou
|
||||||
|
function first appeared in
|
||||||
|
.Nx 7 .
|
||||||
|
.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.
|
@@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
|
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd June 7, 2010
|
.Dd June 7, 2010
|
||||||
.Dt TIMERADD 3
|
.Dt TIMERADD 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm timeradd ,
|
.Nm timeradd ,
|
||||||
@@ -81,7 +81,7 @@ These macros are provided for manipulating the
|
|||||||
and
|
and
|
||||||
.Fa timespec
|
.Fa timespec
|
||||||
structures described in
|
structures described in
|
||||||
.Xr timeval 3 .
|
.Xr timeval 3bsd .
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn timeradd
|
.Fn timeradd
|
||||||
@@ -145,7 +145,7 @@ using the comparison operator given in
|
|||||||
.Fa CMP .
|
.Fa CMP .
|
||||||
The result of the comparison is returned.
|
The result of the comparison is returned.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr timeval 3
|
.Xr timeval 3bsd
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Fn timeradd
|
.Fn timeradd
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd April 12, 2011
|
.Dd April 12, 2011
|
||||||
.Dt TIMEVAL 3
|
.Dt TIMEVAL 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm timeval ,
|
.Nm timeval ,
|
||||||
@@ -130,4 +130,4 @@ example(struct timespec *spec, time_t minutes)
|
|||||||
A better alternative would use the more precise
|
A better alternative would use the more precise
|
||||||
.Xr clock_gettime 2 .
|
.Xr clock_gettime 2 .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr timeradd 3
|
.Xr timeradd 3bsd
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd December 27, 2007
|
.Dd December 27, 2007
|
||||||
.Dt TREE 3
|
.Dt TREE 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm SPLAY_PROTOTYPE ,
|
.Nm SPLAY_PROTOTYPE ,
|
||||||
|
203
man/unvis.3bsd
203
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,13 +27,17 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
|
||||||
.Dt UNVIS 3
|
.\"
|
||||||
|
.Dd March 12, 2011
|
||||||
|
.Dt UNVIS 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm unvis ,
|
.Nm unvis ,
|
||||||
.Nm strunvis ,
|
.Nm strunvis ,
|
||||||
.Nm strnunvis
|
.Nm strnunvis ,
|
||||||
|
.Nm strunvisx ,
|
||||||
|
.Nm strnunvisx
|
||||||
.Nd decode a visual representation of characters
|
.Nd decode a visual representation of characters
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
@@ -44,88 +48,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 +147,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 +195,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.
|
||||||
|
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,87 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: May 31 2007 $
|
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
|
||||||
.Dt VIS 3
|
.\"
|
||||||
|
.Dd April 22, 2017
|
||||||
|
.Dt VIS 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm vis ,
|
.Nm vis ,
|
||||||
|
.Nm nvis ,
|
||||||
.Nm strvis ,
|
.Nm strvis ,
|
||||||
|
.Nm stravis ,
|
||||||
.Nm strnvis ,
|
.Nm strnvis ,
|
||||||
.Nm strvisx
|
.Nm strvisx ,
|
||||||
|
.Nm strnvisx ,
|
||||||
|
.Nm strenvisx ,
|
||||||
|
.Nm svis ,
|
||||||
|
.Nm snvis ,
|
||||||
|
.Nm strsvis ,
|
||||||
|
.Nm strsnvis ,
|
||||||
|
.Nm strsvisx ,
|
||||||
|
.Nm strsnvisx ,
|
||||||
|
.Nm strsenvisx
|
||||||
.Nd visually encode characters
|
.Nd visually encode characters
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.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 +118,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 +130,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 3 ) .
|
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 +285,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 +378,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 +406,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 +449,112 @@ 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
|
||||||
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 .
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 4, 2009
|
.Dd March 4, 2009
|
||||||
.Dt WCSLCPY 3
|
.Dt WCSLCPY 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm wcslcat ,
|
.Nm wcslcat ,
|
||||||
|
@@ -16,6 +16,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 = \
|
||||||
@@ -60,9 +61,11 @@ libbsd_la_LDFLAGS = \
|
|||||||
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 \
|
||||||
@@ -103,7 +106,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 \
|
||||||
|
@@ -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 __GLIBC__
|
||||||
|
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>
|
||||||
@@ -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;
|
||||||
|
@@ -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.")
|
||||||
|
62
src/flopen.c
62
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
|
||||||
@@ -30,13 +32,21 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.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 +58,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 +69,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 +79,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 +104,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;
|
||||||
|
@@ -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
|
||||||
|
@@ -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>
|
||||||
|
@@ -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
|
||||||
@@ -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
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getentropy_linux.c,v 1.40 2015/08/25 17:26:43 deraadt Exp $ */
|
/* $OpenBSD: getentropy_linux.c,v 1.45 2018/03/13 22:53:28 bcook Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
|
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
int getentropy(void *buf, size_t len);
|
int getentropy(void *buf, size_t len);
|
||||||
|
|
||||||
static int gotdata(char *buf, size_t len);
|
static int gotdata(char *buf, size_t len);
|
||||||
#ifdef SYS_getrandom
|
#if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
|
||||||
static int getentropy_getrandom(void *buf, size_t len);
|
static int getentropy_getrandom(void *buf, size_t len);
|
||||||
#endif
|
#endif
|
||||||
static int getentropy_urandom(void *buf, size_t len);
|
static int getentropy_urandom(void *buf, size_t len);
|
||||||
@@ -95,15 +95,18 @@ getentropy(void *buf, size_t len)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYS_getrandom
|
#if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
|
||||||
/*
|
/*
|
||||||
* Try descriptor-less getrandom()
|
* Try descriptor-less getrandom(), in non-blocking mode.
|
||||||
|
*
|
||||||
|
* The design of Linux getrandom is broken. It has an
|
||||||
|
* uninitialized phase coupled with blocking behaviour, which
|
||||||
|
* is unacceptable from within a library at boot time without
|
||||||
|
* possible recovery. See http://bugs.python.org/issue26839#msg267745
|
||||||
*/
|
*/
|
||||||
ret = getentropy_getrandom(buf, len);
|
ret = getentropy_getrandom(buf, len);
|
||||||
if (ret != -1)
|
if (ret != -1)
|
||||||
return (ret);
|
return (ret);
|
||||||
if (errno != ENOSYS)
|
|
||||||
return (-1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -121,7 +124,7 @@ getentropy(void *buf, size_t len)
|
|||||||
* Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID.
|
* Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID.
|
||||||
* sysctl is a failsafe API, so it guarantees a result. This
|
* sysctl is a failsafe API, so it guarantees a result. This
|
||||||
* should work inside a chroot, or when file descriptors are
|
* should work inside a chroot, or when file descriptors are
|
||||||
* exhuasted.
|
* exhausted.
|
||||||
*
|
*
|
||||||
* However this can fail if the Linux kernel removes support
|
* However this can fail if the Linux kernel removes support
|
||||||
* for sysctl. Starting in 2007, there have been efforts to
|
* for sysctl. Starting in 2007, there have been efforts to
|
||||||
@@ -157,7 +160,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 Linux
|
* This code path exists to bring light to the issue that Linux
|
||||||
* does not provide a failsafe API for entropy collection.
|
* still does not provide a failsafe API for entropy collection.
|
||||||
*
|
*
|
||||||
* We hope this demonstrates that Linux should either retain their
|
* We hope this demonstrates that Linux should either retain their
|
||||||
* sysctl ABI, or consider providing a new failsafe API which
|
* sysctl ABI, or consider providing a new failsafe API which
|
||||||
@@ -191,7 +194,7 @@ gotdata(char *buf, size_t len)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYS_getrandom
|
#if defined(SYS_getrandom) && defined(GRND_NONBLOCK)
|
||||||
static int
|
static int
|
||||||
getentropy_getrandom(void *buf, size_t len)
|
getentropy_getrandom(void *buf, size_t len)
|
||||||
{
|
{
|
||||||
@@ -200,7 +203,7 @@ getentropy_getrandom(void *buf, size_t len)
|
|||||||
if (len > 256)
|
if (len > 256)
|
||||||
return (-1);
|
return (-1);
|
||||||
do {
|
do {
|
||||||
ret = syscall(SYS_getrandom, buf, len, 0);
|
ret = syscall(SYS_getrandom, buf, len, GRND_NONBLOCK);
|
||||||
} while (ret == -1 && errno == EINTR);
|
} while (ret == -1 && errno == EINTR);
|
||||||
|
|
||||||
if (ret != (int)len)
|
if (ret != (int)len)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getentropy_osx.c,v 1.8 2014/07/21 20:19:47 guenther Exp $ */
|
/* $OpenBSD: getentropy_osx.c,v 1.11 2016/09/03 15:24:09 bcook Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
|
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
|
||||||
@@ -17,9 +17,10 @@
|
|||||||
* 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 <TargetConditionals.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@@ -45,14 +46,18 @@
|
|||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <mach/host_info.h>
|
#include <mach/host_info.h>
|
||||||
|
#if TARGET_OS_OSX
|
||||||
#include <sys/socketvar.h>
|
#include <sys/socketvar.h>
|
||||||
#include <sys/vmmeter.h>
|
#include <sys/vmmeter.h>
|
||||||
|
#endif
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
#if TARGET_OS_OSX
|
||||||
#include <netinet/udp.h>
|
#include <netinet/udp.h>
|
||||||
#include <netinet/ip_var.h>
|
#include <netinet/ip_var.h>
|
||||||
#include <netinet/tcp_var.h>
|
#include <netinet/tcp_var.h>
|
||||||
#include <netinet/udp_var.h>
|
#include <netinet/udp_var.h>
|
||||||
|
#endif
|
||||||
#include <CommonCrypto/CommonDigest.h>
|
#include <CommonCrypto/CommonDigest.h>
|
||||||
#define SHA512_Update(a, b, c) (CC_SHA512_Update((a), (b), (c)))
|
#define SHA512_Update(a, b, c) (CC_SHA512_Update((a), (b), (c)))
|
||||||
#define SHA512_Init(xxx) (CC_SHA512_Init((xxx)))
|
#define SHA512_Init(xxx) (CC_SHA512_Init((xxx)))
|
||||||
@@ -207,9 +212,11 @@ nodevrandom:
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TARGET_OS_OSX
|
||||||
static int tcpmib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS };
|
static int tcpmib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS };
|
||||||
static int udpmib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS };
|
static int udpmib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS };
|
||||||
static int ipmib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS };
|
static int ipmib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS };
|
||||||
|
#endif
|
||||||
static int kmib[] = { CTL_KERN, KERN_USRSTACK };
|
static int kmib[] = { CTL_KERN, KERN_USRSTACK };
|
||||||
static int hwmib[] = { CTL_HW, HW_USERMEM };
|
static int hwmib[] = { CTL_HW, HW_USERMEM };
|
||||||
|
|
||||||
@@ -229,9 +236,11 @@ getentropy_fallback(void *buf, size_t len)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
size_t i, ii, m;
|
size_t i, ii, m;
|
||||||
char *p;
|
char *p;
|
||||||
|
#if TARGET_OS_OSX
|
||||||
struct tcpstat tcpstat;
|
struct tcpstat tcpstat;
|
||||||
struct udpstat udpstat;
|
struct udpstat udpstat;
|
||||||
struct ipstat ipstat;
|
struct ipstat ipstat;
|
||||||
|
#endif
|
||||||
uint64_t mach_time;
|
uint64_t mach_time;
|
||||||
unsigned int idata;
|
unsigned int idata;
|
||||||
void *addr;
|
void *addr;
|
||||||
@@ -266,6 +275,7 @@ getentropy_fallback(void *buf, size_t len)
|
|||||||
HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]),
|
HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]),
|
||||||
&idata, &ii, NULL, 0) == -1, idata);
|
&idata, &ii, NULL, 0) == -1, idata);
|
||||||
|
|
||||||
|
#if TARGET_OS_OSX
|
||||||
ii = sizeof(tcpstat);
|
ii = sizeof(tcpstat);
|
||||||
HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]),
|
HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]),
|
||||||
&tcpstat, &ii, NULL, 0) == -1, tcpstat);
|
&tcpstat, &ii, NULL, 0) == -1, tcpstat);
|
||||||
@@ -277,6 +287,7 @@ getentropy_fallback(void *buf, size_t len)
|
|||||||
ii = sizeof(ipstat);
|
ii = sizeof(ipstat);
|
||||||
HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]),
|
HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]),
|
||||||
&ipstat, &ii, NULL, 0) == -1, ipstat);
|
&ipstat, &ii, NULL, 0) == -1, ipstat);
|
||||||
|
#endif
|
||||||
|
|
||||||
HX((pid = getpid()) == -1, pid);
|
HX((pid = getpid()) == -1, pid);
|
||||||
HX((pid = getsid(pid)) == -1, pid);
|
HX((pid = getsid(pid)) == -1, pid);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: getentropy_solaris.c,v 1.10 2015/08/25 17:26:43 deraadt Exp $ */
|
/* $OpenBSD: getentropy_solaris.c,v 1.12 2016/08/07 03:27:21 tb Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
|
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.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>
|
||||||
|
59
src/getentropy_win.c
Normal file
59
src/getentropy_win.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* $OpenBSD: getentropy_win.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
|
||||||
|
* Copyright (c) 2014, Bob Beck <beck@obtuse.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Emulation of getentropy(2) as documented at:
|
||||||
|
* http://man.openbsd.org/getentropy.2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <wincrypt.h>
|
||||||
|
#include <process.h>
|
||||||
|
|
||||||
|
int getentropy(void *buf, size_t len);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On Windows, CryptGenRandom is supposed to be a well-seeded
|
||||||
|
* cryptographically strong random number generator.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
getentropy(void *buf, size_t len)
|
||||||
|
{
|
||||||
|
HCRYPTPROV provider;
|
||||||
|
|
||||||
|
if (len > 256) {
|
||||||
|
errno = EIO;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
|
||||||
|
CRYPT_VERIFYCONTEXT) == 0)
|
||||||
|
goto fail;
|
||||||
|
if (CryptGenRandom(provider, len, buf) == 0) {
|
||||||
|
CryptReleaseContext(provider, 0);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
CryptReleaseContext(provider, 0);
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
errno = EIO;
|
||||||
|
return (-1);
|
||||||
|
}
|
@@ -1,3 +1,4 @@
|
|||||||
|
/* $OpenBSD: heapsort.c,v 1.11 2017/05/20 12:48:56 millert Exp $ */
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993
|
* Copyright (c) 1991, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
* Build the list into a heap, where a heap is defined such that for
|
* Build the list into a heap, where a heap is defined such that for
|
||||||
* the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N.
|
* the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N.
|
||||||
*
|
*
|
||||||
* There two cases. If j == nmemb, select largest of Ki and Kj. If
|
* There are two cases. If j == nmemb, select largest of Ki and Kj. If
|
||||||
* j < nmemb, select largest of Ki, Kj and Kj+1.
|
* j < nmemb, select largest of Ki, Kj and Kj+1.
|
||||||
*/
|
*/
|
||||||
#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \
|
#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \
|
||||||
@@ -86,12 +87,12 @@
|
|||||||
* Select the top of the heap and 'heapify'. Since by far the most expensive
|
* Select the top of the heap and 'heapify'. Since by far the most expensive
|
||||||
* action is the call to the compar function, a considerable optimization
|
* action is the call to the compar function, a considerable optimization
|
||||||
* in the average case can be achieved due to the fact that k, the displaced
|
* in the average case can be achieved due to the fact that k, the displaced
|
||||||
* elememt, is usually quite small, so it would be preferable to first
|
* element, is usually quite small, so it would be preferable to first
|
||||||
* heapify, always maintaining the invariant that the larger child is copied
|
* heapify, always maintaining the invariant that the larger child is copied
|
||||||
* over its parent's record.
|
* over its parent's record.
|
||||||
*
|
*
|
||||||
* Then, starting from the *bottom* of the heap, finding k's correct place,
|
* Then, starting from the *bottom* of the heap, finding k's correct place,
|
||||||
* again maintianing the invariant. As a result of the invariant no element
|
* again maintaining the invariant. As a result of the invariant no element
|
||||||
* is 'lost' when k is assigned its correct place in the heap.
|
* is 'lost' when k is assigned its correct place in the heap.
|
||||||
*
|
*
|
||||||
* The time savings from this optimization are on the order of 15-20% for the
|
* The time savings from this optimization are on the order of 15-20% for the
|
||||||
@@ -131,7 +132,7 @@
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
heapsort(void *vbase, size_t nmemb, size_t size,
|
heapsort(void *vbase, size_t nmemb, size_t size,
|
||||||
int (*compar)(const void *, const void *))
|
int (*compar)(const void *, const void *))
|
||||||
{
|
{
|
||||||
size_t cnt, i, j, l;
|
size_t cnt, i, j, l;
|
||||||
char tmp, *tmp1, *tmp2;
|
char tmp, *tmp1, *tmp2;
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
/* $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $ */
|
/* $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $ */
|
||||||
|
|
||||||
/*
|
/*-
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||||
|
*
|
||||||
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
|
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
|
||||||
|
* Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
@@ -31,6 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -39,58 +43,81 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
|
|
||||||
|
static const int maxscale = 6;
|
||||||
|
|
||||||
int
|
int
|
||||||
humanize_number(char *buf, size_t len, int64_t bytes,
|
humanize_number(char *buf, size_t len, int64_t quotient,
|
||||||
const char *suffix, int scale, int flags)
|
const char *suffix, int scale, int flags)
|
||||||
{
|
{
|
||||||
const char *prefixes, *sep;
|
const char *prefixes, *sep;
|
||||||
int b, i, r, maxscale, s1, s2, sign;
|
int i, r, remainder, s1, s2, sign;
|
||||||
|
int divisordeccut;
|
||||||
int64_t divisor, max;
|
int64_t divisor, max;
|
||||||
size_t baselen;
|
size_t baselen;
|
||||||
|
|
||||||
assert(buf != NULL);
|
/* Since so many callers don't check -1, NUL terminate the buffer */
|
||||||
assert(suffix != NULL);
|
|
||||||
assert(scale >= 0);
|
|
||||||
|
|
||||||
if (flags & HN_DIVISOR_1000) {
|
|
||||||
/* SI for decimal multiplies */
|
|
||||||
divisor = 1000;
|
|
||||||
if (flags & HN_B)
|
|
||||||
prefixes = "B\0k\0M\0G\0T\0P\0E";
|
|
||||||
else
|
|
||||||
prefixes = "\0\0k\0M\0G\0T\0P\0E";
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* binary multiplies
|
|
||||||
* XXX IEC 60027-2 recommends Ki, Mi, Gi...
|
|
||||||
*/
|
|
||||||
divisor = 1024;
|
|
||||||
if (flags & HN_B)
|
|
||||||
prefixes = "B\0K\0M\0G\0T\0P\0E";
|
|
||||||
else
|
|
||||||
prefixes = "\0\0K\0M\0G\0T\0P\0E";
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SCALE2PREFIX(scale) (&prefixes[(scale) << 1])
|
|
||||||
maxscale = 7;
|
|
||||||
|
|
||||||
if (scale >= maxscale &&
|
|
||||||
(scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
if (buf == NULL || suffix == NULL)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
if (bytes < 0) {
|
|
||||||
|
/* validate args */
|
||||||
|
if (buf == NULL || suffix == NULL)
|
||||||
|
return (-1);
|
||||||
|
if (scale < 0)
|
||||||
|
return (-1);
|
||||||
|
else if (scale > maxscale &&
|
||||||
|
((scale & ~(HN_AUTOSCALE|HN_GETSCALE)) != 0))
|
||||||
|
return (-1);
|
||||||
|
if ((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/* setup parameters */
|
||||||
|
remainder = 0;
|
||||||
|
|
||||||
|
if (flags & HN_IEC_PREFIXES) {
|
||||||
|
baselen = 2;
|
||||||
|
/*
|
||||||
|
* Use the prefixes for power of two recommended by
|
||||||
|
* the International Electrotechnical Commission
|
||||||
|
* (IEC) in IEC 80000-3 (i.e. Ki, Mi, Gi...).
|
||||||
|
*
|
||||||
|
* HN_IEC_PREFIXES implies a divisor of 1024 here
|
||||||
|
* (use of HN_DIVISOR_1000 would have triggered
|
||||||
|
* an assertion earlier).
|
||||||
|
*/
|
||||||
|
divisor = 1024;
|
||||||
|
divisordeccut = 973; /* ceil(.95 * 1024) */
|
||||||
|
if (flags & HN_B)
|
||||||
|
prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
|
||||||
|
else
|
||||||
|
prefixes = "\0\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
|
||||||
|
} else {
|
||||||
|
baselen = 1;
|
||||||
|
if (flags & HN_DIVISOR_1000) {
|
||||||
|
divisor = 1000;
|
||||||
|
divisordeccut = 950;
|
||||||
|
if (flags & HN_B)
|
||||||
|
prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
|
||||||
|
else
|
||||||
|
prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
|
||||||
|
} else {
|
||||||
|
divisor = 1024;
|
||||||
|
divisordeccut = 973; /* ceil(.95 * 1024) */
|
||||||
|
if (flags & HN_B)
|
||||||
|
prefixes = "B\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E";
|
||||||
|
else
|
||||||
|
prefixes = "\0\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SCALE2PREFIX(scale) (&prefixes[(scale) * 3])
|
||||||
|
|
||||||
|
if (quotient < 0) {
|
||||||
sign = -1;
|
sign = -1;
|
||||||
bytes *= -100;
|
quotient = -quotient;
|
||||||
baselen = 3; /* sign, digit, prefix */
|
baselen += 2; /* sign, digit */
|
||||||
} else {
|
} else {
|
||||||
sign = 1;
|
sign = 1;
|
||||||
bytes *= 100;
|
baselen += 1; /* digit */
|
||||||
baselen = 2; /* digit, prefix */
|
|
||||||
}
|
}
|
||||||
if (flags & HN_NOSPACE)
|
if (flags & HN_NOSPACE)
|
||||||
sep = "";
|
sep = "";
|
||||||
@@ -106,7 +133,7 @@ humanize_number(char *buf, size_t len, int64_t bytes,
|
|||||||
|
|
||||||
if (scale & (HN_AUTOSCALE | HN_GETSCALE)) {
|
if (scale & (HN_AUTOSCALE | HN_GETSCALE)) {
|
||||||
/* See if there is additional columns can be used. */
|
/* See if there is additional columns can be used. */
|
||||||
for (max = 100, i = len - baselen; i-- > 0;)
|
for (max = 1, i = len - baselen; i-- > 0;)
|
||||||
max *= 10;
|
max *= 10;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -114,29 +141,39 @@ humanize_number(char *buf, size_t len, int64_t bytes,
|
|||||||
* If there will be an overflow by the rounding below,
|
* If there will be an overflow by the rounding below,
|
||||||
* divide once more.
|
* divide once more.
|
||||||
*/
|
*/
|
||||||
for (i = 0; bytes >= max - 50 && i < maxscale; i++)
|
for (i = 0;
|
||||||
bytes /= divisor;
|
(quotient >= max || (quotient == max - 1 &&
|
||||||
|
(remainder >= divisordeccut || remainder >=
|
||||||
|
divisor / 2))) && i < maxscale; i++) {
|
||||||
|
remainder = quotient % divisor;
|
||||||
|
quotient /= divisor;
|
||||||
|
}
|
||||||
|
|
||||||
if (scale & HN_GETSCALE)
|
if (scale & HN_GETSCALE)
|
||||||
return (i);
|
return (i);
|
||||||
} else
|
} else {
|
||||||
for (i = 0; i < scale && i < maxscale; i++)
|
for (i = 0; i < scale && i < maxscale; i++) {
|
||||||
bytes /= divisor;
|
remainder = quotient % divisor;
|
||||||
|
quotient /= divisor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If a value <= 9.9 after rounding and ... */
|
/* If a value <= 9.9 after rounding and ... */
|
||||||
if (bytes < 995 && i > 0 && flags & HN_DECIMAL) {
|
/*
|
||||||
/* baselen + \0 + .N */
|
* XXX - should we make sure there is enough space for the decimal
|
||||||
if (len < baselen + 1 + 2)
|
* place and if not, don't do HN_DECIMAL?
|
||||||
return (-1);
|
*/
|
||||||
b = ((int)bytes + 5) / 10;
|
if (((quotient == 9 && remainder < divisordeccut) || quotient < 9) &&
|
||||||
s1 = b / 10;
|
i > 0 && flags & HN_DECIMAL) {
|
||||||
s2 = b % 10;
|
s1 = (int)quotient + ((remainder * 10 + divisor / 2) /
|
||||||
|
divisor / 10);
|
||||||
|
s2 = ((remainder * 10 + divisor / 2) / divisor) % 10;
|
||||||
r = snprintf(buf, len, "%d%s%d%s%s%s",
|
r = snprintf(buf, len, "%d%s%d%s%s%s",
|
||||||
sign * s1, localeconv()->decimal_point, s2,
|
sign * s1, localeconv()->decimal_point, s2,
|
||||||
sep, SCALE2PREFIX(i), suffix);
|
sep, SCALE2PREFIX(i), suffix);
|
||||||
} else
|
} else
|
||||||
r = snprintf(buf, len, "%" PRId64 "%s%s%s",
|
r = snprintf(buf, len, "%" PRId64 "%s%s%s",
|
||||||
sign * ((bytes + 50) / 100),
|
sign * (quotient + (remainder + divisor / 2) / divisor),
|
||||||
sep, SCALE2PREFIX(i), suffix);
|
sep, SCALE2PREFIX(i), suffix);
|
||||||
|
|
||||||
return (r);
|
return (r);
|
||||||
|
@@ -139,3 +139,32 @@ LIBBSD_0.7 {
|
|||||||
LIBBSD_0.8 {
|
LIBBSD_0.8 {
|
||||||
explicit_bzero;
|
explicit_bzero;
|
||||||
} LIBBSD_0.7;
|
} LIBBSD_0.7;
|
||||||
|
|
||||||
|
LIBBSD_0.9 {
|
||||||
|
flopenat;
|
||||||
|
|
||||||
|
pidfile_fileno;
|
||||||
|
|
||||||
|
strtoi;
|
||||||
|
strtou;
|
||||||
|
|
||||||
|
nvis;
|
||||||
|
snvis;
|
||||||
|
stravis;
|
||||||
|
strenvisx;
|
||||||
|
strnunvisx;
|
||||||
|
strsenvisx;
|
||||||
|
strsnvis;
|
||||||
|
strsnvisx;
|
||||||
|
strsvis;
|
||||||
|
strsvisx;
|
||||||
|
svis;
|
||||||
|
} LIBBSD_0.8;
|
||||||
|
|
||||||
|
LIBBSD_0.9.1 {
|
||||||
|
/* The strnvis() and strnunvis() symbols changed prototype to match
|
||||||
|
* the NetBSD implementation. Provided as versioned nodes in 0.9.1, and
|
||||||
|
* exposed here explicitly so that we can redirect at compile-time. */
|
||||||
|
strnvis_netbsd;
|
||||||
|
strnunvis_netbsd;
|
||||||
|
} LIBBSD_0.9;
|
||||||
|
@@ -127,7 +127,11 @@
|
|||||||
#elif defined(__mips__)
|
#elif defined(__mips__)
|
||||||
|
|
||||||
#define ELF_TARG_MACH EM_MIPS
|
#define ELF_TARG_MACH EM_MIPS
|
||||||
|
#if defined(_ABI64) && _MIPS_SIM == _ABI64
|
||||||
|
#define ELF_TARG_CLASS ELFCLASS64
|
||||||
|
#else
|
||||||
#define ELF_TARG_CLASS ELFCLASS32
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
|
#endif
|
||||||
#if defined(__MIPSEB__)
|
#if defined(__MIPSEB__)
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
#else
|
#else
|
||||||
@@ -140,17 +144,29 @@
|
|||||||
#define ELF_TARG_CLASS ELFCLASS32
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
#define ELF_TARG_DATA ELFDATA2LSB
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
|
|
||||||
#elif defined(__powerpc__)
|
|
||||||
|
|
||||||
#define ELF_TARG_MACH EM_PPC
|
|
||||||
#define ELF_TARG_CLASS ELFCLASS32
|
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
|
||||||
|
|
||||||
#elif defined(__powerpc64__)
|
#elif defined(__powerpc64__)
|
||||||
|
|
||||||
#define ELF_TARG_MACH EM_PPC64
|
#define ELF_TARG_MACH EM_PPC64
|
||||||
#define ELF_TARG_CLASS ELFCLASS64
|
#define ELF_TARG_CLASS ELFCLASS64
|
||||||
|
#if defined(__LITTLE_ENDIAN__)
|
||||||
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
|
#elif defined(__BIG_ENDIAN__)
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
#else
|
||||||
|
#error Unknown PowerPC64 endianness
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__powerpc__)
|
||||||
|
|
||||||
|
#define ELF_TARG_MACH EM_PPC
|
||||||
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
|
#if defined(__LITTLE_ENDIAN__)
|
||||||
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
|
#elif defined(__BIG_ENDIAN__)
|
||||||
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
#else
|
||||||
|
#error Unknown PowerPC endianness
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(__riscv)
|
#elif defined(__riscv)
|
||||||
|
|
||||||
@@ -170,7 +186,11 @@
|
|||||||
#define ELF_TARG_MACH EM_SPARCV9
|
#define ELF_TARG_MACH EM_SPARCV9
|
||||||
#define ELF_TARG_CLASS ELFCLASS64
|
#define ELF_TARG_CLASS ELFCLASS64
|
||||||
#else
|
#else
|
||||||
|
#if defined(__sparc_v9__) || defined(__sparcv9)
|
||||||
|
#define ELF_TARG_MACH EM_SPARC32PLUS
|
||||||
|
#else
|
||||||
#define ELF_TARG_MACH EM_SPARC
|
#define ELF_TARG_MACH EM_SPARC
|
||||||
|
#endif
|
||||||
#define ELF_TARG_CLASS ELFCLASS32
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
#endif
|
#endif
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
@@ -205,7 +225,11 @@
|
|||||||
|
|
||||||
#elif defined(__or1k__)
|
#elif defined(__or1k__)
|
||||||
|
|
||||||
|
#if defined(EM_OPENRISC)
|
||||||
#define ELF_TARG_MACH EM_OPENRISC
|
#define ELF_TARG_MACH EM_OPENRISC
|
||||||
|
#else
|
||||||
|
#define ELF_TARG_MACH EM_OR1K
|
||||||
|
#endif
|
||||||
#define ELF_TARG_CLASS ELFCLASS32
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
|
||||||
|
@@ -29,20 +29,27 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
struct pidfh {
|
||||||
|
int pf_fd;
|
||||||
|
char *pf_path;
|
||||||
|
dev_t pf_dev;
|
||||||
|
ino_t pf_ino;
|
||||||
|
};
|
||||||
|
|
||||||
static int _pidfile_remove(struct pidfh *pfh, int freeit);
|
static int _pidfile_remove(struct pidfh *pfh, int freeit);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pidfile_verify(struct pidfh *pfh)
|
pidfile_verify(const struct pidfh *pfh)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
@@ -114,25 +121,33 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
|
|||||||
fd = flopen(pfh->pf_path,
|
fd = flopen(pfh->pf_path,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
|
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
count = 0;
|
if (errno == EWOULDBLOCK) {
|
||||||
rqtp.tv_sec = 0;
|
if (pidptr == NULL) {
|
||||||
rqtp.tv_nsec = 5000000;
|
|
||||||
if (errno == EWOULDBLOCK && pidptr != NULL) {
|
|
||||||
again:
|
|
||||||
errno = pidfile_read(pfh->pf_path, pidptr);
|
|
||||||
if (errno == 0)
|
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
else if (errno == EAGAIN) {
|
} else {
|
||||||
if (++count <= 3) {
|
count = 20;
|
||||||
|
rqtp.tv_sec = 0;
|
||||||
|
rqtp.tv_nsec = 5000000;
|
||||||
|
for (;;) {
|
||||||
|
errno = pidfile_read(pfh->pf_path,
|
||||||
|
pidptr);
|
||||||
|
if (errno != EAGAIN || --count == 0)
|
||||||
|
break;
|
||||||
nanosleep(&rqtp, 0);
|
nanosleep(&rqtp, 0);
|
||||||
goto again;
|
|
||||||
}
|
}
|
||||||
|
if (errno == EAGAIN)
|
||||||
|
*pidptr = -1;
|
||||||
|
if (errno == 0 || errno == EAGAIN)
|
||||||
|
errno = EEXIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
error = errno;
|
||||||
free(pfh->pf_path);
|
free(pfh->pf_path);
|
||||||
free(pfh);
|
free(pfh);
|
||||||
|
errno = error;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remember file information, so in pidfile_write() we are sure we write
|
* Remember file information, so in pidfile_write() we are sure we write
|
||||||
* to the proper descriptor.
|
* to the proper descriptor.
|
||||||
@@ -251,3 +266,14 @@ pidfile_remove(struct pidfh *pfh)
|
|||||||
|
|
||||||
return (_pidfile_remove(pfh, 1));
|
return (_pidfile_remove(pfh, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pidfile_fileno(const struct pidfh *pfh)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (pfh == NULL || pfh->pf_fd == -1) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (pfh->pf_fd);
|
||||||
|
}
|
||||||
|
@@ -34,6 +34,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
|
||||||
|
#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/' || (c) == '\\')
|
||||||
|
#else
|
||||||
|
#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/')
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE___PROGNAME
|
#ifdef HAVE___PROGNAME
|
||||||
extern const char *__progname;
|
extern const char *__progname;
|
||||||
#else
|
#else
|
||||||
@@ -58,11 +64,13 @@ getprogname(void)
|
|||||||
void
|
void
|
||||||
setprogname(const char *progname)
|
setprogname(const char *progname)
|
||||||
{
|
{
|
||||||
const char *last_slash;
|
size_t i;
|
||||||
|
|
||||||
last_slash = strrchr(progname, '/');
|
for (i = strlen(progname); i > 0; i--) {
|
||||||
if (last_slash == NULL)
|
if (LIBBSD_IS_PATHNAME_SEPARATOR(progname[i - 1])) {
|
||||||
__progname = progname;
|
__progname = progname + i;
|
||||||
else
|
return;
|
||||||
__progname = last_slash + 1;
|
}
|
||||||
|
}
|
||||||
|
__progname = progname;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
/* $NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $ */
|
/* $NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl 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.
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
/* $OpenBSD: readpassphrase.c,v 1.20 2007/10/30 12:03:48 millert Exp $ */
|
/* $OpenBSD: readpassphrase.c,v 1.26 2016/10/18 12:47:18 millert Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 2000-2002, 2007, 2010
|
||||||
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
#define TCSASOFT 0
|
#define TCSASOFT 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static volatile sig_atomic_t signo;
|
static volatile sig_atomic_t signo[_NSIG];
|
||||||
|
|
||||||
static void handler(int);
|
static void handler(int);
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ char *
|
|||||||
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
|
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
|
||||||
{
|
{
|
||||||
ssize_t nr;
|
ssize_t nr;
|
||||||
int input, output, save_errno;
|
int input, output, save_errno, i, need_restart;
|
||||||
char ch, *p, *end;
|
char ch, *p, *end;
|
||||||
struct termios term, oterm;
|
struct termios term, oterm;
|
||||||
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
|
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
|
||||||
@@ -56,9 +57,11 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
signo = 0;
|
for (i = 0; i < _NSIG; i++)
|
||||||
|
signo[i] = 0;
|
||||||
nr = -1;
|
nr = -1;
|
||||||
save_errno = 0;
|
save_errno = 0;
|
||||||
|
need_restart = 0;
|
||||||
/*
|
/*
|
||||||
* Read and write to /dev/tty if available. If not, read from
|
* Read and write to /dev/tty if available. If not, read from
|
||||||
* stdin and write to stderr unless a tty is required.
|
* stdin and write to stderr unless a tty is required.
|
||||||
@@ -73,6 +76,27 @@ restart:
|
|||||||
output = STDERR_FILENO;
|
output = STDERR_FILENO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Turn off echo if possible.
|
||||||
|
* If we are using a tty but are not the foreground pgrp this will
|
||||||
|
* generate SIGTTOU, so do it *before* installing the signal handlers.
|
||||||
|
*/
|
||||||
|
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
|
||||||
|
memcpy(&term, &oterm, sizeof(term));
|
||||||
|
if (!(flags & RPP_ECHO_ON))
|
||||||
|
term.c_lflag &= ~(ECHO | ECHONL);
|
||||||
|
#ifdef VSTATUS
|
||||||
|
if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
|
||||||
|
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
|
||||||
|
#endif
|
||||||
|
(void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
|
||||||
|
} else {
|
||||||
|
memset(&term, 0, sizeof(term));
|
||||||
|
term.c_lflag |= ECHO;
|
||||||
|
memset(&oterm, 0, sizeof(oterm));
|
||||||
|
oterm.c_lflag |= ECHO;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Catch signals that would otherwise cause the user to end
|
* Catch signals that would otherwise cause the user to end
|
||||||
* up with echo turned off in the shell. Don't worry about
|
* up with echo turned off in the shell. Don't worry about
|
||||||
@@ -91,53 +115,37 @@ restart:
|
|||||||
(void)sigaction(SIGTTIN, &sa, &savettin);
|
(void)sigaction(SIGTTIN, &sa, &savettin);
|
||||||
(void)sigaction(SIGTTOU, &sa, &savettou);
|
(void)sigaction(SIGTTOU, &sa, &savettou);
|
||||||
|
|
||||||
/* Turn off echo if possible. */
|
if (!(flags & RPP_STDIN))
|
||||||
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
|
(void)write(output, prompt, strlen(prompt));
|
||||||
memcpy(&term, &oterm, sizeof(term));
|
end = buf + bufsiz - 1;
|
||||||
if (!(flags & RPP_ECHO_ON))
|
p = buf;
|
||||||
term.c_lflag &= ~(ECHO | ECHONL);
|
while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
|
||||||
#ifdef VSTATUS
|
if (p < end) {
|
||||||
if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
|
if ((flags & RPP_SEVENBIT))
|
||||||
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
|
ch &= 0x7f;
|
||||||
#endif
|
if (isalpha((unsigned char)ch)) {
|
||||||
(void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
|
if ((flags & RPP_FORCELOWER))
|
||||||
} else {
|
ch = (char)tolower((unsigned char)ch);
|
||||||
memset(&term, 0, sizeof(term));
|
if ((flags & RPP_FORCEUPPER))
|
||||||
term.c_lflag |= ECHO;
|
ch = (char)toupper((unsigned char)ch);
|
||||||
memset(&oterm, 0, sizeof(oterm));
|
|
||||||
oterm.c_lflag |= ECHO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No I/O if we are already backgrounded. */
|
|
||||||
if (signo != SIGTTOU && signo != SIGTTIN) {
|
|
||||||
if (!(flags & RPP_STDIN))
|
|
||||||
(void)write(output, prompt, strlen(prompt));
|
|
||||||
end = buf + bufsiz - 1;
|
|
||||||
p = buf;
|
|
||||||
while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
|
|
||||||
if (p < end) {
|
|
||||||
if ((flags & RPP_SEVENBIT))
|
|
||||||
ch &= 0x7f;
|
|
||||||
if (isalpha(ch)) {
|
|
||||||
if ((flags & RPP_FORCELOWER))
|
|
||||||
ch = (char)tolower(ch);
|
|
||||||
if ((flags & RPP_FORCEUPPER))
|
|
||||||
ch = (char)toupper(ch);
|
|
||||||
}
|
|
||||||
*p++ = ch;
|
|
||||||
}
|
}
|
||||||
|
*p++ = ch;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
|
||||||
save_errno = errno;
|
|
||||||
if (!(term.c_lflag & ECHO))
|
|
||||||
(void)write(output, "\n", 1);
|
|
||||||
}
|
}
|
||||||
|
*p = '\0';
|
||||||
|
save_errno = errno;
|
||||||
|
if (!(term.c_lflag & ECHO))
|
||||||
|
(void)write(output, "\n", 1);
|
||||||
|
|
||||||
/* Restore old terminal settings and signals. */
|
/* Restore old terminal settings and signals. */
|
||||||
if (memcmp(&term, &oterm, sizeof(term)) != 0) {
|
if (memcmp(&term, &oterm, sizeof(term)) != 0) {
|
||||||
|
const int sigttou = signo[SIGTTOU];
|
||||||
|
|
||||||
|
/* Ignore SIGTTOU generated when we are not the fg pgrp. */
|
||||||
while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
|
while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
|
||||||
errno == EINTR)
|
errno == EINTR && !signo[SIGTTOU])
|
||||||
continue;
|
continue;
|
||||||
|
signo[SIGTTOU] = sigttou;
|
||||||
}
|
}
|
||||||
(void)sigaction(SIGALRM, &savealrm, NULL);
|
(void)sigaction(SIGALRM, &savealrm, NULL);
|
||||||
(void)sigaction(SIGHUP, &savehup, NULL);
|
(void)sigaction(SIGHUP, &savehup, NULL);
|
||||||
@@ -155,15 +163,19 @@ restart:
|
|||||||
* If we were interrupted by a signal, resend it to ourselves
|
* If we were interrupted by a signal, resend it to ourselves
|
||||||
* now that we have restored the signal handlers.
|
* now that we have restored the signal handlers.
|
||||||
*/
|
*/
|
||||||
if (signo) {
|
for (i = 0; i < _NSIG; i++) {
|
||||||
kill(getpid(), signo);
|
if (signo[i]) {
|
||||||
switch (signo) {
|
kill(getpid(), i);
|
||||||
case SIGTSTP:
|
switch (i) {
|
||||||
case SIGTTIN:
|
case SIGTSTP:
|
||||||
case SIGTTOU:
|
case SIGTTIN:
|
||||||
goto restart;
|
case SIGTTOU:
|
||||||
|
need_restart = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (need_restart)
|
||||||
|
goto restart;
|
||||||
|
|
||||||
if (save_errno)
|
if (save_errno)
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
@@ -183,5 +195,5 @@ getpass(const char *prompt)
|
|||||||
static void handler(int s)
|
static void handler(int s)
|
||||||
{
|
{
|
||||||
|
|
||||||
signo = s;
|
signo[s] = 1;
|
||||||
}
|
}
|
||||||
|
@@ -173,14 +173,14 @@ setproctitle_init(int argc, char *argv[], char *envp[])
|
|||||||
end = nul + 1;
|
end = nul + 1;
|
||||||
|
|
||||||
for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
|
for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
|
||||||
if (argv[i] == NULL || argv[i] < end)
|
if (argv[i] == NULL || argv[i] != end)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
end = argv[i] + strlen(argv[i]) + 1;
|
end = argv[i] + strlen(argv[i]) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; envp[i]; i++) {
|
for (i = 0; envp[i]; i++) {
|
||||||
if (envp[i] < end)
|
if (envp[i] != end)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
end = envp[i] + strlen(envp[i]) + 1;
|
end = envp[i] + strlen(envp[i]) + 1;
|
||||||
|
97
src/strtoi.c
Normal file
97
src/strtoi.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 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.
|
||||||
|
*
|
||||||
|
* Original version ID:
|
||||||
|
* NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
|
||||||
|
*
|
||||||
|
* Created by Kamil Rytarowski, based on ID:
|
||||||
|
* NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joe…
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define _DIAGASSERT(t)
|
||||||
|
|
||||||
|
intmax_t
|
||||||
|
strtoi(const char *__restrict nptr,
|
||||||
|
char **__restrict endptr, int base,
|
||||||
|
intmax_t lo, intmax_t hi, int *rstatus)
|
||||||
|
{
|
||||||
|
int serrno;
|
||||||
|
intmax_t im;
|
||||||
|
char *ep;
|
||||||
|
int rep;
|
||||||
|
|
||||||
|
_DIAGASSERT(hi >= lo);
|
||||||
|
|
||||||
|
_DIAGASSERT(nptr != NULL);
|
||||||
|
/* endptr may be NULL */
|
||||||
|
|
||||||
|
if (endptr == NULL)
|
||||||
|
endptr = &ep;
|
||||||
|
|
||||||
|
if (rstatus == NULL)
|
||||||
|
rstatus = &rep;
|
||||||
|
|
||||||
|
serrno = errno;
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
im = strtoimax(nptr, endptr, base);
|
||||||
|
|
||||||
|
*rstatus = errno;
|
||||||
|
errno = serrno;
|
||||||
|
|
||||||
|
if (*rstatus == 0) {
|
||||||
|
/* No digits were found */
|
||||||
|
if (nptr == *endptr)
|
||||||
|
*rstatus = ECANCELED;
|
||||||
|
/* There are further characters after number */
|
||||||
|
else if (**endptr != '\0')
|
||||||
|
*rstatus = ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (im < lo) {
|
||||||
|
if (*rstatus == 0)
|
||||||
|
*rstatus = ERANGE;
|
||||||
|
return lo;
|
||||||
|
}
|
||||||
|
if (im > hi) {
|
||||||
|
if (*rstatus == 0)
|
||||||
|
*rstatus = ERANGE;
|
||||||
|
return hi;
|
||||||
|
}
|
||||||
|
|
||||||
|
return im;
|
||||||
|
}
|
@@ -1,67 +1,62 @@
|
|||||||
|
/* $NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $ */
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2004 Ted Unangst and Todd Miller
|
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* by Christos Zoulas.
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
* modification, are permitted provided that the following conditions
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
* are met:
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $
|
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <stdio.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#define INVALID 1
|
#include <inttypes.h>
|
||||||
#define TOOSMALL 2
|
|
||||||
#define TOOLARGE 3
|
|
||||||
|
|
||||||
long long
|
long long
|
||||||
strtonum(const char *numstr, long long minval, long long maxval,
|
strtonum(const char *nptr, long long minval, long long maxval,
|
||||||
const char **errstrp)
|
const char **errstr)
|
||||||
{
|
{
|
||||||
long long ll = 0;
|
int e;
|
||||||
char *ep;
|
long long rv;
|
||||||
int error = 0;
|
const char *resp;
|
||||||
struct errval {
|
|
||||||
const char *errstr;
|
|
||||||
int err;
|
|
||||||
} ev[4] = {
|
|
||||||
{ NULL, 0 },
|
|
||||||
{ "invalid", EINVAL },
|
|
||||||
{ "too small", ERANGE },
|
|
||||||
{ "too large", ERANGE },
|
|
||||||
};
|
|
||||||
|
|
||||||
ev[0].err = errno;
|
if (errstr == NULL)
|
||||||
errno = 0;
|
errstr = &resp;
|
||||||
if (minval > maxval)
|
|
||||||
error = INVALID;
|
rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, &e);
|
||||||
else {
|
|
||||||
ll = strtoll(numstr, &ep, 10);
|
if (e == 0) {
|
||||||
if (errno == EINVAL || numstr == ep || *ep != '\0')
|
*errstr = NULL;
|
||||||
error = INVALID;
|
return rv;
|
||||||
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
|
|
||||||
error = TOOSMALL;
|
|
||||||
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
|
|
||||||
error = TOOLARGE;
|
|
||||||
}
|
}
|
||||||
if (errstrp != NULL)
|
|
||||||
*errstrp = ev[error].errstr;
|
|
||||||
errno = ev[error].err;
|
|
||||||
if (error)
|
|
||||||
ll = 0;
|
|
||||||
|
|
||||||
return (ll);
|
if (e == ERANGE)
|
||||||
|
*errstr = (rv == maxval ? "too large" : "too small");
|
||||||
|
else
|
||||||
|
*errstr = "invalid";
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
97
src/strtou.c
Normal file
97
src/strtou.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 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.
|
||||||
|
*
|
||||||
|
* Original version ID:
|
||||||
|
* NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
|
||||||
|
*
|
||||||
|
* Created by Kamil Rytarowski, based on ID:
|
||||||
|
* NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joe…
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define _DIAGASSERT(t)
|
||||||
|
|
||||||
|
uintmax_t
|
||||||
|
strtou(const char *__restrict nptr,
|
||||||
|
char **__restrict endptr, int base,
|
||||||
|
uintmax_t lo, uintmax_t hi, int *rstatus)
|
||||||
|
{
|
||||||
|
int serrno;
|
||||||
|
uintmax_t im;
|
||||||
|
char *ep;
|
||||||
|
int rep;
|
||||||
|
|
||||||
|
_DIAGASSERT(hi >= lo);
|
||||||
|
|
||||||
|
_DIAGASSERT(nptr != NULL);
|
||||||
|
/* endptr may be NULL */
|
||||||
|
|
||||||
|
if (endptr == NULL)
|
||||||
|
endptr = &ep;
|
||||||
|
|
||||||
|
if (rstatus == NULL)
|
||||||
|
rstatus = &rep;
|
||||||
|
|
||||||
|
serrno = errno;
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
im = strtoumax(nptr, endptr, base);
|
||||||
|
|
||||||
|
*rstatus = errno;
|
||||||
|
errno = serrno;
|
||||||
|
|
||||||
|
if (*rstatus == 0) {
|
||||||
|
/* No digits were found */
|
||||||
|
if (nptr == *endptr)
|
||||||
|
*rstatus = ECANCELED;
|
||||||
|
/* There are further characters after number */
|
||||||
|
else if (**endptr != '\0')
|
||||||
|
*rstatus = ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (im < lo) {
|
||||||
|
if (*rstatus == 0)
|
||||||
|
*rstatus = ERANGE;
|
||||||
|
return lo;
|
||||||
|
}
|
||||||
|
if (im > hi) {
|
||||||
|
if (*rstatus == 0)
|
||||||
|
*rstatus = ERANGE;
|
||||||
|
return hi;
|
||||||
|
}
|
||||||
|
|
||||||
|
return im;
|
||||||
|
}
|
569
src/unvis.c
569
src/unvis.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* $NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -27,9 +29,24 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wcpp"
|
||||||
#include <vis.h>
|
#include <vis.h>
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
#ifdef __weak_alias
|
||||||
|
__weak_alias(strnunvisx,_strnunvisx)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _DIAGASSERT(x)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* decode driven by state machine
|
* decode driven by state machine
|
||||||
@@ -41,15 +58,128 @@
|
|||||||
#define S_CTRL 4 /* control char started (^) */
|
#define S_CTRL 4 /* control char started (^) */
|
||||||
#define S_OCTAL2 5 /* octal digit 2 */
|
#define S_OCTAL2 5 /* octal digit 2 */
|
||||||
#define S_OCTAL3 6 /* octal digit 3 */
|
#define S_OCTAL3 6 /* octal digit 3 */
|
||||||
#define S_HEX2 7 /* hex digit 2 */
|
#define S_HEX 7 /* mandatory hex digit */
|
||||||
|
#define S_HEX1 8 /* http hex digit */
|
||||||
|
#define S_HEX2 9 /* http hex digit 2 */
|
||||||
|
#define S_MIME1 10 /* mime hex digit 1 */
|
||||||
|
#define S_MIME2 11 /* mime hex digit 2 */
|
||||||
|
#define S_EATCRNL 12 /* mime eating CRNL */
|
||||||
|
#define S_AMP 13 /* seen & */
|
||||||
|
#define S_NUMBER 14 /* collecting number */
|
||||||
|
#define S_STRING 15 /* collecting string */
|
||||||
|
|
||||||
#define S_HTTP 0x080 /* %HEXHEX escape */
|
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
||||||
|
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
|
||||||
|
#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10))
|
||||||
|
|
||||||
#define isoctal(c) \
|
/*
|
||||||
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
|
* RFC 1866
|
||||||
#define ishex(c) \
|
*/
|
||||||
((((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '9') || \
|
static const struct nv {
|
||||||
(((unsigned char)(c)) >= 'a' && ((unsigned char)(c)) <= 'f'))
|
char name[7];
|
||||||
|
uint8_t value;
|
||||||
|
} nv[] = {
|
||||||
|
{ "AElig", 198 }, /* capital AE diphthong (ligature) */
|
||||||
|
{ "Aacute", 193 }, /* capital A, acute accent */
|
||||||
|
{ "Acirc", 194 }, /* capital A, circumflex accent */
|
||||||
|
{ "Agrave", 192 }, /* capital A, grave accent */
|
||||||
|
{ "Aring", 197 }, /* capital A, ring */
|
||||||
|
{ "Atilde", 195 }, /* capital A, tilde */
|
||||||
|
{ "Auml", 196 }, /* capital A, dieresis or umlaut mark */
|
||||||
|
{ "Ccedil", 199 }, /* capital C, cedilla */
|
||||||
|
{ "ETH", 208 }, /* capital Eth, Icelandic */
|
||||||
|
{ "Eacute", 201 }, /* capital E, acute accent */
|
||||||
|
{ "Ecirc", 202 }, /* capital E, circumflex accent */
|
||||||
|
{ "Egrave", 200 }, /* capital E, grave accent */
|
||||||
|
{ "Euml", 203 }, /* capital E, dieresis or umlaut mark */
|
||||||
|
{ "Iacute", 205 }, /* capital I, acute accent */
|
||||||
|
{ "Icirc", 206 }, /* capital I, circumflex accent */
|
||||||
|
{ "Igrave", 204 }, /* capital I, grave accent */
|
||||||
|
{ "Iuml", 207 }, /* capital I, dieresis or umlaut mark */
|
||||||
|
{ "Ntilde", 209 }, /* capital N, tilde */
|
||||||
|
{ "Oacute", 211 }, /* capital O, acute accent */
|
||||||
|
{ "Ocirc", 212 }, /* capital O, circumflex accent */
|
||||||
|
{ "Ograve", 210 }, /* capital O, grave accent */
|
||||||
|
{ "Oslash", 216 }, /* capital O, slash */
|
||||||
|
{ "Otilde", 213 }, /* capital O, tilde */
|
||||||
|
{ "Ouml", 214 }, /* capital O, dieresis or umlaut mark */
|
||||||
|
{ "THORN", 222 }, /* capital THORN, Icelandic */
|
||||||
|
{ "Uacute", 218 }, /* capital U, acute accent */
|
||||||
|
{ "Ucirc", 219 }, /* capital U, circumflex accent */
|
||||||
|
{ "Ugrave", 217 }, /* capital U, grave accent */
|
||||||
|
{ "Uuml", 220 }, /* capital U, dieresis or umlaut mark */
|
||||||
|
{ "Yacute", 221 }, /* capital Y, acute accent */
|
||||||
|
{ "aacute", 225 }, /* small a, acute accent */
|
||||||
|
{ "acirc", 226 }, /* small a, circumflex accent */
|
||||||
|
{ "acute", 180 }, /* acute accent */
|
||||||
|
{ "aelig", 230 }, /* small ae diphthong (ligature) */
|
||||||
|
{ "agrave", 224 }, /* small a, grave accent */
|
||||||
|
{ "amp", 38 }, /* ampersand */
|
||||||
|
{ "aring", 229 }, /* small a, ring */
|
||||||
|
{ "atilde", 227 }, /* small a, tilde */
|
||||||
|
{ "auml", 228 }, /* small a, dieresis or umlaut mark */
|
||||||
|
{ "brvbar", 166 }, /* broken (vertical) bar */
|
||||||
|
{ "ccedil", 231 }, /* small c, cedilla */
|
||||||
|
{ "cedil", 184 }, /* cedilla */
|
||||||
|
{ "cent", 162 }, /* cent sign */
|
||||||
|
{ "copy", 169 }, /* copyright sign */
|
||||||
|
{ "curren", 164 }, /* general currency sign */
|
||||||
|
{ "deg", 176 }, /* degree sign */
|
||||||
|
{ "divide", 247 }, /* divide sign */
|
||||||
|
{ "eacute", 233 }, /* small e, acute accent */
|
||||||
|
{ "ecirc", 234 }, /* small e, circumflex accent */
|
||||||
|
{ "egrave", 232 }, /* small e, grave accent */
|
||||||
|
{ "eth", 240 }, /* small eth, Icelandic */
|
||||||
|
{ "euml", 235 }, /* small e, dieresis or umlaut mark */
|
||||||
|
{ "frac12", 189 }, /* fraction one-half */
|
||||||
|
{ "frac14", 188 }, /* fraction one-quarter */
|
||||||
|
{ "frac34", 190 }, /* fraction three-quarters */
|
||||||
|
{ "gt", 62 }, /* greater than */
|
||||||
|
{ "iacute", 237 }, /* small i, acute accent */
|
||||||
|
{ "icirc", 238 }, /* small i, circumflex accent */
|
||||||
|
{ "iexcl", 161 }, /* inverted exclamation mark */
|
||||||
|
{ "igrave", 236 }, /* small i, grave accent */
|
||||||
|
{ "iquest", 191 }, /* inverted question mark */
|
||||||
|
{ "iuml", 239 }, /* small i, dieresis or umlaut mark */
|
||||||
|
{ "laquo", 171 }, /* angle quotation mark, left */
|
||||||
|
{ "lt", 60 }, /* less than */
|
||||||
|
{ "macr", 175 }, /* macron */
|
||||||
|
{ "micro", 181 }, /* micro sign */
|
||||||
|
{ "middot", 183 }, /* middle dot */
|
||||||
|
{ "nbsp", 160 }, /* no-break space */
|
||||||
|
{ "not", 172 }, /* not sign */
|
||||||
|
{ "ntilde", 241 }, /* small n, tilde */
|
||||||
|
{ "oacute", 243 }, /* small o, acute accent */
|
||||||
|
{ "ocirc", 244 }, /* small o, circumflex accent */
|
||||||
|
{ "ograve", 242 }, /* small o, grave accent */
|
||||||
|
{ "ordf", 170 }, /* ordinal indicator, feminine */
|
||||||
|
{ "ordm", 186 }, /* ordinal indicator, masculine */
|
||||||
|
{ "oslash", 248 }, /* small o, slash */
|
||||||
|
{ "otilde", 245 }, /* small o, tilde */
|
||||||
|
{ "ouml", 246 }, /* small o, dieresis or umlaut mark */
|
||||||
|
{ "para", 182 }, /* pilcrow (paragraph sign) */
|
||||||
|
{ "plusmn", 177 }, /* plus-or-minus sign */
|
||||||
|
{ "pound", 163 }, /* pound sterling sign */
|
||||||
|
{ "quot", 34 }, /* double quote */
|
||||||
|
{ "raquo", 187 }, /* angle quotation mark, right */
|
||||||
|
{ "reg", 174 }, /* registered sign */
|
||||||
|
{ "sect", 167 }, /* section sign */
|
||||||
|
{ "shy", 173 }, /* soft hyphen */
|
||||||
|
{ "sup1", 185 }, /* superscript one */
|
||||||
|
{ "sup2", 178 }, /* superscript two */
|
||||||
|
{ "sup3", 179 }, /* superscript three */
|
||||||
|
{ "szlig", 223 }, /* small sharp s, German (sz ligature) */
|
||||||
|
{ "thorn", 254 }, /* small thorn, Icelandic */
|
||||||
|
{ "times", 215 }, /* multiply sign */
|
||||||
|
{ "uacute", 250 }, /* small u, acute accent */
|
||||||
|
{ "ucirc", 251 }, /* small u, circumflex accent */
|
||||||
|
{ "ugrave", 249 }, /* small u, grave accent */
|
||||||
|
{ "uml", 168 }, /* umlaut (dieresis) */
|
||||||
|
{ "uuml", 252 }, /* small u, dieresis or umlaut mark */
|
||||||
|
{ "yacute", 253 }, /* small y, acute accent */
|
||||||
|
{ "yen", 165 }, /* yen sign */
|
||||||
|
{ "yuml", 255 }, /* small y, dieresis or umlaut mark */
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unvis - decode characters previously encoded by vis
|
* unvis - decode characters previously encoded by vis
|
||||||
@@ -57,276 +187,389 @@
|
|||||||
int
|
int
|
||||||
unvis(char *cp, int c, int *astate, int flag)
|
unvis(char *cp, int c, int *astate, int flag)
|
||||||
{
|
{
|
||||||
|
unsigned char uc = (unsigned char)c;
|
||||||
|
unsigned char st, ia, is, lc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bottom 8 bits of astate hold the state machine state.
|
||||||
|
* Top 8 bits hold the current character in the http 1866 nv string decoding
|
||||||
|
*/
|
||||||
|
#define GS(a) ((a) & 0xff)
|
||||||
|
#define SS(a, b) (((uint32_t)(a) << 24) | (b))
|
||||||
|
#define GI(a) ((uint32_t)(a) >> 24)
|
||||||
|
|
||||||
|
_DIAGASSERT(cp != NULL);
|
||||||
|
_DIAGASSERT(astate != NULL);
|
||||||
|
st = GS(*astate);
|
||||||
|
|
||||||
if (flag & UNVIS_END) {
|
if (flag & UNVIS_END) {
|
||||||
if (*astate == S_OCTAL2 || *astate == S_OCTAL3) {
|
switch (st) {
|
||||||
*astate = S_GROUND;
|
case S_OCTAL2:
|
||||||
return (UNVIS_VALID);
|
case S_OCTAL3:
|
||||||
|
case S_HEX2:
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
case S_GROUND:
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
default:
|
||||||
|
return UNVIS_SYNBAD;
|
||||||
}
|
}
|
||||||
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*astate & ~S_HTTP) {
|
switch (st) {
|
||||||
|
|
||||||
case S_GROUND:
|
case S_GROUND:
|
||||||
*cp = 0;
|
*cp = 0;
|
||||||
if (c == '\\') {
|
if ((flag & VIS_NOESCAPE) == 0 && c == '\\') {
|
||||||
*astate = S_START;
|
*astate = SS(0, S_START);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
}
|
}
|
||||||
if (flag & VIS_HTTPSTYLE && c == '%') {
|
if ((flag & VIS_HTTP1808) && c == '%') {
|
||||||
*astate = S_START | S_HTTP;
|
*astate = SS(0, S_HEX1);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
if ((flag & VIS_HTTP1866) && c == '&') {
|
||||||
|
*astate = SS(0, S_AMP);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
if ((flag & VIS_MIMESTYLE) && c == '=') {
|
||||||
|
*astate = SS(0, S_MIME1);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
}
|
}
|
||||||
*cp = c;
|
*cp = c;
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
|
|
||||||
case S_START:
|
case S_START:
|
||||||
if (*astate & S_HTTP) {
|
|
||||||
if (ishex(tolower(c))) {
|
|
||||||
*cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a');
|
|
||||||
*astate = S_HEX2;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case '\\':
|
case '\\':
|
||||||
*cp = c;
|
*cp = c;
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case '0': case '1': case '2': case '3':
|
case '0': case '1': case '2': case '3':
|
||||||
case '4': case '5': case '6': case '7':
|
case '4': case '5': case '6': case '7':
|
||||||
*cp = (c - '0');
|
*cp = (c - '0');
|
||||||
*astate = S_OCTAL2;
|
*astate = SS(0, S_OCTAL2);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
case 'M':
|
case 'M':
|
||||||
*cp = 0200;
|
*cp = (char)0200;
|
||||||
*astate = S_META;
|
*astate = SS(0, S_META);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
case '^':
|
case '^':
|
||||||
*astate = S_CTRL;
|
*astate = SS(0, S_CTRL);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
case 'n':
|
case 'n':
|
||||||
*cp = '\n';
|
*cp = '\n';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'r':
|
case 'r':
|
||||||
*cp = '\r';
|
*cp = '\r';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'b':
|
case 'b':
|
||||||
*cp = '\b';
|
*cp = '\b';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'a':
|
case 'a':
|
||||||
*cp = '\007';
|
*cp = '\007';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'v':
|
case 'v':
|
||||||
*cp = '\v';
|
*cp = '\v';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 't':
|
case 't':
|
||||||
*cp = '\t';
|
*cp = '\t';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'f':
|
case 'f':
|
||||||
*cp = '\f';
|
*cp = '\f';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 's':
|
case 's':
|
||||||
*cp = ' ';
|
*cp = ' ';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
case 'E':
|
case 'E':
|
||||||
*cp = '\033';
|
*cp = '\033';
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
|
case 'x':
|
||||||
|
*astate = SS(0, S_HEX);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
case '\n':
|
case '\n':
|
||||||
/*
|
/*
|
||||||
* hidden newline
|
* hidden newline
|
||||||
*/
|
*/
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_NOCHAR);
|
return UNVIS_NOCHAR;
|
||||||
case '$':
|
case '$':
|
||||||
/*
|
/*
|
||||||
* hidden marker
|
* hidden marker
|
||||||
*/
|
*/
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_NOCHAR);
|
return UNVIS_NOCHAR;
|
||||||
|
default:
|
||||||
|
if (isgraph(c)) {
|
||||||
|
*cp = c;
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*astate = S_GROUND;
|
goto bad;
|
||||||
return (UNVIS_SYNBAD);
|
|
||||||
|
|
||||||
case S_META:
|
case S_META:
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
*astate = S_META1;
|
*astate = SS(0, S_META1);
|
||||||
else if (c == '^')
|
else if (c == '^')
|
||||||
*astate = S_CTRL;
|
*astate = SS(0, S_CTRL);
|
||||||
else {
|
else
|
||||||
*astate = S_GROUND;
|
goto bad;
|
||||||
return (UNVIS_SYNBAD);
|
return UNVIS_NOCHAR;
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
case S_META1:
|
case S_META1:
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
*cp |= c;
|
*cp |= c;
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
|
|
||||||
case S_CTRL:
|
case S_CTRL:
|
||||||
if (c == '?')
|
if (c == '?')
|
||||||
*cp |= 0177;
|
*cp |= 0177;
|
||||||
else
|
else
|
||||||
*cp |= c & 037;
|
*cp |= c & 037;
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
|
|
||||||
case S_OCTAL2: /* second possible octal digit */
|
case S_OCTAL2: /* second possible octal digit */
|
||||||
if (isoctal(c)) {
|
if (isoctal(uc)) {
|
||||||
/*
|
/*
|
||||||
* yes - and maybe a third
|
* yes - and maybe a third
|
||||||
*/
|
*/
|
||||||
*cp = (*cp << 3) + (c - '0');
|
*cp = (*cp << 3) + (c - '0');
|
||||||
*astate = S_OCTAL3;
|
*astate = SS(0, S_OCTAL3);
|
||||||
return (0);
|
return UNVIS_NOCHAR;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* no - done with current sequence, push back passed char
|
* no - done with current sequence, push back passed char
|
||||||
*/
|
*/
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_VALIDPUSH);
|
return UNVIS_VALIDPUSH;
|
||||||
|
|
||||||
case S_OCTAL3: /* third possible octal digit */
|
case S_OCTAL3: /* third possible octal digit */
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
if (isoctal(c)) {
|
if (isoctal(uc)) {
|
||||||
*cp = (*cp << 3) + (c - '0');
|
*cp = (*cp << 3) + (c - '0');
|
||||||
return (UNVIS_VALID);
|
return UNVIS_VALID;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* we were done, push back passed char
|
* we were done, push back passed char
|
||||||
*/
|
*/
|
||||||
return (UNVIS_VALIDPUSH);
|
return UNVIS_VALIDPUSH;
|
||||||
|
|
||||||
case S_HEX2: /* second mandatory hex digit */
|
case S_HEX:
|
||||||
if (ishex(tolower(c))) {
|
if (!isxdigit(uc))
|
||||||
*cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10));
|
goto bad;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case S_HEX1:
|
||||||
|
if (isxdigit(uc)) {
|
||||||
|
*cp = xtod(uc);
|
||||||
|
*astate = SS(0, S_HEX2);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* no - done with current sequence, push back passed char
|
||||||
|
*/
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
return UNVIS_VALIDPUSH;
|
||||||
|
|
||||||
|
case S_HEX2:
|
||||||
*astate = S_GROUND;
|
*astate = S_GROUND;
|
||||||
return (UNVIS_VALID);
|
if (isxdigit(uc)) {
|
||||||
|
*cp = xtod(uc) | (*cp << 4);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
}
|
||||||
|
return UNVIS_VALIDPUSH;
|
||||||
|
|
||||||
|
case S_MIME1:
|
||||||
|
if (uc == '\n' || uc == '\r') {
|
||||||
|
*astate = SS(0, S_EATCRNL);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
if (isxdigit(uc) && (isdigit(uc) || isupper(uc))) {
|
||||||
|
*cp = XTOD(uc);
|
||||||
|
*astate = SS(0, S_MIME2);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
goto bad;
|
||||||
|
|
||||||
|
case S_MIME2:
|
||||||
|
if (isxdigit(uc) && (isdigit(uc) || isupper(uc))) {
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
*cp = XTOD(uc) | (*cp << 4);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
}
|
||||||
|
goto bad;
|
||||||
|
|
||||||
|
case S_EATCRNL:
|
||||||
|
switch (uc) {
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
case '=':
|
||||||
|
*astate = SS(0, S_MIME1);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
default:
|
||||||
|
*cp = uc;
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
case S_AMP:
|
||||||
|
*cp = 0;
|
||||||
|
if (uc == '#') {
|
||||||
|
*astate = SS(0, S_NUMBER);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
*astate = SS(0, S_STRING);
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
|
||||||
|
case S_STRING:
|
||||||
|
ia = *cp; /* index in the array */
|
||||||
|
is = GI(*astate); /* index in the string */
|
||||||
|
lc = is == 0 ? 0 : nv[ia].name[is - 1]; /* last character */
|
||||||
|
|
||||||
|
if (uc == ';')
|
||||||
|
uc = '\0';
|
||||||
|
|
||||||
|
for (; ia < __arraycount(nv); ia++) {
|
||||||
|
if (is != 0 && nv[ia].name[is - 1] != lc)
|
||||||
|
goto bad;
|
||||||
|
if (nv[ia].name[is] == uc)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ia == __arraycount(nv))
|
||||||
|
goto bad;
|
||||||
|
|
||||||
|
if (uc != 0) {
|
||||||
|
*cp = ia;
|
||||||
|
*astate = SS(is + 1, S_STRING);
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*cp = nv[ia].value;
|
||||||
|
*astate = SS(0, S_GROUND);
|
||||||
|
return UNVIS_VALID;
|
||||||
|
|
||||||
|
case S_NUMBER:
|
||||||
|
if (uc == ';')
|
||||||
|
return UNVIS_VALID;
|
||||||
|
if (!isdigit(uc))
|
||||||
|
goto bad;
|
||||||
|
*cp += (*cp * 10) + uc - '0';
|
||||||
|
return UNVIS_NOCHAR;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
bad:
|
||||||
/*
|
/*
|
||||||
* decoder in unknown state - (probably uninitialized)
|
* decoder in unknown state - (probably uninitialized)
|
||||||
*/
|
*/
|
||||||
*astate = S_GROUND;
|
*astate = SS(0, S_GROUND);
|
||||||
return (UNVIS_SYNBAD);
|
return UNVIS_SYNBAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* strunvis - decode src into dst
|
* strnunvisx - decode src into dst
|
||||||
*
|
*
|
||||||
* Number of chars decoded into dst is returned, -1 on error.
|
* Number of chars decoded into dst is returned, -1 on error.
|
||||||
* Dst is null terminated.
|
* Dst is null terminated.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
strunvis(char *dst, const char *src)
|
strnunvisx(char *dst, size_t dlen, const char *src, int flag)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
char *start = dst;
|
char t = '\0', *start = dst;
|
||||||
int state = 0;
|
int state = 0;
|
||||||
|
|
||||||
while ((c = *src++)) {
|
_DIAGASSERT(src != NULL);
|
||||||
again:
|
_DIAGASSERT(dst != NULL);
|
||||||
switch (unvis(dst, c, &state, 0)) {
|
#define CHECKSPACE() \
|
||||||
|
do { \
|
||||||
|
if (dlen-- == 0) { \
|
||||||
|
errno = ENOSPC; \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
|
while ((c = *src++) != '\0') {
|
||||||
|
again:
|
||||||
|
switch (unvis(&t, c, &state, flag)) {
|
||||||
case UNVIS_VALID:
|
case UNVIS_VALID:
|
||||||
dst++;
|
CHECKSPACE();
|
||||||
|
*dst++ = t;
|
||||||
break;
|
break;
|
||||||
case UNVIS_VALIDPUSH:
|
case UNVIS_VALIDPUSH:
|
||||||
dst++;
|
CHECKSPACE();
|
||||||
|
*dst++ = t;
|
||||||
goto again;
|
goto again;
|
||||||
case 0:
|
case 0:
|
||||||
case UNVIS_NOCHAR:
|
case UNVIS_NOCHAR:
|
||||||
break;
|
break;
|
||||||
|
case UNVIS_SYNBAD:
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
default:
|
default:
|
||||||
*dst = '\0';
|
_DIAGASSERT(/*CONSTCOND*/0);
|
||||||
return (-1);
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
|
if (unvis(&t, c, &state, UNVIS_END) == UNVIS_VALID) {
|
||||||
dst++;
|
CHECKSPACE();
|
||||||
|
*dst++ = t;
|
||||||
|
}
|
||||||
|
CHECKSPACE();
|
||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
return (dst - start);
|
return (int)(dst - start);
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
|
||||||
strnunvis(char *dst, const char *src, size_t sz)
|
|
||||||
{
|
|
||||||
char c, p;
|
|
||||||
char *start = dst, *end = dst + sz - 1;
|
|
||||||
int state = 0;
|
|
||||||
|
|
||||||
if (sz > 0)
|
|
||||||
*end = '\0';
|
|
||||||
while ((c = *src++)) {
|
|
||||||
again:
|
|
||||||
switch (unvis(&p, c, &state, 0)) {
|
|
||||||
case UNVIS_VALID:
|
|
||||||
if (dst < end)
|
|
||||||
*dst = p;
|
|
||||||
dst++;
|
|
||||||
break;
|
|
||||||
case UNVIS_VALIDPUSH:
|
|
||||||
if (dst < end)
|
|
||||||
*dst = p;
|
|
||||||
dst++;
|
|
||||||
goto again;
|
|
||||||
case 0:
|
|
||||||
case UNVIS_NOCHAR:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (dst <= end)
|
|
||||||
*dst = '\0';
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (unvis(&p, c, &state, UNVIS_END) == UNVIS_VALID) {
|
|
||||||
if (dst < end)
|
|
||||||
*dst = p;
|
|
||||||
dst++;
|
|
||||||
}
|
|
||||||
if (dst <= end)
|
|
||||||
*dst = '\0';
|
|
||||||
return (dst - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
strunvisx(char *dst, const char *src, int flag)
|
strunvisx(char *dst, const char *src, int flag)
|
||||||
{
|
{
|
||||||
char c;
|
return strnunvisx(dst, (size_t)~0, src, flag);
|
||||||
char *start = dst;
|
|
||||||
int state = 0;
|
|
||||||
|
|
||||||
while ((c = *src++)) {
|
|
||||||
again:
|
|
||||||
switch (unvis(dst, c, &state, flag)) {
|
|
||||||
case UNVIS_VALID:
|
|
||||||
dst++;
|
|
||||||
break;
|
|
||||||
case UNVIS_VALIDPUSH:
|
|
||||||
dst++;
|
|
||||||
goto again;
|
|
||||||
case 0:
|
|
||||||
case UNVIS_NOCHAR:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
|
|
||||||
dst++;
|
|
||||||
*dst = '\0';
|
|
||||||
return (dst - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strunvis(char *dst, const char *src)
|
||||||
|
{
|
||||||
|
return strnunvisx(dst, (size_t)~0, src, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* OpenBSD, 2001: strnunvis(char *dst, const char *src, size_t dlen);
|
||||||
|
* NetBSD: 2012, strnunvis(char *dst, size_t dlen, const char *src);
|
||||||
|
*/
|
||||||
|
ssize_t
|
||||||
|
strnunvis_openbsd(char *dst, const char *src, size_t dlen)
|
||||||
|
{
|
||||||
|
return strnunvisx(dst, dlen, src, 0);
|
||||||
|
}
|
||||||
|
__asm__(".symver strnunvis_openbsd,strnunvis@@LIBBSD_0.2");
|
||||||
|
|
||||||
|
int
|
||||||
|
strnunvis_netbsd(char *dst, size_t dlen, const char *src)
|
||||||
|
{
|
||||||
|
return strnunvisx(dst, dlen, src, 0);
|
||||||
|
}
|
||||||
|
__asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1");
|
||||||
|
897
src/vis.c
897
src/vis.c
@@ -1,4 +1,5 @@
|
|||||||
/* $OpenBSD: vis.c,v 1.18 2005/08/29 18:38:41 otto Exp $ */
|
/* $NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -28,220 +29,742 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
/*-
|
||||||
#include <limits.h>
|
* Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
|
||||||
#include <ctype.h>
|
* All rights reserved.
|
||||||
#include <string.h>
|
*
|
||||||
#include <stdio.h>
|
* Redistribution and use in source and binary forms, with or without
|
||||||
#include <vis.h>
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
#define isoctal(c) \
|
#include <sys/cdefs.h>
|
||||||
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
|
#include <sys/types.h>
|
||||||
#define isvisible(c) \
|
#include <sys/param.h>
|
||||||
(((unsigned int)(c) <= UCHAR_MAX && \
|
|
||||||
isascii((unsigned char)(c)) && \
|
#include <assert.h>
|
||||||
(((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \
|
#pragma GCC diagnostic push
|
||||||
(flag & VIS_GLOB) == 0) && \
|
#pragma GCC diagnostic ignored "-Wcpp"
|
||||||
isgraph((unsigned char)(c))) || \
|
#include <vis.h>
|
||||||
((flag & VIS_SP) == 0 && (c) == ' ') || \
|
#pragma GCC diagnostic pop
|
||||||
((flag & VIS_TAB) == 0 && (c) == '\t') || \
|
#include <errno.h>
|
||||||
((flag & VIS_NL) == 0 && (c) == '\n') || \
|
#include <stdlib.h>
|
||||||
((flag & VIS_SAFE) && ((c) == '\b' || \
|
#include <wchar.h>
|
||||||
(c) == '\007' || (c) == '\r' || \
|
#include <wctype.h>
|
||||||
isgraph((unsigned char)(c)))))
|
|
||||||
|
#ifdef __weak_alias
|
||||||
|
__weak_alias(strvisx,_strvisx)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define _DIAGASSERT(x)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The reason for going through the trouble to deal with character encodings
|
||||||
|
* in vis(3), is that we use this to safe encode output of commands. This
|
||||||
|
* safe encoding varies depending on the character set. For example if we
|
||||||
|
* display ps output in French, we don't want to display French characters
|
||||||
|
* as M-foo.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *);
|
||||||
|
|
||||||
|
#undef BELL
|
||||||
|
#define BELL L'\a'
|
||||||
|
|
||||||
|
#if defined(LC_C_LOCALE)
|
||||||
|
#define iscgraph(c) isgraph_l(c, LC_C_LOCALE)
|
||||||
|
#else
|
||||||
|
/* Keep it simple for now, no locale stuff */
|
||||||
|
#define iscgraph(c) isgraph(c)
|
||||||
|
#ifdef notyet
|
||||||
|
#include <locale.h>
|
||||||
|
static int
|
||||||
|
iscgraph(int c) {
|
||||||
|
int rv;
|
||||||
|
char *ol;
|
||||||
|
|
||||||
|
ol = setlocale(LC_CTYPE, "C");
|
||||||
|
rv = isgraph(c);
|
||||||
|
if (ol)
|
||||||
|
setlocale(LC_CTYPE, ol);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ISGRAPH(flags, c) \
|
||||||
|
(((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
|
||||||
|
|
||||||
|
#define iswoctal(c) (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
|
||||||
|
#define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n')
|
||||||
|
#define iswsafe(c) (c == L'\b' || c == BELL || c == L'\r')
|
||||||
|
#define xtoa(c) L"0123456789abcdef"[c]
|
||||||
|
#define XTOA(c) L"0123456789ABCDEF"[c]
|
||||||
|
|
||||||
|
#define MAXEXTRAS 30
|
||||||
|
|
||||||
|
static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~";
|
||||||
|
static const wchar_t char_glob[] = L"*?[#";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On NetBSD and glibc MB_LEN_MAX is currently > 8 which does not fit on any
|
||||||
|
* integer integral type and it is probably wrong, since currently the maximum
|
||||||
|
* number of bytes and character needs is 6. Until this is fixed, the
|
||||||
|
* loops below are using sizeof(uint64_t) - 1 instead of MB_LEN_MAX, and
|
||||||
|
* the assertion is commented out.
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
#ifndef CTASSERT
|
||||||
|
#define CTASSERT(x) _CTASSERT(x, __LINE__)
|
||||||
|
#define _CTASSERT(x, y) __CTASSERT(x, y)
|
||||||
|
#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CTASSERT(MB_LEN_MAX <= sizeof(uint64_t));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is do_hvis, for HTTP style (RFC 1808)
|
||||||
|
*/
|
||||||
|
static wchar_t *
|
||||||
|
do_hvis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
|
||||||
|
{
|
||||||
|
if (iswalnum(c)
|
||||||
|
/* safe */
|
||||||
|
|| c == L'$' || c == L'-' || c == L'_' || c == L'.' || c == L'+'
|
||||||
|
/* extra */
|
||||||
|
|| c == L'!' || c == L'*' || c == L'\'' || c == L'(' || c == L')'
|
||||||
|
|| c == L',')
|
||||||
|
dst = do_svis(dst, c, flags, nextc, extra);
|
||||||
|
else {
|
||||||
|
*dst++ = L'%';
|
||||||
|
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf);
|
||||||
|
*dst++ = xtoa((unsigned int)c & 0xf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is do_mvis, for Quoted-Printable MIME (RFC 2045)
|
||||||
|
* NB: No handling of long lines or CRLF.
|
||||||
|
*/
|
||||||
|
static wchar_t *
|
||||||
|
do_mvis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
|
||||||
|
{
|
||||||
|
if ((c != L'\n') &&
|
||||||
|
/* Space at the end of the line */
|
||||||
|
((iswspace(c) && (nextc == L'\r' || nextc == L'\n')) ||
|
||||||
|
/* Out of range */
|
||||||
|
(!iswspace(c) && (c < 33 || (c > 60 && c < 62) || c > 126)) ||
|
||||||
|
/* Specific char to be escaped */
|
||||||
|
wcschr(L"#$@[\\]^`{|}~", c) != NULL)) {
|
||||||
|
*dst++ = L'=';
|
||||||
|
*dst++ = XTOA(((unsigned int)c >> 4) & 0xf);
|
||||||
|
*dst++ = XTOA((unsigned int)c & 0xf);
|
||||||
|
} else
|
||||||
|
dst = do_svis(dst, c, flags, nextc, extra);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output single byte of multibyte character.
|
||||||
|
*/
|
||||||
|
static wchar_t *
|
||||||
|
do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra)
|
||||||
|
{
|
||||||
|
if (flags & VIS_CSTYLE) {
|
||||||
|
switch (c) {
|
||||||
|
case L'\n':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'n';
|
||||||
|
return dst;
|
||||||
|
case L'\r':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'r';
|
||||||
|
return dst;
|
||||||
|
case L'\b':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'b';
|
||||||
|
return dst;
|
||||||
|
case BELL:
|
||||||
|
*dst++ = L'\\'; *dst++ = L'a';
|
||||||
|
return dst;
|
||||||
|
case L'\v':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'v';
|
||||||
|
return dst;
|
||||||
|
case L'\t':
|
||||||
|
*dst++ = L'\\'; *dst++ = L't';
|
||||||
|
return dst;
|
||||||
|
case L'\f':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'f';
|
||||||
|
return dst;
|
||||||
|
case L' ':
|
||||||
|
*dst++ = L'\\'; *dst++ = L's';
|
||||||
|
return dst;
|
||||||
|
case L'\0':
|
||||||
|
*dst++ = L'\\'; *dst++ = L'0';
|
||||||
|
if (iswoctal(nextc)) {
|
||||||
|
*dst++ = L'0';
|
||||||
|
*dst++ = L'0';
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
/* We cannot encode these characters in VIS_CSTYLE
|
||||||
|
* because they special meaning */
|
||||||
|
case L'n':
|
||||||
|
case L'r':
|
||||||
|
case L'b':
|
||||||
|
case L'a':
|
||||||
|
case L'v':
|
||||||
|
case L't':
|
||||||
|
case L'f':
|
||||||
|
case L's':
|
||||||
|
case L'0':
|
||||||
|
case L'M':
|
||||||
|
case L'^':
|
||||||
|
case L'$': /* vis(1) -l */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (ISGRAPH(flags, c) && !iswoctal(c)) {
|
||||||
|
*dst++ = L'\\';
|
||||||
|
*dst++ = c;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) {
|
||||||
|
*dst++ = L'\\';
|
||||||
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0';
|
||||||
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0';
|
||||||
|
*dst++ = (c & 07) + L'0';
|
||||||
|
} else {
|
||||||
|
if ((flags & VIS_NOSLASH) == 0)
|
||||||
|
*dst++ = L'\\';
|
||||||
|
|
||||||
|
if (c & 0200) {
|
||||||
|
c &= 0177;
|
||||||
|
*dst++ = L'M';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iswcntrl(c)) {
|
||||||
|
*dst++ = L'^';
|
||||||
|
if (c == 0177)
|
||||||
|
*dst++ = L'?';
|
||||||
|
else
|
||||||
|
*dst++ = c + L'@';
|
||||||
|
} else {
|
||||||
|
*dst++ = L'-';
|
||||||
|
*dst++ = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is do_vis, the central code of vis.
|
||||||
|
* dst: Pointer to the destination buffer
|
||||||
|
* c: Character to encode
|
||||||
|
* flags: Flags word
|
||||||
|
* nextc: The character following 'c'
|
||||||
|
* extra: Pointer to the list of extra characters to be
|
||||||
|
* backslash-protected.
|
||||||
|
*/
|
||||||
|
static wchar_t *
|
||||||
|
do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
|
||||||
|
{
|
||||||
|
int iswextra, i, shft;
|
||||||
|
uint64_t bmsk, wmsk;
|
||||||
|
|
||||||
|
iswextra = wcschr(extra, c) != NULL;
|
||||||
|
if (!iswextra && (ISGRAPH(flags, c) || iswwhite(c) ||
|
||||||
|
((flags & VIS_SAFE) && iswsafe(c)))) {
|
||||||
|
*dst++ = c;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See comment in istrsenvisx() output loop, below. */
|
||||||
|
wmsk = 0;
|
||||||
|
for (i = sizeof(wmsk) - 1; i >= 0; i--) {
|
||||||
|
shft = i * NBBY;
|
||||||
|
bmsk = (uint64_t)0xffLL << shft;
|
||||||
|
wmsk |= bmsk;
|
||||||
|
if ((c & wmsk) || i == 0)
|
||||||
|
dst = do_mbyte(dst, (wint_t)(
|
||||||
|
(uint64_t)(c & bmsk) >> shft),
|
||||||
|
flags, nextc, iswextra);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef wchar_t *(*visfun_t)(wchar_t *, wint_t, int, wint_t, const wchar_t *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the appropriate encoding function depending on the flags given.
|
||||||
|
*/
|
||||||
|
static visfun_t
|
||||||
|
getvisfun(int flags)
|
||||||
|
{
|
||||||
|
if (flags & VIS_HTTPSTYLE)
|
||||||
|
return do_hvis;
|
||||||
|
if (flags & VIS_MIMESTYLE)
|
||||||
|
return do_mvis;
|
||||||
|
return do_svis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Expand list of extra characters to not visually encode.
|
||||||
|
*/
|
||||||
|
static wchar_t *
|
||||||
|
makeextralist(int flags, const char *src)
|
||||||
|
{
|
||||||
|
wchar_t *dst, *d;
|
||||||
|
size_t len;
|
||||||
|
const wchar_t *s;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
dst[i] = (wchar_t)(u_char)src[i];
|
||||||
|
d = dst + len;
|
||||||
|
} else
|
||||||
|
d = dst + wcslen(dst);
|
||||||
|
|
||||||
|
if (flags & VIS_GLOB)
|
||||||
|
for (s = char_glob; *s; *d++ = *s++)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (flags & VIS_SHELL)
|
||||||
|
for (s = char_shell; *s; *d++ = *s++)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (flags & VIS_SP) *d++ = L' ';
|
||||||
|
if (flags & VIS_TAB) *d++ = L'\t';
|
||||||
|
if (flags & VIS_NL) *d++ = L'\n';
|
||||||
|
if (flags & VIS_DQ) *d++ = L'"';
|
||||||
|
if ((flags & VIS_NOSLASH) == 0) *d++ = L'\\';
|
||||||
|
*d = L'\0';
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* istrsenvisx()
|
||||||
|
* The main internal function.
|
||||||
|
* All user-visible functions call this one.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||||
|
int flags, const char *mbextra, int *cerr_ptr)
|
||||||
|
{
|
||||||
|
wchar_t *dst, *src, *pdst, *psrc, *start, *extra;
|
||||||
|
size_t len, olen;
|
||||||
|
uint64_t bmsk, wmsk;
|
||||||
|
wint_t c;
|
||||||
|
visfun_t f;
|
||||||
|
int clen = 0, cerr, error = -1, i, shft;
|
||||||
|
char *mbdst, *mdst;
|
||||||
|
ssize_t mbslength, maxolen;
|
||||||
|
|
||||||
|
_DIAGASSERT(mbdstp != NULL);
|
||||||
|
_DIAGASSERT(mbsrc != NULL || mblength == 0);
|
||||||
|
_DIAGASSERT(mbextra != NULL);
|
||||||
|
|
||||||
|
mbslength = (ssize_t)mblength;
|
||||||
|
/*
|
||||||
|
* When inputing a single character, must also read in the
|
||||||
|
* next character for nextc, the look-ahead character.
|
||||||
|
*/
|
||||||
|
if (mbslength == 1)
|
||||||
|
mbslength++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input (mbsrc) is a char string considered to be multibyte
|
||||||
|
* characters. The input loop will read this string pulling
|
||||||
|
* one character, possibly multiple bytes, from mbsrc and
|
||||||
|
* converting each to wchar_t in src.
|
||||||
|
*
|
||||||
|
* The vis conversion will be done using the wide char
|
||||||
|
* wchar_t string.
|
||||||
|
*
|
||||||
|
* This will then be converted back to a multibyte string to
|
||||||
|
* return to the caller.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Allocate space for the wide char strings */
|
||||||
|
psrc = pdst = extra = NULL;
|
||||||
|
mdst = NULL;
|
||||||
|
if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL)
|
||||||
|
return -1;
|
||||||
|
if ((pdst = calloc((16 * mbslength) + 1, sizeof(*pdst))) == NULL)
|
||||||
|
goto out;
|
||||||
|
if (*mbdstp == NULL) {
|
||||||
|
if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL)
|
||||||
|
goto out;
|
||||||
|
*mbdstp = mdst;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbdst = *mbdstp;
|
||||||
|
dst = pdst;
|
||||||
|
src = psrc;
|
||||||
|
|
||||||
|
if (flags & VIS_NOLOCALE) {
|
||||||
|
/* Do one byte at a time conversion */
|
||||||
|
cerr = 1;
|
||||||
|
} else {
|
||||||
|
/* Use caller's multibyte conversion error flag. */
|
||||||
|
cerr = cerr_ptr ? *cerr_ptr : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input loop.
|
||||||
|
* Handle up to mblength characters (not bytes). We do not
|
||||||
|
* stop at NULs because we may be processing a block of data
|
||||||
|
* that includes NULs.
|
||||||
|
*/
|
||||||
|
while (mbslength > 0) {
|
||||||
|
/* Convert one multibyte character to wchar_t. */
|
||||||
|
if (!cerr)
|
||||||
|
clen = mbtowc(src, mbsrc, MB_LEN_MAX);
|
||||||
|
if (cerr || clen < 0) {
|
||||||
|
/* Conversion error, process as a byte instead. */
|
||||||
|
*src = (wint_t)(u_char)*mbsrc;
|
||||||
|
clen = 1;
|
||||||
|
cerr = 1;
|
||||||
|
}
|
||||||
|
if (clen == 0) {
|
||||||
|
/*
|
||||||
|
* NUL in input gives 0 return value. process
|
||||||
|
* as single NUL byte and keep going.
|
||||||
|
*/
|
||||||
|
clen = 1;
|
||||||
|
}
|
||||||
|
/* Advance buffer character pointer. */
|
||||||
|
src++;
|
||||||
|
/* Advance input pointer by number of bytes read. */
|
||||||
|
mbsrc += clen;
|
||||||
|
/* Decrement input byte count. */
|
||||||
|
mbslength -= clen;
|
||||||
|
}
|
||||||
|
len = src - psrc;
|
||||||
|
src = psrc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In the single character input case, we will have actually
|
||||||
|
* processed two characters, c and nextc. Reset len back to
|
||||||
|
* just a single character.
|
||||||
|
*/
|
||||||
|
if (mblength < len)
|
||||||
|
len = mblength;
|
||||||
|
|
||||||
|
/* Convert extra argument to list of characters for this mode. */
|
||||||
|
extra = makeextralist(flags, mbextra);
|
||||||
|
if (!extra) {
|
||||||
|
if (dlen && *dlen == 0) {
|
||||||
|
errno = ENOSPC;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
*mbdst = '\0'; /* can't create extra, return "" */
|
||||||
|
error = 0;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look up which processing function to call. */
|
||||||
|
f = getvisfun(flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Main processing loop.
|
||||||
|
* Call do_Xvis processing function one character at a time
|
||||||
|
* with next character available for look-ahead.
|
||||||
|
*/
|
||||||
|
for (start = dst; len > 0; len--) {
|
||||||
|
c = *src++;
|
||||||
|
dst = (*f)(dst, c, flags, len >= 1 ? *src : L'\0', extra);
|
||||||
|
if (dst == NULL) {
|
||||||
|
errno = ENOSPC;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminate the string in the buffer. */
|
||||||
|
*dst = L'\0';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output loop.
|
||||||
|
* Convert wchar_t string back to multibyte output string.
|
||||||
|
* If we have hit a multi-byte conversion error on input,
|
||||||
|
* output byte-by-byte here. Else use wctomb().
|
||||||
|
*/
|
||||||
|
len = wcslen(start);
|
||||||
|
maxolen = dlen ? *dlen : (wcslen(start) * MB_LEN_MAX + 1);
|
||||||
|
olen = 0;
|
||||||
|
for (dst = start; len > 0; len--) {
|
||||||
|
if (!cerr)
|
||||||
|
clen = wctomb(mbdst, *dst);
|
||||||
|
if (cerr || clen < 0) {
|
||||||
|
/*
|
||||||
|
* Conversion error, process as a byte(s) instead.
|
||||||
|
* Examine each byte and higher-order bytes for
|
||||||
|
* data. E.g.,
|
||||||
|
* 0x000000000000a264 -> a2 64
|
||||||
|
* 0x000000001f00a264 -> 1f 00 a2 64
|
||||||
|
*/
|
||||||
|
clen = 0;
|
||||||
|
wmsk = 0;
|
||||||
|
for (i = sizeof(wmsk) - 1; i >= 0; i--) {
|
||||||
|
shft = i * NBBY;
|
||||||
|
bmsk = (uint64_t)0xffLL << shft;
|
||||||
|
wmsk |= bmsk;
|
||||||
|
if ((*dst & wmsk) || i == 0)
|
||||||
|
mbdst[clen++] = (char)(
|
||||||
|
(uint64_t)(*dst & bmsk) >>
|
||||||
|
shft);
|
||||||
|
}
|
||||||
|
cerr = 1;
|
||||||
|
}
|
||||||
|
/* If this character would exceed our output limit, stop. */
|
||||||
|
if (olen + clen > (size_t)maxolen)
|
||||||
|
break;
|
||||||
|
/* Advance output pointer by number of bytes written. */
|
||||||
|
mbdst += clen;
|
||||||
|
/* Advance buffer character pointer. */
|
||||||
|
dst++;
|
||||||
|
/* Incrment output character count. */
|
||||||
|
olen += clen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminate the output string. */
|
||||||
|
*mbdst = '\0';
|
||||||
|
|
||||||
|
if (flags & VIS_NOLOCALE) {
|
||||||
|
/* Pass conversion error flag out. */
|
||||||
|
if (cerr_ptr)
|
||||||
|
*cerr_ptr = cerr;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(extra);
|
||||||
|
free(pdst);
|
||||||
|
free(psrc);
|
||||||
|
|
||||||
|
return (int)olen;
|
||||||
|
out:
|
||||||
|
free(extra);
|
||||||
|
free(pdst);
|
||||||
|
free(psrc);
|
||||||
|
free(mdst);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc,
|
||||||
|
int flags, const char *mbextra, int *cerr_ptr)
|
||||||
|
{
|
||||||
|
return istrsenvisx(mbdstp, dlen, mbsrc,
|
||||||
|
mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The "svis" variants all take an "extra" arg that is a pointer
|
||||||
|
* to a NUL-terminated list of characters to be encoded, too.
|
||||||
|
* These functions are useful e. g. to encode strings in such a
|
||||||
|
* way so that they are not interpreted by a shell.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *
|
||||||
|
svis(char *mbdst, int c, int flags, int nextc, const char *mbextra)
|
||||||
|
{
|
||||||
|
char cc[2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
cc[0] = c;
|
||||||
|
cc[1] = nextc;
|
||||||
|
|
||||||
|
ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, mbextra, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
return NULL;
|
||||||
|
return mbdst + ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra)
|
||||||
|
{
|
||||||
|
char cc[2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
cc[0] = c;
|
||||||
|
cc[1] = nextc;
|
||||||
|
|
||||||
|
ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, mbextra, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
return NULL;
|
||||||
|
return mbdst + ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
|
||||||
|
{
|
||||||
|
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
|
||||||
|
{
|
||||||
|
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
|
||||||
|
{
|
||||||
|
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||||
|
const char *mbextra)
|
||||||
|
{
|
||||||
|
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||||
|
const char *mbextra, int *cerr_ptr)
|
||||||
|
{
|
||||||
|
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vis - visually encode characters
|
* vis - visually encode characters
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
vis(char *dst, int c, int flag, int nextc)
|
vis(char *mbdst, int c, int flags, int nextc)
|
||||||
{
|
{
|
||||||
c = (unsigned char)c;
|
char cc[2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (flag & VIS_HTTPSTYLE) {
|
cc[0] = c;
|
||||||
/* Described in RFC 1808 */
|
cc[1] = nextc;
|
||||||
if (!(isalnum(c) /* alpha-numeric */
|
|
||||||
/* safe */
|
|
||||||
|| c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
|
|
||||||
/* extra */
|
|
||||||
|| c == '!' || c == '*' || c == '\'' || c == '('
|
|
||||||
|| c == ')' || c == ',')) {
|
|
||||||
*dst++ = '%';
|
|
||||||
snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c);
|
|
||||||
dst += 2;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flag & VIS_GLOB) &&
|
ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, "", NULL);
|
||||||
(c == '*' || c == '?' || c == '[' || c == '#'))
|
if (ret < 0)
|
||||||
;
|
return NULL;
|
||||||
else if (isgraph(c) ||
|
return mbdst + ret;
|
||||||
((flag & VIS_SP) == 0 && c == ' ') ||
|
}
|
||||||
((flag & VIS_TAB) == 0 && c == '\t') ||
|
|
||||||
((flag & VIS_NL) == 0 && c == '\n') ||
|
|
||||||
((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) {
|
|
||||||
*dst++ = c;
|
|
||||||
if (c == '\\' && (flag & VIS_NOSLASH) == 0)
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst = '\0';
|
|
||||||
return (dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flag & VIS_CSTYLE) {
|
char *
|
||||||
switch(c) {
|
nvis(char *mbdst, size_t dlen, int c, int flags, int nextc)
|
||||||
case '\n':
|
{
|
||||||
*dst++ = '\\';
|
char cc[2];
|
||||||
*dst++ = 'n';
|
int ret;
|
||||||
goto done;
|
|
||||||
case '\r':
|
cc[0] = c;
|
||||||
*dst++ = '\\';
|
cc[1] = nextc;
|
||||||
*dst++ = 'r';
|
|
||||||
goto done;
|
ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, "", NULL);
|
||||||
case '\b':
|
if (ret < 0)
|
||||||
*dst++ = '\\';
|
return NULL;
|
||||||
*dst++ = 'b';
|
return mbdst + ret;
|
||||||
goto done;
|
|
||||||
case '\a':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = 'a';
|
|
||||||
goto done;
|
|
||||||
case '\v':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = 'v';
|
|
||||||
goto done;
|
|
||||||
case '\t':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = 't';
|
|
||||||
goto done;
|
|
||||||
case '\f':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = 'f';
|
|
||||||
goto done;
|
|
||||||
case ' ':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = 's';
|
|
||||||
goto done;
|
|
||||||
case '\0':
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = '0';
|
|
||||||
if (isoctal(nextc)) {
|
|
||||||
*dst++ = '0';
|
|
||||||
*dst++ = '0';
|
|
||||||
}
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
|
|
||||||
*dst++ = '\\';
|
|
||||||
*dst++ = ((unsigned char)c >> 6 & 07) + '0';
|
|
||||||
*dst++ = ((unsigned char)c >> 3 & 07) + '0';
|
|
||||||
*dst++ = ((unsigned char)c & 07) + '0';
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if ((flag & VIS_NOSLASH) == 0)
|
|
||||||
*dst++ = '\\';
|
|
||||||
if (c & 0200) {
|
|
||||||
c &= 0177;
|
|
||||||
*dst++ = 'M';
|
|
||||||
}
|
|
||||||
if (iscntrl(c)) {
|
|
||||||
*dst++ = '^';
|
|
||||||
if (c == 0177)
|
|
||||||
*dst++ = '?';
|
|
||||||
else
|
|
||||||
*dst++ = c + '@';
|
|
||||||
} else {
|
|
||||||
*dst++ = '-';
|
|
||||||
*dst++ = c;
|
|
||||||
}
|
|
||||||
done:
|
|
||||||
*dst = '\0';
|
|
||||||
return (dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* strvis, strnvis, strvisx - visually encode characters from src into dst
|
* strvis - visually encode characters from src into dst
|
||||||
*
|
*
|
||||||
* Dst must be 4 times the size of src to account for possible
|
* Dst must be 4 times the size of src to account for possible
|
||||||
* expansion. The length of dst, not including the trailing NUL,
|
* expansion. The length of dst, not including the trailing NULL,
|
||||||
* is returned.
|
* is returned.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
strvis(char *mbdst, const char *mbsrc, int flags)
|
||||||
|
{
|
||||||
|
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
*
|
*
|
||||||
* Strnvis will write no more than siz-1 bytes (and will NULL terminate).
|
* Provide both implementations and default for now on the historical one to
|
||||||
* The number of bytes needed to fully encode the string is returned.
|
* avoid breakage, we will switch to the NetBSD one in libbsd 0.10.0 or so.
|
||||||
*
|
*
|
||||||
* Strvisx encodes exactly len bytes from src into dst.
|
* OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag);
|
||||||
* This is useful for encoding a block of data.
|
* NetBSD: 2012, strnvis(char *dst, size_t dlen, const char *src, int flag);
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
strvis(char *dst, const char *src, int flag)
|
strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
|
||||||
{
|
{
|
||||||
char c;
|
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||||
char *start;
|
}
|
||||||
|
__asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2");
|
||||||
|
|
||||||
for (start = dst; (c = *src); )
|
int
|
||||||
dst = vis(dst, c, flag, *++src);
|
strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
|
||||||
*dst = '\0';
|
{
|
||||||
return (dst - start);
|
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||||
|
}
|
||||||
|
__asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1");
|
||||||
|
|
||||||
|
int
|
||||||
|
stravis(char **mbdstp, const char *mbsrc, int flags)
|
||||||
|
{
|
||||||
|
*mbdstp = NULL;
|
||||||
|
return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* strvisx - visually encode characters from src into dst
|
||||||
|
*
|
||||||
|
* Dst must be 4 times the size of src to account for possible
|
||||||
|
* expansion. The length of dst, not including the trailing NULL,
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* Strvisx encodes exactly len characters from src into dst.
|
||||||
|
* This is useful for encoding a block of data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
|
||||||
|
{
|
||||||
|
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
strnvis(char *dst, const char *src, size_t siz, int flag)
|
strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
|
||||||
{
|
{
|
||||||
char *start, *end;
|
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL);
|
||||||
char tbuf[5];
|
|
||||||
int c, i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
|
|
||||||
if (isvisible(c)) {
|
|
||||||
i = 1;
|
|
||||||
*dst++ = c;
|
|
||||||
if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
|
|
||||||
/* need space for the extra '\\' */
|
|
||||||
if (dst < end)
|
|
||||||
*dst++ = '\\';
|
|
||||||
else {
|
|
||||||
dst--;
|
|
||||||
i = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
src++;
|
|
||||||
} else {
|
|
||||||
i = vis(tbuf, c, flag, *++src) - tbuf;
|
|
||||||
if (dst + i <= end) {
|
|
||||||
memcpy(dst, tbuf, i);
|
|
||||||
dst += i;
|
|
||||||
} else {
|
|
||||||
src--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (siz > 0)
|
|
||||||
*dst = '\0';
|
|
||||||
if (dst + i > end) {
|
|
||||||
/* adjust return value for truncation */
|
|
||||||
while ((c = *src))
|
|
||||||
dst += vis(tbuf, c, flag, *++src) - tbuf;
|
|
||||||
}
|
|
||||||
return (dst - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
strvisx(char *dst, const char *src, size_t len, int flag)
|
strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||||
|
int *cerr_ptr)
|
||||||
{
|
{
|
||||||
int c;
|
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
|
||||||
char *start;
|
|
||||||
|
|
||||||
for (start = dst; len > 1; len--) {
|
|
||||||
c = *src;
|
|
||||||
dst = vis(dst, c, flag, *++src);
|
|
||||||
}
|
|
||||||
if (len)
|
|
||||||
dst = vis(dst, *src, flag, '\0');
|
|
||||||
*dst = '\0';
|
|
||||||
|
|
||||||
return (dst - start);
|
|
||||||
}
|
}
|
||||||
|
2
test/.gitignore
vendored
2
test/.gitignore
vendored
@@ -19,3 +19,5 @@ setmode
|
|||||||
strl
|
strl
|
||||||
strmode
|
strmode
|
||||||
strnstr
|
strnstr
|
||||||
|
vis
|
||||||
|
vis-openbsd
|
||||||
|
@@ -47,6 +47,8 @@ check_PROGRAMS = \
|
|||||||
strl \
|
strl \
|
||||||
strmode \
|
strmode \
|
||||||
strnstr \
|
strnstr \
|
||||||
|
vis \
|
||||||
|
vis-openbsd \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
if HAVE_LIBTESTU01
|
if HAVE_LIBTESTU01
|
||||||
|
11
test/nlist.c
11
test/nlist.c
@@ -61,7 +61,7 @@ main(int argc, char **argv)
|
|||||||
{ .n_un.n_name = "data_pub_init" },
|
{ .n_un.n_name = "data_pub_init" },
|
||||||
{ .n_un.n_name = "data_prv_init" },
|
{ .n_un.n_name = "data_prv_init" },
|
||||||
{ .n_un.n_name = NULL },
|
{ .n_un.n_name = NULL },
|
||||||
}, *nlp;
|
};
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
assert(*data_pub_ptr == 50);
|
assert(*data_pub_ptr == 50);
|
||||||
@@ -69,8 +69,17 @@ main(int argc, char **argv)
|
|||||||
rc = nlist(argv[0], nl);
|
rc = nlist(argv[0], nl);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
|
|
||||||
|
#if defined(__powerpc64__) && _CALL_ELF == 1
|
||||||
|
/* On PowerPC 64-bit ELFv1, the functions are stored in
|
||||||
|
* the .text sections but they are accessed through a function
|
||||||
|
* descriptor stored in a data section, for example for PowerPC
|
||||||
|
* 64-bit that section is called .opd. */
|
||||||
|
assert(nl[0].n_type == (N_DATA | N_EXT));
|
||||||
|
assert(nl[1].n_type == (N_DATA | N_EXT));
|
||||||
|
#else
|
||||||
assert(nl[0].n_type == (N_TEXT | N_EXT));
|
assert(nl[0].n_type == (N_TEXT | N_EXT));
|
||||||
assert(nl[1].n_type == (N_TEXT | N_EXT));
|
assert(nl[1].n_type == (N_TEXT | N_EXT));
|
||||||
|
#endif
|
||||||
assert(nl[2].n_type == (N_BSS | N_EXT));
|
assert(nl[2].n_type == (N_BSS | N_EXT));
|
||||||
assert(nl[3].n_type == (N_DATA | N_EXT));
|
assert(nl[3].n_type == (N_DATA | N_EXT));
|
||||||
assert(nl[4].n_type == (N_DATA));
|
assert(nl[4].n_type == (N_DATA));
|
||||||
|
@@ -31,7 +31,12 @@
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
assert(strcmp(getprogname(), "progname") == 0);
|
const char *progname;
|
||||||
|
|
||||||
|
progname = getprogname();
|
||||||
|
if (strncmp(progname, "lt-", 3) == 0)
|
||||||
|
progname += 3;
|
||||||
|
assert(strcmp(progname, "progname") == 0);
|
||||||
|
|
||||||
setprogname("program-name");
|
setprogname("program-name");
|
||||||
assert(strcmp(getprogname(), "program-name") == 0);
|
assert(strcmp(getprogname(), "program-name") == 0);
|
||||||
|
47
test/vis-openbsd.c
Normal file
47
test/vis-openbsd.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wcpp"
|
||||||
|
#include <vis.h>
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char str[200];
|
||||||
|
char unstr[200];
|
||||||
|
|
||||||
|
strnvis(str, "0123456789abcdef", 10, 0);
|
||||||
|
assert(strcmp(str, "0123456789") == 0);
|
||||||
|
|
||||||
|
strnunvis(unstr, str, 100);
|
||||||
|
assert(strcmp(unstr, "0123456789") == 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
46
test/vis.c
Normal file
46
test/vis.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LIBBSD_NETBSD_VIS 1
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char str[200];
|
||||||
|
char unstr[200];
|
||||||
|
|
||||||
|
strnvis(str, 10, "0123456789abcdef", 0);
|
||||||
|
assert(strcmp(str, "0123456789") == 0);
|
||||||
|
|
||||||
|
strnunvis(unstr, 100, str);
|
||||||
|
assert(strcmp(unstr, "0123456789") == 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user