Compare commits

...

52 Commits

Author SHA1 Message Date
Guillem Jover
a11c98a6b5 Release libbsd 0.10.0 2019-08-08 17:07:25 +02:00
Guillem Jover
5745ca0362 err: Add err(), warn(), errx() and warnx() familiy of functions
Some systems such as Windows or musl-libc based ones do not have these
BSD extensions. In addition libbsd itself is making use of the warnx()
functions, so we better provide these interfaces in case they are
missing.
2019-08-08 03:47:05 +02:00
Guillem Jover
9628798d7d err: Rewrite warnc() and errc() family functions to be standalone
Do not depend on the system vwarn() and verr() functions to implement
the *c() variants, as the system might actually lack any of the <err.h>
BSD extensions.
2019-08-08 03:47:05 +02:00
Guillem Jover
f34a5f71d9 err: Mark error functions as non-returning with __dead2 2019-08-08 03:47:05 +02:00
Michael Shigorin
72c68868c8 Add e2k support for nlist()
This is a Russian 64-bit LE VLIW architecture named Elbrus
(formerly Elbrus 2000).

[guillem@hadrons.org:
 - Place the entry in alphabetical order. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:05 +02:00
Frank Schaefer
a4323f2b16 Add AArch64 ILP32 support to nlist()
Closes: !7
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Rosen Penev
4997efa59a Add ARC support to nlist()
Closes: !6
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Guillem Jover
96202c6c14 Add a comment to note the ELF entries are sorted alphabetically
This should help people wanting to add new entries.
2019-08-08 03:47:04 +02:00
James Clarke
61d378f5e9 Re-allow direct use of nlist.n_name in <nlist.h>
Commit e8d340de ("Remove a.out support from nlist()") introduced a copy
of the definition of nlist from a.out.h. However, as well as having
n_name inside n_un, on the various BSDs n_name could also be accessed
as a direct member of nlist, and this is made use of by FreeBSD's
usr.bin/netstat/main.c. Thus we should also add the same enclosing
anonymous union.

[guillem@hadrons.org:
 - Add a minimal unit test. ]

Closes: !4
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Guillem Jover
9d917aad37 nlist: Fix out-of-bounds read on strtab
When doing a string comparison for a symbol name from the string table,
we should make sure we do a bounded comparison, otherwise a non-NUL
terminated string might make the code read out-of-bounds.

Warned-by: coverity
2019-08-08 03:22:52 +02:00
Guillem Jover
18662cadfc nlist: Fix unbounded malloc() calls
There are a couple of malloc() calls with unbounded size arguments,
coming from the parsed file. We need to make sure the size is not
larger than the file being parsed, otherwise we might end up with
out of memory conditions.

Reported-by: Daniel Hodson <daniel@elttam.com.au>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
ce53f7c25f nlist: Fix pread() return value check
We should check for partial reads, and not continue in those cases,
as we are not retrying them, otherwise we might end up operating on
uninitialized data.

Reported-by: Daniel Hodson <daniel@elttam.com.au>
Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
24d1f4dd34 nlist: Check whether sh_link is within bounds
The sh_link members should be >= e_shnum, otherwise we might do out of
bounds read accesses on the shdr array.

Reported-by: Daniel Hodson <daniel@elttam.com.au>
Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
e9529d9b4a nlist: Check that e_shnum and e_shentsize are within bounds
The e_shnum must not be 0, otherwise we will do a zero sized allocation
and further processing of the executable will lead to out of bounds
read/write accesses. The e_shentsize must be equal to sizeof(Elf_Shdr),
otherwise we will perform out of bounds read accesses on the shdr array.

Reported-by: Daniel Hodson <daniel@elttam.com.au>
Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
3aaedb1208 nlist: Check whether the nl argument is not NULL
This prevents programming errors.

Reported-by: Daniel Hodson <daniel@elttam.com.au>
Based-on-patch-by: Daniel Hodson <daniel@elttam.com.au>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
2c754f435b man: Add man page sections to function references
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Sebastian
ee4d24970a man: Fix typo
Closes: !5
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
8d2afa3a9f man: Fix typos
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
e9f6faf3aa man: Replace references to a.out(5) with elf(5)
The a.out(5) support in nlist(3) got removed some time ago, and
there is now only elf(5) support.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
99320b9168 man: Define doc-operating-system-NetBSD string variables
This way we do not depend on the installed groff being new enough.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
71c710e9a8 man: Use major.minor version for .Nx macros
The macro only recognizes this version form, and not just major alone.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
21f4052c5b man: Add doc-str-Lb-libbsd aliases for str-Lb-libbsd
groff(1) has changed the internal layout for the .Lb doc strings, but to
preserve backwards compatibility we cannot simply rename them, we need
to create new aliases so that these will work with old and new macros.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
1899e2c5ab Update TODO
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Aaron Dierking
4803340802 Provide a <sys/param.h> with MIN() and MAX()
Windows doesn't provide <sys/param.h>. Several libbsd sources require it
for MIN(), and these are useful non-system-specific macros anyway.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Aaron Dierking
f99b8ea527 build: Disable CRT warnings on Windows
These warnings are not helpful for libbsd.

[guillem@hadrons.org:
 - Rename WINDOWS conditional to OS_WINDOWS.
 - Add a nil terminator to the AM_CPPFLAGS. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Aaron Dierking
4bed48398f build: Detect Windows/MinGW at configure time
Extend the host OS checks to define an OS_WINDOWS automake conditional if
the host is MinGW-like. This will be useful for future Windows-specific
build tweaks.

[guillem@hadrons.org:
 - Rename WINDOWS conditional to OS_WINDOWS. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
2e071c3cc1 build: Support platforms without symbol versioning
The .symver directive is ELF-specific. On non-ELF platforms, work around
this with __attribute__((__alias__)) for the default symbol, and ignore
the variant versioned symbols.

Based-on-patch-by: Aaron Dierking <aarond@fb.com>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:22:09 +02:00
Guillem Jover
890699a78b build: Abstract symbol versioning via new libbsd_symver_* macros
This makes it more obvious what they are doing. It will make it easier
to make these directives more portable, as they are really ELF specific.
2019-08-08 03:22:09 +02:00
Guillem Jover
b0ebb0d4c2 build: Use __register_atfork() only if really available
This is a glibc-specific symbol that has no public declaration. But is
being used by the OpenBSD and this implementation as a hack to avoid
having to link against the pthread library. This interface is at least
included in LSB 5.0 [L], and using pthread_atfork() is otherwise
problematic anyway [P].

 [L] <https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---register-atfork.html>
 [P] <http://austingroupbugs.net/view.php?id=851>

One problem is that we were using it whenever __GLIBC__ is defined,
which is supposed to be defined only on an actual glibc, but uClibc
defines that macro, but it does not provide the symbol on its noMMU
variant.

We add a new configure check that will try to link a program that uses
that symbol to make sure it is present.

Closes: !2
Reported-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2019-08-08 03:21:49 +02:00
Guillem Jover
73aea4f808 build: Fix check for clock_gettime() within librt
The check was always setting the libraries to link to include -lrt,
as the success case includes the builtin one. Handle the various
values.
2019-08-07 00:03:25 +02:00
Aaron Dierking
7cfa2d4530 Correct Clang feature detection
Clang's __GNUC__ and __GNUC_MINOR__ definitions are not reliable and may
not be defined at all when targeting the MSVC ABI. Use feature-checking
macros when possible or check for __clang__.

[guillem@hadrons.org: Update for __ protected keyword change. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Guillem Jover
574c7a1365 Protect C language extensions with two leading and trailing underscores
This should make their usage safer against user macros.
2018-06-18 04:31:00 +02:00
Aaron Dierking
c2d9d84088 Guard non-portable forwarded includes
These headers are not available on Windows. <bsd/sys/cdefs.h> ensures
that __has_include() and __has_include_next() are defined.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
2ebe6d5a02 Windows support for inet_net_pton()
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
aeea1f4083 Windows support for HASHFileChunk()
<io.h> provides the necessary file I/O functions.

[guillem@hadrons.org: Move include before <hashinc>. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
0500a1bd08 Don't require <grp.h>
This is only used in the overlay test and Windows does not provide it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
3d9c6c08ed Only define S_ISTXT if S_ISVTX is defined
Windows doesn't provide S_ISVTX. Prefer not defining it rather than
defining it to something invalid.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
b9dee9f69a Use CHAR_BIT instead of NBBY in strnvis()
<sys/param.h> is not available on Windows.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Aaron Dierking
81c3c3e405 Replace reintroduced legacy u_* type usage in strnvis() and strnunvis()
This fixes a regression caused by 2d7de18. These types are not available
on all systems.

Fixes: commit 2d7de186e9
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:28:45 +02:00
Guillem Jover
5e0998fa4f Remove dead code in vis
The loop only executes while len > 0, and the trinary operator in the
function argument is checking against len >= 1 which will always be
true.

Warned-by: coverity
2018-06-17 23:01:02 +02:00
Guillem Jover
8e2d55047c Fix vis family of functions to not leak
The code uses an internal helper function to avoid code repetition. But
to get there, the function takes a pointer to a pointer, so that the few
functions that require returning an allocated buffer can get hold of it
this way.

The problem is that the user might pass a NULL pointer and trigger an
internal allocation even if the functions are not expected to do so.

Add a new internal helper for non-allocations, that will assert that
condition, and make any other function that requires this behavior call
this one instead.

Warned-by: coverity
2018-06-17 23:00:52 +02:00
Baruch Siach
13c32916b4 flopen: Add missing <fcntl.h> include
Commit 993828d84e (Add flopenat() function from FreeBSD) dropped the
fcntl.h header. This breaks the build with musl libc:

flopen.c: In function ‘vflopenat’:
flopen.c:60:14: error: ‘O_CREAT’ undeclared (first use in this function)
  if (flags & O_CREAT) {
              ^~~~~~~

Restore the fcntl.h header include to fix the build.

Fixes: commit 993828d84e
Submitted-also-by: parazyd <parazyd@dyne.org>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-17 20:23:48 +02:00
Guillem Jover
8e834cd068 build: Simplify gitlab CI configuration
Merge all stages so that we do not need to pass artifacts around.
Quiesce «apt install».
2018-05-31 04:00:26 +02:00
Guillem Jover
e354f9b1d0 build: Install git in gitlab CI configuration 2018-05-31 03:46:14 +02:00
Guillem Jover
4c5e9b478e build: Fix gitlab CI configuration
Run «apt install» in non-interactive mode, and do not install
Recommends. Replace build-essential, which is rather fat, with gcc
and make. Execute autogen instead of autoreconf directly.
2018-05-31 03:42:33 +02:00
Guillem Jover
005b509061 build: Add a gitlab CI configuration file 2018-05-31 03:23:16 +02:00
Jakub Wilk
a8531ad051 man: Fix comma splice
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-05-23 02:58:09 +02:00
Jakub Wilk
c4b0fd2c9f man: Fix name of the function injected by libbsd-ctor
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-05-23 02:58:09 +02:00
Guillem Jover
1ca09c18f7 Release libbsd 0.9.1 2018-05-22 16:07:42 +02:00
Guillem Jover
e4e15ed286 Fix strnvis() and strnunvis() NetBSD ABI break
The NetBSD implementations have different prototypes to the ones coming
from OpenBSD, which will break builds, and have caused segfaults at
run-time. We provide now both interfaces with different prototypes as
different version nodes allow selecting them at compile-time, defaulting
for now to the OpenBSD one to avoid build-time breakage, while emitting
a compile-time warning. Later on, in 0.10.0, we will be switching the
compile-time default to the NetBSD version.

Ref: http://gnats.netbsd.org/44977
Fixes: https://bugs.debian.org/899282
2018-05-22 16:07:42 +02:00
Guillem Jover
bf697b900c Add symbol redirection support
We need this to be able to select different version symbols at
compile-time.
2018-05-22 15:45:37 +02:00
Guillem Jover
f1966385b3 Fix COPYING file format
We cannot refer to a License short-name if that is not on its own
License paragraph. Split several other common License fields into
their own paragraphs to avoid this problem in the future.
2018-05-22 13:47:05 +02:00
76 changed files with 796 additions and 220 deletions

9
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,9 @@
image: debian:stretch
test:
before_script:
- apt update -qq
- apt install -qq -y --no-install-recommends git gcc make autoconf automake libtool
script:
- ./autogen && ./configure
- make check

202
COPYING
View File

@@ -74,16 +74,18 @@ License: BSD-4-clause-Christopher-G-Demetriou
Files: Files:
include/bsd/err.h include/bsd/err.h
include/bsd/stdlib.h include/bsd/stdlib.h
include/bsd/sys/param.h
include/bsd/unistd.h include/bsd/unistd.h
src/bsd_getopt.c src/bsd_getopt.c
src/err.c src/err.c
src/fgetln.c src/fgetln.c
src/progname.c src/progname.c
Copyright: Copyright:
Copyright © 2005, 2008-2012 Guillem Jover <guillem@hadrons.org> Copyright © 2005, 2008-2012, 2019 Guillem Jover <guillem@hadrons.org>
Copyright © 2005 Hector Garcia Alvarez Copyright © 2005 Hector Garcia Alvarez
Copyright © 2005 Aurelien Jarno Copyright © 2005 Aurelien Jarno
Copyright © 2006 Robert Millan Copyright © 2006 Robert Millan
Copyright © 2018 Facebook, Inc.
License: BSD-3-clause License: BSD-3-clause
Files: Files:
@@ -156,29 +158,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
@@ -187,30 +176,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
@@ -299,36 +265,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:
src/vis.c
Copyright:
Copyright © 1989, 1993
The Regents of the University of California. All rights reserved.
.
Copyright © 1999, 2005 The NetBSD Foundation, Inc.
All rights reserved.
License: BSD-3-clause-Regents and BSD-2-clause-NetBSD
Files: Files:
include/bsd/sys/endian.h include/bsd/sys/endian.h
@@ -419,25 +355,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
@@ -567,6 +484,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
@@ -590,6 +557,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

2
TODO
View File

@@ -1,3 +1,4 @@
* Migrate portable functions from GNU/kFreeBSD's libfreebsd.
* Add more functions used by ported packages (check openssh). * Add more functions used by ported packages (check openssh).
* Add more unit tests. * Add more unit tests.
* Add missing man pages. * Add missing man pages.
@@ -5,7 +6,6 @@
- timeconv? - timeconv?
* Add a README.import file. * Add a README.import file.
* Update man pages: * Update man pages:
- Fix references to a.out(5) and inline needed struct definitions.
- Document when each interface was added on every BSD, and libbsd. - Document when each interface was added on every BSD, and libbsd.
* Handle LFS properly. By default the library emits LFS objects, but might * Handle LFS properly. By default the library emits LFS objects, but might
be used by non-LFS objects. We should either provide foo and foo64 be used by non-LFS objects. We should either provide foo and foo64

View File

@@ -12,7 +12,7 @@ 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=9 LIBBSD_ABI_MINOR=10
LIBBSD_ABI_PATCH=0 LIBBSD_ABI_PATCH=0
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH" LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
@@ -44,11 +44,16 @@ AC_SUBST([TESTU01_LIBS])
AM_CONDITIONAL([HAVE_LIBTESTU01], AM_CONDITIONAL([HAVE_LIBTESTU01],
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"]) [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
is_windows=no
AS_CASE([$host_os], AS_CASE([$host_os],
[*-gnu*], [ [*-gnu*], [
# In old glibc versions (< 2.17) clock_gettime() is in librt. # In old glibc versions (< 2.17) clock_gettime() is in librt.
saved_LIBS="$LIBS" saved_LIBS="$LIBS"
AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"]) AC_SEARCH_LIBS([clock_gettime], [rt], [
AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
])
])
AC_SUBST([CLOCK_GETTIME_LIBS]) AC_SUBST([CLOCK_GETTIME_LIBS])
LIBS="$saved_LIBS" LIBS="$saved_LIBS"
], ],
@@ -56,10 +61,14 @@ AS_CASE([$host_os],
# Upstream refuses to define this, we will do it ourselves then. # Upstream refuses to define this, we will do it ourselves then.
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl]) AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
], ],
[mingw*], [
is_windows=yes
],
) )
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h]) AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE AC_C_INLINE
@@ -87,7 +96,7 @@ AC_CACHE_CHECK(
[[ [[
static int rc = 1; static int rc = 1;
static void init(int argc) { if (argc == 1) rc = 0; } static void init(int argc) { if (argc == 1) rc = 0; }
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init; void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
int main() { return rc; } int main() { return rc; }
]] ]]
)], )],
@@ -141,6 +150,23 @@ AC_LINK_IFELSE(
AC_MSG_RESULT([yes])], AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])]) [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([for __register_atfork])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#include <stddef.h>
extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
]], [[
__register_atfork(NULL, NULL, NULL, __dso_handle);
]])],
[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
[Define to 1 if you have __register_atfork])
AC_MSG_RESULT([yes])],
[ARC4RANDOM_ATFORK_LIBS="-pthread"
AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
AC_MSG_RESULT([no])
])
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
getauxval getentropy getexecname getline \ getauxval getentropy getexecname getline \
pstat_getproc sysconf]) pstat_getproc sysconf])

View File

@@ -4,6 +4,7 @@ nobase_include_HEADERS = \
bsd/sys/bitstring.h \ bsd/sys/bitstring.h \
bsd/sys/cdefs.h \ bsd/sys/cdefs.h \
bsd/sys/endian.h \ bsd/sys/endian.h \
bsd/sys/param.h \
bsd/sys/poll.h \ bsd/sys/poll.h \
bsd/sys/queue.h \ bsd/sys/queue.h \
bsd/sys/time.h \ bsd/sys/time.h \

View File

@@ -26,31 +26,56 @@
*/ */
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<err.h>)
#include_next <err.h> #include_next <err.h>
#else #else
#define LIBBSD_NEED_ERR_H_FUNCS
#endif
#else
#include <bsd/sys/cdefs.h>
#if __has_include(<err.h>)
#include <err.h> #include <err.h>
#else
#define LIBBSD_NEED_ERR_H_FUNCS
#endif
#endif #endif
#ifndef LIBBSD_ERR_H #ifndef LIBBSD_ERR_H
#define LIBBSD_ERR_H #define LIBBSD_ERR_H
#ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#else
#include <bsd/sys/cdefs.h>
#endif
#include <stdarg.h> #include <stdarg.h>
__BEGIN_DECLS __BEGIN_DECLS
void warnc(int code, const char *format, ...)
__printflike(2, 3);
void vwarnc(int code, const char *format, va_list ap) void vwarnc(int code, const char *format, va_list ap)
__printflike(2, 0); __printflike(2, 0);
void errc(int status, int code, const char *format, ...) void warnc(int code, const char *format, ...)
__printflike(3, 4); __printflike(2, 3);
void verrc(int status, int code, const char *format, va_list ap) void verrc(int status, int code, const char *format, va_list ap)
__printflike(3, 0); __printflike(3, 0) __dead2;
void errc(int status, int code, const char *format, ...)
__printflike(3, 4) __dead2;
#ifdef LIBBSD_NEED_ERR_H_FUNCS
void vwarn(const char *format, va_list ap)
__printflike(1, 0);
void vwarnx(const char *format, va_list ap)
__printflike(1, 0);
void warn(const char *format, ...)
__printflike(1, 2);
void warnx(const char *format, ...)
__printflike(1, 2);
void verr(int status, const char *format, va_list ap)
__printflike(2, 0) __dead2;
void verrx(int status, const char *format, va_list ap)
__printflike(2, 0) __dead2;
void err(int status, const char *format, ...)
__printflike(2, 3) __dead2;
void errx(int status, const char *format, ...)
__printflike(2, 3) __dead2;
#endif
__END_DECLS __END_DECLS
#endif #endif

View File

@@ -25,9 +25,15 @@
*/ */
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<getopt.h>)
#include_next <getopt.h> #include_next <getopt.h>
#endif
#include <unistd.h> #include <unistd.h>
#else #else
#include <bsd/sys/cdefs.h>
#if __has_include(<getopt.h>)
#include <getopt.h> #include <getopt.h>
#endif
#include <bsd/unistd.h> #include <bsd/unistd.h>
#endif #endif

View File

@@ -34,11 +34,14 @@
#endif #endif
struct nlist { struct nlist {
union {
char *n_name;
union { union {
char *n_name; char *n_name;
struct n_list *n_next; struct n_list *n_next;
long n_strx; long n_strx;
} n_un; } n_un;
};
unsigned char n_type; unsigned char n_type;
char n_other; char n_other;
short n_desc; short n_desc;

View File

@@ -30,6 +30,13 @@
#ifndef __has_include_next #ifndef __has_include_next
#define __has_include_next(x) 1 #define __has_include_next(x) 1
#endif #endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
/* Clang expands this to 1 if an identifier is *not* reserved. */
#ifndef __is_identifier
#define __is_identifier(x) 1
#endif
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
/* /*
@@ -76,22 +83,31 @@
#define _SYS_CDEFS_H #define _SYS_CDEFS_H
#endif #endif
#define LIBBSD_CONCAT(x, y) x ## y
#define LIBBSD_STRING(x) #x
#ifdef __GNUC__ #ifdef __GNUC__
#define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__) #define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
#else #else
#define LIBBSD_GCC_VERSION 0 #define LIBBSD_GCC_VERSION 0
#endif #endif
#if LIBBSD_GCC_VERSION >= 0x0405 #if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x))) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
#elif LIBBSD_GCC_VERSION >= 0x0301 #elif LIBBSD_GCC_VERSION >= 0x0301
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated)) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
#else #else
#define LIBBSD_DEPRECATED(x) #define LIBBSD_DEPRECATED(x)
#endif #endif
#if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
#define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
#endif
#define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
#define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
#ifndef __dead2 #ifndef __dead2
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
# define __dead2 __attribute__((__noreturn__)) # define __dead2 __attribute__((__noreturn__))
# else # else
# define __dead2 # define __dead2
@@ -99,7 +115,7 @@
#endif #endif
#ifndef __pure2 #ifndef __pure2
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
# define __pure2 __attribute__((__const__)) # define __pure2 __attribute__((__const__))
# else # else
# define __pure2 # define __pure2
@@ -107,7 +123,7 @@
#endif #endif
#ifndef __packed #ifndef __packed
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
# define __packed __attribute__((__packed__)) # define __packed __attribute__((__packed__))
# else # else
# define __packed # define __packed
@@ -115,7 +131,7 @@
#endif #endif
#ifndef __aligned #ifndef __aligned
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
# define __aligned(x) __attribute__((__aligned__(x))) # define __aligned(x) __attribute__((__aligned__(x)))
# else # else
# define __aligned(x) # define __aligned(x)
@@ -128,7 +144,7 @@
#if 0 #if 0
#ifndef __unused #ifndef __unused
# if LIBBSD_GCC_VERSION >= 0x0300 # if LIBBSD_GCC_VERSION >= 0x0300
# define __unused __attribute__((unused)) # define __unused __attribute__((__unused__))
# else # else
# define __unused # define __unused
# endif # endif
@@ -136,15 +152,15 @@
#endif #endif
#ifndef __printflike #ifndef __printflike
# if LIBBSD_GCC_VERSION >= 0x0300 # if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
# define __printflike(x, y) __attribute((format(printf, (x), (y)))) # define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
# else # else
# define __printflike(x, y) # define __printflike(x, y)
# endif # endif
#endif #endif
#ifndef __nonnull #ifndef __nonnull
# if LIBBSD_GCC_VERSION >= 0x0302 # if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
# define __nonnull(x) __attribute__((__nonnull__(x))) # define __nonnull(x) __attribute__((__nonnull__(x)))
# else # else
# define __nonnull(x) # define __nonnull(x)
@@ -166,7 +182,7 @@
* require it. * require it.
*/ */
#ifndef __offsetof #ifndef __offsetof
# if LIBBSD_GCC_VERSION >= 0x0401 # if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
# define __offsetof(type, field) __builtin_offsetof(type, field) # define __offsetof(type, field) __builtin_offsetof(type, field)
# else # else
# ifndef __cplusplus # ifndef __cplusplus
@@ -191,9 +207,9 @@
* compatible with member m. * compatible with member m.
*/ */
#ifndef __containerof #ifndef __containerof
# if LIBBSD_GCC_VERSION >= 0x0301 # if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
# define __containerof(x, s, m) ({ \ # define __containerof(x, s, m) ({ \
const volatile __typeof(((s *)0)->m) *__x = (x); \ const volatile __typeof__(((s *)0)->m) *__x = (x); \
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \ __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
}) })
# else # else

View File

@@ -27,10 +27,16 @@
*/ */
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<endian.h>)
#include_next <endian.h> #include_next <endian.h>
#endif
#else #else
#include <bsd/sys/cdefs.h>
#if __has_include(<endian.h>)
#include <endian.h> #include <endian.h>
#endif #endif
#endif
#ifndef LIBBSD_SYS_ENDIAN_H #ifndef LIBBSD_SYS_ENDIAN_H
#define LIBBSD_SYS_ENDIAN_H #define LIBBSD_SYS_ENDIAN_H

49
include/bsd/sys/param.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* Copyright © 2018 Facebook, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<sys/param.h>)
#include_next <sys/param.h>
#endif
#else
#include <bsd/sys/cdefs.h>
#if __has_include(<sys/param.h>)
#include <sys/param.h>
#endif
#endif
#ifndef LIBBSD_SYS_PARAM_H
#define LIBBSD_SYS_PARAM_H
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#endif

View File

@@ -33,10 +33,16 @@
*/ */
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<sys/time.h>)
#include_next <sys/time.h> #include_next <sys/time.h>
#endif
#else #else
#include <bsd/sys/cdefs.h>
#if __has_include(<sys/time.h>)
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#endif
#ifndef LIBBSD_SYS_TIME_H #ifndef LIBBSD_SYS_TIME_H
#define LIBBSD_SYS_TIME_H #define LIBBSD_SYS_TIME_H

View File

@@ -26,22 +26,23 @@
*/ */
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#if __has_include_next(<unistd.h>)
#include_next <unistd.h> #include_next <unistd.h>
#endif
#else #else
#include <bsd/sys/cdefs.h>
#if __has_include(<unistd.h>)
#include <unistd.h> #include <unistd.h>
#endif #endif
#endif
#ifndef LIBBSD_UNISTD_H #ifndef LIBBSD_UNISTD_H
#define LIBBSD_UNISTD_H #define LIBBSD_UNISTD_H
#ifdef LIBBSD_OVERLAY
#include <sys/cdefs.h>
#else
#include <bsd/sys/cdefs.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#ifndef S_ISTXT #if !defined(S_ISTXT) && defined(S_ISVTX)
#define S_ISTXT S_ISVTX #define S_ISTXT S_ISVTX
#endif #endif

View File

@@ -88,6 +88,22 @@
#include <bsd/sys/cdefs.h> #include <bsd/sys/cdefs.h>
#endif #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 *nvis(char *, size_t, int, int, int);
@@ -97,7 +113,14 @@ char *snvis(char *, size_t, int, int, int, const char *);
int strvis(char *, const char *, int); int strvis(char *, const char *, int);
int stravis(char **, const char *, int); int stravis(char **, const char *, int);
int strnvis(char *, size_t, 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);
#endif
int strsvis(char *, const char *, int, const char *); int strsvis(char *, const char *, int, const char *);
int strsnvis(char *, size_t, const char *, int, const char *); int strsnvis(char *, size_t, const char *, int, const char *);
@@ -112,7 +135,14 @@ int strsenvisx(char *, size_t, const char *, size_t , int, const char *,
int *); int *);
int strunvis(char *, const char *); int strunvis(char *, const char *);
int strnunvis(char *, size_t, 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);
int strnunvisx(char *, size_t, const char *, int); int strnunvisx(char *, size_t, const char *, int);

View File

@@ -42,6 +42,7 @@
.Nd arc4 random number generator .Nd arc4 random number generator
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -33,6 +33,7 @@
.Nd delete open file descriptors .Nd delete open file descriptors
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In unistd.h .In unistd.h

View File

@@ -38,6 +38,7 @@
.Nd formatted error messages .Nd formatted error messages
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In err.h .In err.h
@@ -144,6 +145,7 @@ if ((fd = open(block_device, O_RDONLY, 0)) == -1)
.Xr printf 3 , .Xr printf 3 ,
.Xr strerror 3 .Xr strerror 3
.Sh HISTORY .Sh HISTORY
.ds doc-operating-system-NetBSD-7.0 7.0
The functions The functions
.Fn errc , .Fn errc ,
.Fn verrc , .Fn verrc ,

View File

@@ -33,6 +33,7 @@
.Nd format a number from human readable form .Nd format a number from human readable form
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In libutil.h .In libutil.h

View File

@@ -37,6 +37,7 @@
.Nd write zeroes to a byte string .Nd write zeroes to a byte string
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In string.h .In string.h

View File

@@ -36,6 +36,7 @@
.Nd get a line from a stream .Nd get a line from a stream
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -36,6 +36,7 @@
.Nd get a line of wide characters from a stream .Nd get a line of wide characters from a stream
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -34,6 +34,7 @@
.Nd "Reliably open and lock a file" .Nd "Reliably open and lock a file"
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/fcntl.h .In sys/fcntl.h

View File

@@ -34,6 +34,7 @@
.Nd sanitizes user-supplied printf(3)-style format string .Nd sanitizes user-supplied printf(3)-style format string
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -30,6 +30,7 @@
.Nd return the next logical line from a stream .Nd return the next logical line from a stream
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -39,6 +39,7 @@
.Nd flush a stream .Nd flush a stream
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -40,6 +40,7 @@
.Nd open a stream .Nd open a stream
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdio.h .In stdio.h

View File

@@ -36,6 +36,7 @@
.Nd get preferred block size .Nd get preferred block size
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -33,6 +33,7 @@
.Nd get the effective credentials of a UNIX-domain peer .Nd get the effective credentials of a UNIX-domain peer
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h

View File

@@ -40,6 +40,7 @@
.Nd get or set the program name .Nd get or set the program name
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -40,6 +40,7 @@
.Nd sort functions .Nd sort functions
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -36,6 +36,7 @@
.Nd format a number into a human readable form and viceversa .Nd format a number into a human readable form and viceversa
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -1,6 +1,6 @@
.\" libbsd man page .\" libbsd man page
.\" .\"
.\" Copyright © 2017-2018 Gullem Jover <guillem@hadrons.org> .\" Copyright © 2017-2018 Guillem Jover <guillem@hadrons.org>
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" modification, are permitted provided that the following conditions
@@ -24,7 +24,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd May 21 2018 .Dd May 21, 2018
.Dt LIBBSD 7 .Dt LIBBSD 7
.Os .Os
.Sh NAME .Sh NAME
@@ -33,7 +33,7 @@
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm libbsd .Nm libbsd
library provides a set if compatibility macros and functions commonly found library provides a set of compatibility macros and functions commonly found
on BSD-based systems. on BSD-based systems.
Its purpose is to make those available on non-BSD based systems to ease Its purpose is to make those available on non-BSD based systems to ease
portability. portability.
@@ -76,7 +76,7 @@ The package also provides a
.Pa bsd-ctor .Pa bsd-ctor
static library that can be used to inject automatic constructors into a static library that can be used to inject automatic constructors into a
program so that the program so that the
.Fn setproctitle .Fn setproctitle_init 3
function gets invoked automatically at startup time. function gets invoked automatically at startup time.
This can be done with the This can be done with the
.Xr pkg-config 3 .Xr pkg-config 3
@@ -134,7 +134,7 @@ or non-buggy way; or because there are better more portable replacements now.
.Pp .Pp
This is the list of currently deprecated macros and functions: This is the list of currently deprecated macros and functions:
.Bl -tag -width 4m .Bl -tag -width 4m
.It Fn fgetln .It Fn fgetln 3
Unportable, requires assistance from the stdio layer. Unportable, requires assistance from the stdio layer.
An implementation has to choose between leaking buffers or being reentrant An implementation has to choose between leaking buffers or being reentrant
for a limited amount of streams (this implementation chose the latter with for a limited amount of streams (this implementation chose the latter with
@@ -143,7 +143,7 @@ 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 .It Fn fgetwln 3
Unportable, requires assistance from the stdio layer. Unportable, requires assistance from the stdio layer.
An implementation has to choose between leaking buffers or being reentrant An implementation has to choose between leaking buffers or being reentrant
for a limited amount of streams (this implementation chose the latter with for a limited amount of streams (this implementation chose the latter with
@@ -154,10 +154,10 @@ instead, which is available in many systems and required by
.St -isoC-99 .St -isoC-99
and and
.St -p1003.1-2001 . .St -p1003.1-2001 .
.It Fn funopen .It Fn funopen 3
Unportable, requires assistance from the stdio layer or some hook framework. Unportable, requires assistance from the stdio layer or some hook framework.
On GNU systems the On GNU systems the
.Fn fopencookie .Fn fopencookie 3
function can be used. function can be used.
Otherwise the code needs to be prepared for neither of these functions being Otherwise the code needs to be prepared for neither of these functions being
available. available.
@@ -171,23 +171,23 @@ are present in all major
for example. for example.
.Pp .Pp
.Bl -tag -width 4m -compact .Bl -tag -width 4m -compact
.It Fn MD5Init .It Fn MD5Init 3
.It Fn MD5Update .It Fn MD5Update 3
.It Fn MD5Pad .It Fn MD5Pad 3
.It Fn MD5Final .It Fn MD5Final 3
.It Fn MD5Transform .It Fn MD5Transform 3
.It Fn MD5End .It Fn MD5End 3
.It Fn MD5File .It Fn MD5File 3
.It Fn MD5FileChunk .It Fn MD5FileChunk 3
.It Fn MD5Data .It Fn MD5Data 3
The set of MD5 digest functions are now provided by the 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. companion library, so it is advised to use that instead.
.It Fn explicit_bzero .It Fn explicit_bzero 3
This function is provided by This function is provided by
.Nm glibc .Nm glibc
2.25. 2.25.
.It Fn reallocarray .It Fn reallocarray 3
This function is provided by This function is provided by
.Nm glibc .Nm glibc
2.26. 2.26.

View File

@@ -25,6 +25,7 @@
.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h

View File

@@ -36,6 +36,7 @@
.Nd retrieve symbol table name list from an executable file .Nd retrieve symbol table name list from an executable file
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In nlist.h .In nlist.h
@@ -50,7 +51,7 @@ The
function function
retrieves name list entries from the symbol table of an retrieves name list entries from the symbol table of an
executable file (see executable file (see
.Xr a.out 5 ) . .Xr elf 5 ) .
The argument The argument
.Fa \&nl .Fa \&nl
is set to reference the is set to reference the
@@ -71,9 +72,12 @@ The last entry in the list is always
The number of invalid entries is returned if successful; otherwise, The number of invalid entries is returned if successful; otherwise,
if the file if the file
.Fa filename .Fa filename
does not exist or is not executable, the returned value is \-1. does not exist or is not executable,
or the nl pointer is
.Dv NULL ,
the returned value is \-1.
.Sh SEE ALSO .Sh SEE ALSO
.Xr a.out 5 .Xr elf 5
.Sh HISTORY .Sh HISTORY
A A
.Fn nlist .Fn nlist

View File

@@ -36,6 +36,7 @@
.Nd "library for PID files handling" .Nd "library for PID files handling"
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In libutil.h .In libutil.h

View File

@@ -38,6 +38,7 @@
.Nd radix sort .Nd radix sort
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In limits.h .In limits.h

View File

@@ -26,6 +26,7 @@
.Nd get a passphrase from the user .Nd get a passphrase from the user
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In readpassphrase.h .In readpassphrase.h

View File

@@ -40,6 +40,7 @@
.Nd memory allocation and deallocation .Nd memory allocation and deallocation
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -40,6 +40,7 @@
.Nd general purpose memory allocation functions .Nd general purpose memory allocation functions
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stdlib.h .In stdlib.h

View File

@@ -39,6 +39,7 @@
.Nd modify mode bits .Nd modify mode bits
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In unistd.h .In unistd.h

View File

@@ -28,6 +28,7 @@
.Nd set process title .Nd set process title
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
@@ -118,7 +119,7 @@ similar functions.
.Pp .Pp
The The
.Fn setproctitle_init .Fn setproctitle_init
function is a libbsd extension not present on the BSDs, avoid using it function is a libbsd extension not present on the BSDs; avoid using it
in portable code. in portable code.
.Sh AUTHORS .Sh AUTHORS
.An -nosplit .An -nosplit

View File

@@ -39,6 +39,7 @@
.Nd stringlist manipulation functions .Nd stringlist manipulation functions
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In stringlist.h .In stringlist.h

View File

@@ -23,6 +23,7 @@
.Nd size-bounded string copying and concatenation .Nd size-bounded string copying and concatenation
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In string.h .In string.h

View File

@@ -36,6 +36,7 @@
.Nd convert inode status information into a symbolic string .Nd convert inode status information into a symbolic string
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In string.h .In string.h

View File

@@ -41,6 +41,7 @@
.Nd locate a substring in a string .Nd locate a substring in a string
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In string.h .In string.h

View File

@@ -44,6 +44,7 @@
.Nd convert string value to an intmax_t integer .Nd convert string value to an intmax_t integer
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In inttypes.h .In inttypes.h
@@ -225,10 +226,11 @@ function is a
.Nx .Nx
extension. extension.
.Sh HISTORY .Sh HISTORY
.ds doc-operating-system-NetBSD-7.0 7.0
The The
.Fn strtoi .Fn strtoi
function first appeared in function first appeared in
.Nx 7 . .Nx 7.0 .
.Ox .Ox
introduced the introduced the
.Fn strtonum 3bsd .Fn strtonum 3bsd

View File

@@ -23,6 +23,7 @@
.Nd reliably convert string value to an integer .Nd reliably convert string value to an integer
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In limits.h .In limits.h
@@ -144,13 +145,14 @@ is an
.Ox .Ox
extension. extension.
.Sh HISTORY .Sh HISTORY
.ds doc-operating-system-NetBSD-8.0 8.0
The The
.Fn strtonum .Fn strtonum
function first appeared in function first appeared in
.Ox 3.6 . .Ox 3.6 .
.Fn strtonum .Fn strtonum
was redesigned in was redesigned in
.Nx 8 .Nx 8.0
as as
.Fn strtoi 3bsd .Fn strtoi 3bsd
and and

View File

@@ -44,6 +44,7 @@
.Nd convert a string to an uintmax_t integer .Nd convert a string to an uintmax_t integer
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In inttypes.h .In inttypes.h
@@ -219,6 +220,7 @@ the range given was invalid, i.e.
.Xr strtoull 3 , .Xr strtoull 3 ,
.Xr strtoumax 3 .Xr strtoumax 3
.Sh STANDARDS .Sh STANDARDS
.ds doc-operating-system-NetBSD-7.0 7.0
The The
.Fn strtou .Fn strtou
function is a function is a
@@ -228,7 +230,7 @@ extension.
The The
.Fn strtou .Fn strtou
function first appeared in function first appeared in
.Nx 7 . .Nx 7.0 .
.Ox .Ox
introduced the introduced the
.Fn strtonum 3bsd .Fn strtonum 3bsd

View File

@@ -47,6 +47,7 @@
.Nd operations on time structure .Nd operations on time structure
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/time.h .In sys/time.h

View File

@@ -36,6 +36,7 @@
.Nd time structures .Nd time structures
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/time.h .In sys/time.h

View File

@@ -41,6 +41,7 @@
.Nd decode a visual representation of characters .Nd decode a visual representation of characters
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In vis.h .In vis.h

View File

@@ -51,6 +51,7 @@
.Nd visually encode characters .Nd visually encode characters
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In vis.h .In vis.h

View File

@@ -44,6 +44,7 @@
.Nd wide character string manipulation operations .Nd wide character string manipulation operations
.Sh LIBRARY .Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In wchar.h .In wchar.h

View File

@@ -7,6 +7,13 @@ AM_CPPFLAGS = \
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \ -DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-D__REENTRANT -D__REENTRANT
if OS_WINDOWS
AM_CPPFLAGS += \
-D_CRT_SECURE_NO_WARNINGS \
-D_CRT_NONSTDC_NO_WARNINGS \
$(nil)
endif
libbsd_la_included_sources = \ libbsd_la_included_sources = \
hash/helper.c \ hash/helper.c \
getentropy_aix.c \ getentropy_aix.c \
@@ -54,7 +61,9 @@ libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \ $(libbsd_la_included_sources) \
libbsd.map libbsd.map
libbsd_la_LIBADD = \ libbsd_la_LIBADD = \
$(CLOCK_GETTIME_LIBS) $(CLOCK_GETTIME_LIBS) \
$(ARC4RANDOM_ATFORK_LIBS) \
$(nil)
libbsd_la_LDFLAGS = \ libbsd_la_LDFLAGS = \
-Wl,--version-script=$(srcdir)/libbsd.map \ -Wl,--version-script=$(srcdir)/libbsd.map \
-version-number $(LIBBSD_ABI) -version-number $(LIBBSD_ABI)

View File

@@ -39,11 +39,11 @@
#define minimum(a, b) ((a) < (b) ? (a) : (b)) #define minimum(a, b) ((a) < (b) ? (a) : (b))
#if defined(__GNUC__) || defined(_MSC_VER) #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
#define inline __inline #define inline __inline
#else /* __GNUC__ || _MSC_VER */ #else /* __GNUC__ || __clang__ || _MSC_VER */
#define inline #define inline
#endif /* !__GNUC__ && !_MSC_VER */ #endif /* !__GNUC__ && !__clang__ && !_MSC_VER */
#define KEYSZ 32 #define KEYSZ 32
#define IVSZ 8 #define IVSZ 8

View File

@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
#ifdef __GLIBC__ #ifdef HAVE___REGISTER_ATFORK
extern void *__dso_handle; extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *); extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle) #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)

View File

@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
#ifdef __GLIBC__ #ifdef HAVE___REGISTER_ATFORK
extern void *__dso_handle; extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *); extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle) #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)

104
src/err.c
View File

@@ -1,6 +1,6 @@
/* /*
* Copyright © 2006 Robert Millan * Copyright © 2006 Robert Millan
* Copyright © 2011 Guillem Jover <guillem@hadrons.org> * Copyright © 2011, 2019 Guillem Jover <guillem@hadrons.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -26,8 +26,24 @@
*/ */
#include <err.h> #include <err.h>
#ifdef LIBBSD_NEED_ERR_H_FUNCS
#include <errno.h> #include <errno.h>
#endif
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
void
vwarnc(int code, const char *format, va_list ap)
{
fprintf(stderr, "%s: ", getprogname());
if (format) {
vfprintf(stderr, format, ap);
fprintf(stderr, ": ");
}
fprintf(stderr, "%s\n", strerror(code));
}
void void
warnc(int code, const char *format, ...) warnc(int code, const char *format, ...)
@@ -40,13 +56,15 @@ warnc(int code, const char *format, ...)
} }
void void
vwarnc(int code, const char *format, va_list ap) verrc(int status, int code, const char *format, va_list ap)
{ {
int tmp = errno; fprintf(stderr, "%s: ", getprogname());
if (format) {
errno = code; vfprintf(stderr, format, ap);
vwarn(format, ap); fprintf(stderr, ": ");
errno = tmp; }
fprintf(stderr, "%s\n", strerror(code));
exit(status);
} }
void void
@@ -59,9 +77,75 @@ errc(int status, int code, const char *format, ...)
va_end(ap); va_end(ap);
} }
#ifdef LIBBSD_NEED_ERR_H_FUNCS
void void
verrc(int status, int code, const char *format, va_list ap) vwarn(const char *format, va_list ap)
{ {
errno = code; vwarnc(errno, format, ap);
verr(status, format, ap);
} }
void
warn(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vwarnc(errno, format, ap);
va_end(ap);
}
void
vwarnx(const char *format, va_list ap)
{
fprintf(stderr, "%s: ", getprogname());
if (format)
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
}
void
warnx(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vwarnx(format, ap);
va_end(ap);
}
void
verr(int status, const char *format, va_list ap)
{
verrc(status, errno, format, ap);
}
void
err(int status, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrc(status, errno, format, ap);
va_end(ap);
}
void
verrx(int eval, const char *format, va_list ap)
{
fprintf(stderr, "%s: ", getprogname());
if (format)
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
exit(eval);
}
void
errx(int eval, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrx(eval, format, ap);
va_end(ap);
}
#endif

View File

@@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
__attribute__((weak)) void __attribute__((__weak__)) void
__explicit_bzero_hook(void *buf, size_t len) __explicit_bzero_hook(void *buf, size_t len)
{ {
} }

View File

@@ -32,6 +32,7 @@
#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>

View File

@@ -19,6 +19,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <hashinc> #include <hashinc>

View File

@@ -19,9 +19,14 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>

View File

@@ -160,3 +160,24 @@ LIBBSD_0.9 {
strsvisx; strsvisx;
svis; svis;
} LIBBSD_0.8; } 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;
LIBBSD_0.10.0 {
/* These BSD extensions are available on GNU systems, but not on other
* systems such as Windows or musl libc based ones. */
vwarn;
vwarnx;
warn;
warnx;
verr;
verrx;
err;
errx;
} LIBBSD_0.9.1;

View File

@@ -37,6 +37,8 @@
#define ELF_TARG_VER EV_CURRENT #define ELF_TARG_VER EV_CURRENT
/* The following entries are sorted alphabetically. */
#if defined(__alpha__) #if defined(__alpha__)
#define ELF_TARG_MACH EM_ALPHA #define ELF_TARG_MACH EM_ALPHA
@@ -53,6 +55,12 @@
#endif #endif
#define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_DATA ELFDATA2LSB
#elif defined (__arc__)
#define ELF_TARG_MACH EM_ARC
#define ELF_TARG_CLASS ELFCLASS32
#define ELF_TARG_DATA ELFDATA2LSB
#elif defined(__arm__) #elif defined(__arm__)
#define ELF_TARG_MACH EM_ARM #define ELF_TARG_MACH EM_ARM
@@ -66,7 +74,11 @@
#elif defined(__aarch64__) #elif defined(__aarch64__)
#define ELF_TARG_MACH EM_AARCH64 #define ELF_TARG_MACH EM_AARCH64
#if defined(__ILP32__)
#define ELF_TARG_CLASS ELFCLASS32
#else
#define ELF_TARG_CLASS ELFCLASS64 #define ELF_TARG_CLASS ELFCLASS64
#endif
#if defined(__AARCH64EB__) #if defined(__AARCH64EB__)
#define ELF_TARG_DATA ELFDATA2MSB #define ELF_TARG_DATA ELFDATA2MSB
#else #else
@@ -88,6 +100,12 @@
#error Unknown AVR32 endianness #error Unknown AVR32 endianness
#endif #endif
#elif defined(__e2k__)
#define ELF_TARG_MACH EM_MCST_ELBRUS
#define ELF_TARG_CLASS ELFCLASS64
#define ELF_TARG_DATA ELFDATA2LSB
#elif defined(__hppa__) #elif defined(__hppa__)
#define ELF_TARG_MACH EM_PARISC #define ELF_TARG_MACH EM_PARISC

View File

@@ -29,5 +29,19 @@
#define libbsd_link_warning(symbol, msg) \ #define libbsd_link_warning(symbol, msg) \
static const char libbsd_emit_link_warning_##symbol[] \ static const char libbsd_emit_link_warning_##symbol[] \
__attribute__((used,section(".gnu.warning." #symbol))) = msg; __attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
#ifdef __ELF__
#define libbsd_symver_default(alias, symbol, version) \
__asm__(".symver " #symbol "," #alias "@@" #version)
#define libbsd_symver_variant(alias, symbol, version) \
__asm__(".symver " #symbol "," #alias "@" #version)
#else
#define libbsd_symver_default(alias, symbol, version) \
extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
#define libbsd_symver_variant(alias, symbol, version)
#endif
#endif #endif

View File

@@ -141,11 +141,17 @@ __fdnlist(int fd, struct nlist *list)
fstat(fd, &st) < 0) fstat(fd, &st) < 0)
return (-1); return (-1);
if (ehdr.e_shnum == 0 ||
ehdr.e_shentsize != sizeof(Elf_Shdr)) {
errno = ERANGE;
return (-1);
}
/* calculate section header table size */ /* calculate section header table size */
shdr_size = ehdr.e_shentsize * ehdr.e_shnum; shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
/* Make sure it's not too big to mmap */ /* Make sure it's not too big to mmap */
if (shdr_size > SIZE_T_MAX) { if (shdr_size > SIZE_T_MAX || shdr_size > st.st_size) {
errno = EFBIG; errno = EFBIG;
return (-1); return (-1);
} }
@@ -155,7 +161,7 @@ __fdnlist(int fd, struct nlist *list)
return (-1); return (-1);
/* Load section header table. */ /* Load section header table. */
if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) < 0) if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) != (ssize_t)shdr_size)
goto done; goto done;
/* /*
@@ -166,6 +172,9 @@ __fdnlist(int fd, struct nlist *list)
*/ */
for (i = 0; i < ehdr.e_shnum; i++) { for (i = 0; i < ehdr.e_shnum; i++) {
if (shdr[i].sh_type == SHT_SYMTAB) { if (shdr[i].sh_type == SHT_SYMTAB) {
if (shdr[i].sh_link >= ehdr.e_shnum)
goto done;
symoff = shdr[i].sh_offset; symoff = shdr[i].sh_offset;
symsize = shdr[i].sh_size; symsize = shdr[i].sh_size;
symstroff = shdr[shdr[i].sh_link].sh_offset; symstroff = shdr[shdr[i].sh_link].sh_offset;
@@ -175,7 +184,7 @@ __fdnlist(int fd, struct nlist *list)
} }
/* Check for files too large to mmap. */ /* Check for files too large to mmap. */
if (symstrsize > SIZE_T_MAX) { if (symstrsize > SIZE_T_MAX || symstrsize > st.st_size) {
errno = EFBIG; errno = EFBIG;
goto done; goto done;
} }
@@ -189,7 +198,7 @@ __fdnlist(int fd, struct nlist *list)
if (strtab == NULL) if (strtab == NULL)
goto done; goto done;
if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) < 0) if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) != (ssize_t)symstrsize)
goto done; goto done;
/* /*
@@ -227,16 +236,18 @@ __fdnlist(int fd, struct nlist *list)
symsize -= cc; symsize -= cc;
for (s = sbuf; cc > 0 && nent > 0; ++s, cc -= sizeof(*s)) { for (s = sbuf; cc > 0 && nent > 0; ++s, cc -= sizeof(*s)) {
char *name; char *name;
Elf_Word size;
struct nlist *p; struct nlist *p;
name = strtab + s->st_name; name = strtab + s->st_name;
if (name[0] == '\0') if (name[0] == '\0')
continue; continue;
size = symstrsize - s->st_name;
for (p = list; !ISLAST(p); p++) { for (p = list; !ISLAST(p); p++) {
if ((p->n_un.n_name[0] == '_' && if ((p->n_un.n_name[0] == '_' &&
strcmp(name, p->n_un.n_name+1) == 0) strncmp(name, p->n_un.n_name+1, size) == 0) ||
|| strcmp(name, p->n_un.n_name) == 0) { strncmp(name, p->n_un.n_name, size) == 0) {
elf_sym_to_nlist(p, s, shdr, elf_sym_to_nlist(p, s, shdr,
ehdr.e_shnum); ehdr.e_shnum);
if (--nent <= 0) if (--nent <= 0)
@@ -258,6 +269,10 @@ nlist(const char *name, struct nlist *list)
{ {
int fd, n; int fd, n;
if (list == NULL) {
errno = EINVAL;
return (-1);
}
fd = open(name, O_RDONLY, 0); fd = open(name, O_RDONLY, 0);
if (fd < 0) if (fd < 0)
return (-1); return (-1);

View File

@@ -31,6 +31,7 @@
#include <err.h> #include <err.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "local-link.h"
static struct { static struct {
/* Original value. */ /* Original value. */
@@ -280,16 +281,19 @@ setproctitle_impl(const char *fmt, ...)
*++nul = '\0'; *++nul = '\0';
} }
} }
__asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5"); libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
/* The original function introduced in 0.2 was a stub, it only got implemented /* The original function introduced in 0.2 was a stub, it only got implemented
* in 0.5, make the implementation available in the old version as an alias * in 0.5, make the implementation available in the old version as an alias
* for code linking against that version, and change the default to use the * for code linking against that version, and change the default to use the
* new version, so that new code depends on the implemented version. */ * new version, so that new code depends on the implemented version. */
#ifdef HAVE_TYPEOF #ifdef HAVE_TYPEOF
extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl"))); extern __typeof__(setproctitle_impl)
setproctitle_stub
__attribute__((__alias__("setproctitle_impl")));
#else #else
void setproctitle_stub(const char *fmt, ...) void
__attribute__((alias("setproctitle_impl"))); setproctitle_stub(const char *fmt, ...)
__attribute__((__alias__("setproctitle_impl")));
#endif #endif
__asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2"); libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);

View File

@@ -49,4 +49,4 @@
* move them from .ctors to .init_array. * move them from .ctors to .init_array.
*/ */
void (*libbsd_init_func)(int argc, char *argv[], char *envp[]) void (*libbsd_init_func)(int argc, char *argv[], char *envp[])
__attribute__((section(".init_array"))) = setproctitle_init; __attribute__((__section__(".init_array"))) = setproctitle_init;

View File

@@ -37,7 +37,12 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include <vis.h> #include <vis.h>
#pragma GCC diagnostic pop
#include "local-link.h"
#ifdef __weak_alias #ifdef __weak_alias
__weak_alias(strnunvisx,_strnunvisx) __weak_alias(strnunvisx,_strnunvisx)
@@ -65,7 +70,8 @@ __weak_alias(strnunvisx,_strnunvisx)
#define S_NUMBER 14 /* collecting number */ #define S_NUMBER 14 /* collecting number */
#define S_STRING 15 /* collecting string */ #define S_STRING 15 /* collecting string */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define isoctal(c) \
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) #define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10)) #define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10))
@@ -543,8 +549,30 @@ strunvis(char *dst, const char *src)
return strnunvisx(dst, (size_t)~0, src, 0); return strnunvisx(dst, (size_t)~0, src, 0);
} }
int /*
strnunvis(char *dst, size_t dlen, const char *src) * 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); return strnunvisx(dst, dlen, src, 0);
} }
libbsd_symver_default(strnunvis, strnunvis_openbsd, LIBBSD_0.2);
int
strnunvis_netbsd(char *dst, size_t dlen, const char *src)
{
return strnunvisx(dst, dlen, src, 0);
}
libbsd_symver_variant(strnunvis, strnunvis_netbsd, LIBBSD_0.9.1);

View File

@@ -57,10 +57,12 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h>
#include <assert.h> #include <assert.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include <vis.h> #include <vis.h>
#pragma GCC diagnostic pop
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
@@ -75,6 +77,8 @@ __weak_alias(strvisx,_strvisx)
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "local-link.h"
#define _DIAGASSERT(x) #define _DIAGASSERT(x)
/* /*
@@ -114,7 +118,8 @@ iscgraph(int c) {
#define ISGRAPH(flags, c) \ #define ISGRAPH(flags, c) \
(((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c)) (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
#define iswoctal(c) (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7') #define iswoctal(c) \
(((unsigned char)(c)) >= L'0' && ((unsigned char)(c)) <= L'7')
#define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n') #define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n')
#define iswsafe(c) (c == L'\b' || c == BELL || c == L'\r') #define iswsafe(c) (c == L'\b' || c == BELL || c == L'\r')
#define xtoa(c) L"0123456789abcdef"[c] #define xtoa(c) L"0123456789abcdef"[c]
@@ -250,8 +255,10 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra)
} }
if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) { if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) {
*dst++ = L'\\'; *dst++ = L'\\';
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0'; *dst++ =
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0'; (unsigned char)(((uint32_t)(unsigned char)c >> 6) & 03) + L'0';
*dst++ =
(unsigned char)(((uint32_t)(unsigned char)c >> 3) & 07) + L'0';
*dst++ = (c & 07) + L'0'; *dst++ = (c & 07) + L'0';
} else { } else {
if ((flags & VIS_NOSLASH) == 0) if ((flags & VIS_NOSLASH) == 0)
@@ -302,7 +309,7 @@ do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
/* See comment in istrsenvisx() output loop, below. */ /* See comment in istrsenvisx() output loop, below. */
wmsk = 0; wmsk = 0;
for (i = sizeof(wmsk) - 1; i >= 0; i--) { for (i = sizeof(wmsk) - 1; i >= 0; i--) {
shft = i * NBBY; shft = i * CHAR_BIT;
bmsk = (uint64_t)0xffLL << shft; bmsk = (uint64_t)0xffLL << shft;
wmsk |= bmsk; wmsk |= bmsk;
if ((c & wmsk) || i == 0) if ((c & wmsk) || i == 0)
@@ -346,7 +353,7 @@ makeextralist(int flags, const char *src)
if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) { if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
size_t i; size_t i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
dst[i] = (wchar_t)(u_char)src[i]; dst[i] = (wchar_t)(unsigned char)src[i];
d = dst + len; d = dst + len;
} else } else
d = dst + wcslen(dst); d = dst + wcslen(dst);
@@ -449,7 +456,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
clen = mbtowc(src, mbsrc, MB_LEN_MAX); clen = mbtowc(src, mbsrc, MB_LEN_MAX);
if (cerr || clen < 0) { if (cerr || clen < 0) {
/* Conversion error, process as a byte instead. */ /* Conversion error, process as a byte instead. */
*src = (wint_t)(u_char)*mbsrc; *src = (wint_t)(unsigned char)*mbsrc;
clen = 1; clen = 1;
cerr = 1; cerr = 1;
} }
@@ -500,7 +507,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
*/ */
for (start = dst; len > 0; len--) { for (start = dst; len > 0; len--) {
c = *src++; c = *src++;
dst = (*f)(dst, c, flags, len >= 1 ? *src : L'\0', extra); dst = (*f)(dst, c, flags, *src, extra);
if (dst == NULL) { if (dst == NULL) {
errno = ENOSPC; errno = ENOSPC;
goto out; goto out;
@@ -533,7 +540,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
clen = 0; clen = 0;
wmsk = 0; wmsk = 0;
for (i = sizeof(wmsk) - 1; i >= 0; i--) { for (i = sizeof(wmsk) - 1; i >= 0; i--) {
shft = i * NBBY; shft = i * CHAR_BIT;
bmsk = (uint64_t)0xffLL << shft; bmsk = (uint64_t)0xffLL << shft;
wmsk |= bmsk; wmsk |= bmsk;
if ((*dst & wmsk) || i == 0) if ((*dst & wmsk) || i == 0)
@@ -577,10 +584,20 @@ out:
} }
static int static int
istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc, istrsenvisxna(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
int flags, const char *mbextra, int *cerr_ptr) int flags, const char *mbextra, int *cerr_ptr)
{ {
return istrsenvisx(mbdstp, dlen, mbsrc, assert(mbdst != NULL);
return istrsenvisx(&mbdst, dlen, mbsrc, mblength,
flags, mbextra, cerr_ptr);
}
static int
istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc,
int flags, const char *mbextra, int *cerr_ptr)
{
return istrsenvisxna(mbdst, dlen, mbsrc,
mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr); mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
} }
@@ -625,33 +642,33 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra
int int
strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra) strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
{ {
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL); return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL);
} }
int int
strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra) strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
{ {
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL); return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL);
} }
int int
strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra) strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
{ {
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL); return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
} }
int int
strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
const char *mbextra) const char *mbextra)
{ {
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL); return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
} }
int int
strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
const char *mbextra, int *cerr_ptr) const char *mbextra, int *cerr_ptr)
{ {
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr); return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
} }
/* /*
@@ -698,20 +715,43 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc)
int int
strvis(char *mbdst, const char *mbsrc, int flags) strvis(char *mbdst, const char *mbsrc, int flags)
{ {
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL); 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.
*
* 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: strnvis(char *dst, const char *src, size_t dlen, int flag);
* NetBSD: 2012, strnvis(char *dst, size_t dlen, const char *src, int flag);
*/
int int
strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags) strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
{ {
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL); return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
} }
libbsd_symver_default(strnvis, strnvis_openbsd, LIBBSD_0.2);
int
strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
{
return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
}
libbsd_symver_variant(strnvis, strnvis_netbsd, LIBBSD_0.9.1);
int int
stravis(char **mbdstp, const char *mbsrc, int flags) stravis(char **mbdstp, const char *mbsrc, int flags)
{ {
*mbdstp = NULL; *mbdstp = NULL;
return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL); return istrsenvisx(mbdstp, NULL, mbsrc,
mbsrc != NULL ? strlen(mbsrc) : 0, flags, "", NULL);
} }
/* /*
@@ -728,18 +768,18 @@ stravis(char **mbdstp, const char *mbsrc, int flags)
int int
strvisx(char *mbdst, const char *mbsrc, size_t len, int flags) strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
{ {
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL); return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, "", NULL);
} }
int int
strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags) strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
{ {
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL); return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", NULL);
} }
int int
strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
int *cerr_ptr) int *cerr_ptr)
{ {
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr); return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
} }

2
test/.gitignore vendored
View File

@@ -19,3 +19,5 @@ setmode
strl strl
strmode strmode
strnstr strnstr
vis
vis-openbsd

View File

@@ -47,6 +47,8 @@ check_PROGRAMS = \
strl \ strl \
strmode \ strmode \
strnstr \ strnstr \
vis \
vis-openbsd \
$(nil) $(nil)
if HAVE_LIBTESTU01 if HAVE_LIBTESTU01

View File

@@ -66,6 +66,8 @@ main(int argc, char **argv)
assert(*data_pub_ptr == 50); assert(*data_pub_ptr == 50);
assert(nl[0].n_name == nl[0].n_un.n_name);
rc = nlist(argv[0], nl); rc = nlist(argv[0], nl);
assert(rc == 0); assert(rc == 0);

View File

@@ -28,7 +28,9 @@
* other headers through magic macros, to check that the overlay is working * other headers through magic macros, to check that the overlay is working
* properly. */ * properly. */
#include <errno.h> #include <errno.h>
#ifdef HAVE_GRP_H
#include <grp.h> #include <grp.h>
#endif
#include <stdint.h> #include <stdint.h>
/* Include libbsd overlayed headers that might get partially included. */ /* Include libbsd overlayed headers that might get partially included. */

47
test/vis-openbsd.c Normal file
View 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
View 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;
}