Compare commits

..

No commits in common. "main" and "0.11.6" have entirely different histories.
main ... 0.11.6

116 changed files with 1002 additions and 3149 deletions

2
.gitignore vendored
View File

@ -10,8 +10,6 @@ ChangeLog
*.trs *.trs
*.gcda *.gcda
*.gcno *.gcno
*.sym
*.map
.dirstamp .dirstamp
.deps/ .deps/
.libs/ .libs/

View File

@ -1,30 +1,16 @@
.vpath-tests:
script:
- ./autogen
- mkdir -p build-tree
- cd build-tree
- ../configure
- make check
.unit-tests: .unit-tests:
script: script:
- ./autogen && ./configure - ./autogen && ./configure
- make check - make check
.unit-tests-asan:
script:
- ./autogen && ./configure --enable-sanitize
- make check
.coverage: .coverage:
script: script:
- ./autogen && ./configure --disable-static - ./autogen && ./configure --disable-static
- make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb" - make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
- gcovr -s -e test/ - gcovr -s -e test/
coverage: /^TOTAL.*\s+(\d+\%)$/
.debian: .debian:
image: debian:latest image: debian:buster
stage: test stage: test
before_script: before_script:
- apt-get update -qq - apt-get update -qq
@ -38,11 +24,8 @@
- apk add --no-cache git gcc make autoconf automake libtool - apk add --no-cache git gcc make autoconf automake libtool
bsd-compat-headers linux-headers libmd-dev musl-dev gcovr bsd-compat-headers linux-headers libmd-dev musl-dev gcovr
vpath-tests:debian:
extends: [.debian, .vpath-tests]
unit-tests:debian: unit-tests:debian:
extends: [.debian, .unit-tests-asan] extends: [.debian, .unit-tests]
coverage:debian: coverage:debian:
extends: [.debian, .coverage] extends: [.debian, .coverage]

76
COPYING
View File

@ -3,9 +3,73 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files: Files:
* *
Copyright: Copyright:
Copyright © 2004-2024 Guillem Jover <guillem@hadrons.org> Copyright © 2004-2006, 2008-2022 Guillem Jover <guillem@hadrons.org>
License: BSD-3-clause License: BSD-3-clause
Files:
man/arc4random.3bsd
Copyright:
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
All rights reserved.
License: BSD-4-clause-Niels-Provos
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Niels Provos.
4. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Files:
man/getprogname.3bsd
Copyright:
Copyright © 2001 Christopher G. Demetriou
All rights reserved.
License: BSD-4-clause-Christopher-G-Demetriou
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed for the
NetBSD Project. See http://www.netbsd.org/ for
information about NetBSD.
4. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Files: Files:
include/bsd/err.h include/bsd/err.h
include/bsd/stdlib.h include/bsd/stdlib.h
@ -171,7 +235,6 @@ License: BSD-5-clause-Peter-Wemm
Files: Files:
include/bsd/stringlist.h include/bsd/stringlist.h
man/arc4random.3bsd
man/fmtcheck.3bsd man/fmtcheck.3bsd
man/humanize_number.3bsd man/humanize_number.3bsd
man/stringlist.3bsd man/stringlist.3bsd
@ -186,12 +249,6 @@ Copyright:
Copyright © 2013 John-Mark Gurney <jmg@FreeBSD.org> Copyright © 2013 John-Mark Gurney <jmg@FreeBSD.org>
All rights reserved. All rights reserved.
. .
Copyright © 2014 The NetBSD Foundation, Inc.
All rights reserved.
.
Some code was derived from software contributed to The NetBSD Foundation
by Taylor R. Campbell.
.
Some code was contributed to The NetBSD Foundation by Allen Briggs. Some code was contributed to The NetBSD Foundation by Allen Briggs.
. .
Some code was contributed to The NetBSD Foundation by Luke Mewburn. Some code was contributed to The NetBSD Foundation by Luke Mewburn.
@ -253,6 +310,7 @@ Copyright:
All rights reserved. All rights reserved.
. .
Copyright © 2009 Advanced Computing Technologies LLC Copyright © 2009 Advanced Computing Technologies LLC
Written by: John H. Baldwin <jhb@FreeBSD.org>
All rights reserved. All rights reserved.
. .
Copyright © 2011 Guillem Jover <guillem@hadrons.org> Copyright © 2011 Guillem Jover <guillem@hadrons.org>
@ -344,7 +402,7 @@ Copyright:
Copyright © 2014 Theo de Raadt <deraadt@openbsd.org> Copyright © 2014 Theo de Raadt <deraadt@openbsd.org>
Copyright © 2014 Google Inc. Copyright © 2014 Google Inc.
Copyright © 2015 Michael Felt <aixtools@gmail.com> Copyright © 2015 Michael Felt <aixtools@gmail.com>
Copyright © 2015, 2022 Guillem Jover <guillem@hadrons.org> Copyright © 2015 Guillem Jover <guillem@hadrons.org>
License: ISC License: ISC
Permission to use, copy, modify, and distribute this software for any Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above

View File

@ -1,18 +1,13 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
SUBDIRS = \ SUBDIRS = include man src test
include \
man \
src \
test \
# EOL
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \ EXTRA_DIST = \
autogen \ autogen \
get-version \ get-version \
# EOL $(nil)
dist-hook: dist-hook:
echo $(VERSION) >$(distdir)/.dist-version echo $(VERSION) >$(distdir)/.dist-version

5
README
View File

@ -9,7 +9,6 @@ A BSD compatible message-digest library is required, on systems where
this is not provided by its libc or libmd libraries, the canonical this is not provided by its libc or libmd libraries, the canonical
implementation to use is <https://www.hadrons.org/software/libmd/>. implementation to use is <https://www.hadrons.org/software/libmd/>.
Releases Releases
-------- --------
@ -31,7 +30,7 @@ The mail address is:
Source Repository Source Repository
----------------- -----------------
The primary repository can be browsed at: The master repository can be browsed at:
<https://cgit.freedesktop.org/libbsd> <https://cgit.freedesktop.org/libbsd>
@ -39,7 +38,6 @@ and cloned from:
<https://anongit.freedesktop.org/git/libbsd> <https://anongit.freedesktop.org/git/libbsd>
Building from git source Building from git source
------------------------ ------------------------
@ -57,7 +55,6 @@ the git tree:
the source should be roughly equivalent to the distributed tar source. the source should be roughly equivalent to the distributed tar source.
Building from tar source Building from tar source
------------------------ ------------------------

View File

@ -6,22 +6,17 @@ AC_CONFIG_SRCDIR([src/strlcpy.c])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE( AM_INIT_AUTOMAKE([1.9 foreign nostdinc subdir-objects no-dist-gzip dist-xz])
[1.11]
[-Wall]
[foreign]
[nostdinc]
[subdir-objects]
[no-dist-gzip dist-xz]
)
AM_SILENT_RULES([yes])
SOVERSION_MAJOR=0 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
SOVERSION_MINOR=12 [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
SOVERSION_PATCH=2
SOVERSION="$SOVERSION_MAJOR:$SOVERSION_MINOR:$SOVERSION_PATCH" LIBBSD_ABI_MAJOR=0
AC_SUBST([SOVERSION]) LIBBSD_ABI_MINOR=11
LIBBSD_ABI_PATCH=6
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
AC_SUBST([LIBBSD_ABI])
# Check and store if we got user supplied variables # Check and store if we got user supplied variables
user_CFLAGS=${CFLAGS-unset} user_CFLAGS=${CFLAGS-unset}
@ -29,353 +24,27 @@ user_CFLAGS=${CFLAGS-unset}
# Checks for operating system services and capabilities. # Checks for operating system services and capabilities.
AC_USE_SYSTEM_EXTENSIONS AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
LIBBSD_SYS_TIME64
AM_PROG_AR
LT_INIT LT_INIT
LIBBSD_LINKER_VERSION_SCRIPT
## Select library ABI to expose. AC_CACHE_CHECK([if ld supports --version-script flag],
# [libbsd_cv_version_script], [
# The systems have DROP comments for interfaces that could be dropped on echo "{ global: symbol; local: *; };" >conftest.map
# the next SOVERSION bump. save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
is_windows=no AC_LINK_IFELSE([
AC_LANG_PROGRAM([], [])
api_time_macros=unknown ], [
libbsd_cv_version_script=yes
abi_accmode=unknown ], [
abi_arc4random=unknown libbsd_cv_version_script=no
abi_arc4random_stir=unknown ])
abi_asprintf=unknown LDFLAGS="$save_LDFLAGS"
abi_bsd_getopt=unknown rm -f conftest.map
abi_closefrom=unknown ]
abi_err=unknown
abi_errc=unknown
abi_expand_number=unknown
abi_explicit_bzero=unknown
abi_fgetln=unknown
abi_flopen=unknown
abi_fmtcheck=unknown
abi_fpurge=unknown
abi_freezero=unknown
abi_funopen=unknown
abi_getbsize=unknown
abi_getpeereid=unknown
abi_humanize_number=unknown
abi_id_from_name=unknown
abi_inet_net_pton=unknown
abi_md5=unknown
abi_name_from_id=unknown
abi_nlist=unknown
abi_pidfile=unknown
abi_proctitle=unknown
abi_progname=unknown
abi_readpassphrase=unknown
abi_reallocarray=unknown
abi_reallocf=unknown
abi_recallocarray=unknown
abi_stringlist=unknown
abi_sort=unknown
abi_strl=unknown
abi_strmode=unknown
abi_strnstr=unknown
abi_strtonum=unknown
abi_strtox=unknown
abi_timeconv=unknown
abi_vis=unknown
abi_wcsl=unknown
AS_CASE([$host_os],
[*-gnu* | gnu*], [
api_time_macros=no
abi_accmode=yes
# DROP: On glibc >= 2.36.
#abi_arc4random=no
abi_arc4random=yes
abi_arc4random_stir=yes
abi_asprintf=no
abi_bsd_getopt=yes
# DROP: On glibc >= 2.34.
#abi_closefrom=no
abi_closefrom=yes
abi_err=no
abi_errc=yes
abi_expand_number=yes
# DROP: On glibc >= 2.25.
#abi_explicit_bzero=no
abi_explicit_bzero=yes
abi_fgetln=yes
abi_flopen=yes
abi_fmtcheck=yes
abi_fpurge=yes
abi_freezero=yes
abi_funopen=yes
abi_getbsize=yes
abi_getpeereid=yes
abi_humanize_number=yes
abi_id_from_name=yes
# DROP: On glibc.
#abi_inet_net_pton=no
abi_inet_net_pton=yes
# DROP: On libmd.
#abi_md5=no
abi_md5=yes
abi_name_from_id=yes
abi_nlist=yes
abi_pidfile=yes
abi_proctitle=yes
abi_progname=yes
abi_readpassphrase=yes
# DROP: On glibc >= 2.26.
#abi_reallocarray=no
abi_reallocarray=yes
abi_reallocf=yes
abi_recallocarray=yes
abi_stringlist=yes
abi_sort=yes
# DROP: On glibc >= 2.38.
#abi_strl=no
abi_strl=yes
abi_strmode=yes
abi_strnstr=yes
abi_strtonum=yes
abi_strtox=yes
abi_timeconv=yes
# DROP: On libmd.
abi_transparent_libmd=yes
abi_vis=yes
abi_wcsl=yes
],
[*-musl*], [
api_time_macros=no
abi_accmode=yes
abi_arc4random=yes
abi_arc4random_stir=yes
abi_asprintf=no
# DROP: On musl >= 0.9.7, optreset got implemented.
#abi_bsd_getopt=no
abi_bsd_getopt=yes
abi_closefrom=yes
abi_err=no
abi_errc=yes
abi_expand_number=yes
# DROP: On musl >= 1.1.20.
#abi_explicit_bzero=no
abi_explicit_bzero=yes
# DROP: On musl >= 0.9.4.
#abi_fgetln=no
abi_fgetln=yes
abi_flopen=yes
abi_fmtcheck=yes
abi_fpurge=yes
abi_freezero=yes
# On musl >= 1.1.19, fopencookie() got implemented, and because we were
# checking for its presence to decide whether to build funopen(), it got
# included in builds even when previously it had not been included, which
# is partially an ABI issue, but given that disabling it now would be
# worse, we'll ignore this as this is only a problem with downgrades. And
# enable it explicitly
#abi_funopen=no
abi_funopen=yes
abi_getbsize=yes
abi_getpeereid=yes
abi_humanize_number=yes
abi_id_from_name=yes
abi_inet_net_pton=yes
# DROP: On libmd.
#abi_md5=no
abi_md5=yes
abi_name_from_id=yes
abi_nlist=yes
abi_pidfile=yes
abi_proctitle=yes
abi_progname=yes
abi_readpassphrase=yes
# DROP: On musl >= 1.2.2.
#abi_reallocarray=no
abi_reallocarray=yes
abi_reallocf=ues
abi_recallocarray=yes
abi_stringlist=yes
abi_sort=yes
# DROP: On musl >= 0.5.0, strlcpy() and strlcat() were already implemented.
#abi_strl=no
abi_strl=yes
abi_strmode=yes
abi_strnstr=yes
abi_strtonum=yes
abi_strtox=yes
abi_timeconv=yes
# DROP: On libmd.
abi_transparent_libmd=yes
abi_vis=yes
abi_wcsl=yes
],
[darwin*], [
api_time_macros=no
abi_accmode=no
abi_arc4random=no
abi_arc4random_stir=no
abi_asprintf=no
abi_bsd_getopt=no
abi_closefrom=yes
abi_err=no
abi_errc=no
abi_expand_number=yes
abi_explicit_bzero=yes
abi_fgetln=no
abi_flopen=yes
abi_fmtcheck=no
abi_fpurge=no
abi_freezero=yes
abi_funopen=no
abi_getbsize=yes
abi_getpeereid=no
abi_humanize_number=yes
abi_id_from_name=yes
abi_inet_net_pton=no
# On libmd.
abi_md5=no
abi_name_from_id=no
abi_nlist=no
abi_pidfile=yes
abi_proctitle=yes
abi_progname=no
abi_readpassphrase=no
abi_reallocarray=yes
abi_reallocf=no
abi_recallocarray=yes
abi_stringlist=no
abi_sort=no
abi_strl=no
abi_strmode=no
abi_strnstr=no
abi_strtonum=no
abi_strtox=yes
abi_timeconv=no
# On libmd.
abi_transparent_libmd=no
abi_vis=no
abi_wcsl=no
],
[solaris2*], [
api_time_macros=yes
abi_accmode=yes
abi_arc4random=no
abi_arc4random_stir=no
abi_asprintf=no
abi_bsd_getopt=yes
abi_closefrom=no
abi_err=no
abi_errc=yes
abi_expand_number=yes
abi_explicit_bzero=yes
abi_fgetln=yes
abi_flopen=yes
abi_fmtcheck=no
abi_fpurge=yes
abi_freezero=yes
abi_funopen=no
abi_getbsize=yes
abi_getpeereid=yes
abi_humanize_number=yes
abi_id_from_name=yes
abi_inet_net_pton=yes
# On libmd.
abi_md5=no
abi_name_from_id=yes
abi_nlist=no
abi_pidfile=yes
abi_proctitle=yes
abi_progname=no
abi_readpassphrase=yes
abi_reallocarray=yes
abi_reallocf=no
abi_recallocarray=yes
abi_stringlist=yes
abi_sort=yes
abi_strl=no
abi_strmode=yes
abi_strnstr=no
abi_strtonum=no
abi_strtox=yes
abi_timeconv=yes
# On libmd.
abi_transparent_libmd=no
abi_vis=yes
abi_wcsl=yes
],
[aix*], [
api_time_macros=yes
abi_accmode=yes
abi_arc4random=yes
abi_arc4random_stir=yes
abi_asprintf=yes
abi_bsd_getopt=yes
abi_closefrom=yes
abi_err=yes
abi_errc=yes
abi_expand_number=yes
abi_explicit_bzero=yes
abi_fgetln=yes
abi_flopen=yes
abi_fmtcheck=yes
abi_fpurge=no
abi_freezero=yes
abi_funopen=no
abi_getbsize=yes
abi_getpeereid=yes
abi_humanize_number=yes
abi_id_from_name=yes
abi_inet_net_pton=no
# On libmd.
abi_md5=no
abi_name_from_id=yes
abi_nlist=no
abi_pidfile=yes
abi_proctitle=yes
abi_progname=yes
abi_readpassphrase=yes
abi_reallocarray=yes
abi_reallocf=yes
abi_recallocarray=yes
abi_stringlist=yes
abi_sort=yes
abi_strl=yes
abi_strmode=yes
abi_strnstr=yes
abi_strtonum=yes
abi_strtox=yes
abi_timeconv=yes
# On libmd.
abi_transparent_libmd=no
abi_vis=yes
abi_wcsl=yes
],
[mingw*], [
is_windows=yes
],
) )
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
# Handle artificial ABI selections that are combinations of others. [test "x$libbsd_cv_version_script" = "xyes"])
AS_IF([test "$abi_name_from_id" = "yes" || test "$abi_id_from_name" = "yes"], [
abi_pwcache=yes
], [
abi_pwcache=no
])
AS_IF([test "$abi_err" = "yes" || test "$abi_errc" = "yes"], [
abi_err_h=yes
], [
abi_err_h=no
])
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
# Checks for programs. # Checks for programs.
AC_CHECK_TOOL([OBJDUMP], [objdump]) AC_CHECK_TOOL([OBJDUMP], [objdump])
@ -423,53 +92,37 @@ AS_IF([test "$user_CFLAGS" = unset], [
LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings]) LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings])
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS" CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
AC_ARG_ENABLE([sanitize],
[AS_HELP_STRING([--enable-sanitize], [enable compiler sanitizer support])],
[
LIBBSD_COMPILER_FLAGS=''
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=address])
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=leak])
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=undefined])
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
LDFLAGS="$LDFLAGS $LIBBSD_COMPILER_FLAGS"
])
]) ])
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits], AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
[TESTU01_LIBS="-ltestu01"]) [TESTU01_LIBS="-ltestu01"])
AC_SUBST([TESTU01_LIBS]) AC_SUBST([TESTU01_LIBS])
AM_CONDITIONAL([HAVE_LIBTESTU01], AM_CONDITIONAL([HAVE_LIBTESTU01],
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"]) [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
saved_LIBS="$LIBS" saved_LIBS="$LIBS"
AS_IF([test "$abi_md5" = "yes"], [ AC_SEARCH_LIBS([MD5Update], [md], [
AC_SEARCH_LIBS([MD5Update], [md], [ AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [ MD5_LIBS="$MD5_LIBS $ac_cv_search_MD5Update"
MD5_LIBS="$MD5_LIBS $ac_cv_search_MD5Update" need_transparent_libmd=yes
abi_transparent_libmd=yes
])
], [
AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
]) ])
], [
AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
]) ])
AS_IF([test "$abi_arc4random" = "yes"], [ AC_SEARCH_LIBS([SHA512Update], [md], [
AC_CHECK_FUNCS([getentropy]) AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_SHA512Update"
AS_IF([test "$ac_cv_func_getentropy" != "yes"], [
AC_SEARCH_LIBS([SHA512Update], [md], [
AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
LIBBSD_LIBS="$SHA512_LIBS $ac_cv_search_SHA512Update"
])
], [
AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
])
]) ])
], [
AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
]) ])
LIBS="$saved_LIBS" LIBS="$saved_LIBS"
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
[test "x$need_transparent_libmd" = "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.
@ -481,28 +134,18 @@ AS_CASE([$host_os],
]) ])
LIBS="$saved_LIBS" LIBS="$saved_LIBS"
], ],
[aix*], [ [*-musl*], [
saved_LIBS="$LIBS" # Upstream refuses to define this, we will do it ourselves then.
AC_SEARCH_LIBS([perfstat_cpu_total], [perfstat], [ AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
AS_IF([test "x$ac_cv_search_perfstat_cpu_total" != "xnone required"], [ ],
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_perfstat_cpu_total" [mingw*], [
]) is_windows=yes
])
LIBS="$saved_LIBS"
], ],
) )
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([\ AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h pwd.h grp.h])
sys/ndir.h \
sys/dir.h \
ndir.h \
dirent.h \
pwd.h \
grp.h \
stdio_ext.h \
procinfo.h \
])
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE AC_C_INLINE
@ -515,115 +158,108 @@ AC_TYPE_UID_T
AC_TYPE_SIZE_T AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T AC_TYPE_SSIZE_T
AC_CHECK_DECL([F_CLOSEM], [ AC_CHECK_DECL([F_CLOSEM],
AC_DEFINE([HAVE_FCNTL_CLOSEM], [1], [AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
[Define to 1 if you have fcntl(F_CLOSEM)]) [Define to 1 if you have fcntl(F_CLOSEM)])],
], [], [[ [],
#include <limits.h> [#include <limits.h>
#include <fcntl.h> #include <fcntl.h>])
]])
AC_CHECK_DECLS([environ], [], [], [[ AC_CACHE_CHECK(
#include <unistd.h> [for GNU .init_array section support],
]]) [libbsd_cv_gnu_init_array_support],
[AC_RUN_IFELSE(
LIBBSD_HAS_GNU_INIT_ARRAY [AC_LANG_SOURCE(
[[
static int rc = 1;
static void init(int argc) { if (argc == 1) rc = 0; }
void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
int main() { return rc; }
]]
)],
[libbsd_cv_gnu_init_array_support=yes],
[libbsd_cv_gnu_init_array_support=no],
[AC_PREPROC_IFELSE(
[AC_LANG_SOURCE(
[[
/* Look for a known libc that supports .init_array with the GNU extension
* to pass main() arguments to the init functions. */
#include <stdlib.h>
#if defined __GLIBC_PREREQ
# if __GLIBC_PREREQ(2, 4)
/* glibc supports GNU .init_array since 2.4. */
# else
# error glibc does not support GNU .init_array
# endif
#else
/*
* Basic SysV ABI .init_array support, init functions do not get arguments:
* - Bionic since its inception.
* - uClibc since 0.9.29.
*/
# error unknown whether libc supports GNU .init_array
#endif
]]
)],
[libbsd_cv_gnu_init_array_support=yes],
[libbsd_cv_gnu_init_array_support=no])
]
)]
)
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
[test "$libbsd_cv_gnu_init_array_support" = yes])
# Checks for library functions. # Checks for library functions.
LIBBSD_CHECK_PROGNAME AC_MSG_CHECKING([for program_invocation_short_name])
LIBBSD_CHECK_REGISTER_ATFORK AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <errno.h>]],
[[const char *p = program_invocation_short_name;]])],
[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
[Define to 1 if you have program_invocation_short_name])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])])
AC_CHECK_FUNCS([\ AC_MSG_CHECKING([for __progname])
vasprintf \ AC_LINK_IFELSE(
asprintf \ [AC_LANG_PROGRAM([[extern char *__progname;]],
clearenv \ [[printf("%s", __progname);]])],
dirfd \ [AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
flock \ AC_MSG_RESULT([yes])],
fopencookie \ [AC_MSG_RESULT([no])])
__fpurge \
funopen \
getauxval \
getentropy \
getexecname \
getline \
open_memstream \
pstat_getproc \
sysconf \
uid_from_user \
gid_from_group \
user_from_uid \
group_from_gid \
])
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"]) AC_MSG_CHECKING([for __register_atfork])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#include <stddef.h>
extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
]], [[
__register_atfork(NULL, NULL, NULL, __dso_handle);
]])],
[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
[Define to 1 if you have __register_atfork])
AC_MSG_RESULT([yes])],
[LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
AC_MSG_RESULT([no])
])
# API selection AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
LIBBSD_SELECT_API([time_macros], [time struct conversion macros]) getauxval getentropy getexecname getline \
pstat_getproc sysconf])
# ABI selection AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
LIBBSD_SELECT_ABI([accmode], [setmode()/getmode()])
LIBBSD_SELECT_ABI([arc4random], [arc4random() API])
LIBBSD_SELECT_ABI([arc4random_stir], [arc4random_stir()/arc4random_addrandom()])
LIBBSD_SELECT_ABI([asprintf], [vasprintf()/asprintf()])
LIBBSD_SELECT_ABI([bsd_getopt], [BSD getopt()])
LIBBSD_SELECT_ABI([closefrom], [closefrom()])
LIBBSD_SELECT_ABI([err_h], [err.h header])
LIBBSD_SELECT_ABI([err], [err API])
LIBBSD_SELECT_ABI([errc], [errc API])
LIBBSD_SELECT_ABI([expand_number], [expand_number()])
LIBBSD_SELECT_ABI([explicit_bzero], [explicit_bzero()])
LIBBSD_SELECT_ABI([fgetln], [fgetln/fgetwln()])
LIBBSD_SELECT_ABI([flopen], [flopen()/flopenat()])
LIBBSD_SELECT_ABI([fmtcheck], [fmtcheck()])
LIBBSD_SELECT_ABI([fpurge], [fpurge()])
LIBBSD_SELECT_ABI([freezero], [freezero()])
LIBBSD_SELECT_ABI([funopen], [funopen()])
LIBBSD_SELECT_ABI([getbsize], [getbsize()])
LIBBSD_SELECT_ABI([getpeereid], [getpeereid()])
LIBBSD_SELECT_ABI([humanize_number], [humanize_number()/dehumanize_number()])
LIBBSD_SELECT_ABI([id_from_name], [uid_from_user()/gid_from_user()])
LIBBSD_SELECT_ABI([inet_net_pton], [inet_net_pton()])
LIBBSD_SELECT_ABI([md5], [MD5 digest functions])
LIBBSD_SELECT_ABI([name_from_id], [user_from_uid()/group_from_gid()])
LIBBSD_SELECT_ABI([nlist], [nlist()])
LIBBSD_SELECT_ABI([pidfile], [pidfile API])
LIBBSD_SELECT_ABI([proctitle], [setproctitle() API])
LIBBSD_SELECT_ABI([progname], [setprogname()/getprogname()])
LIBBSD_SELECT_ABI([pwcache], [password cache API])
LIBBSD_SELECT_ABI([readpassphrase], [readpassphrase()])
LIBBSD_SELECT_ABI([reallocarray], [reallocarray()])
LIBBSD_SELECT_ABI([reallocf], [reallocf()])
LIBBSD_SELECT_ABI([recallocarray], [recallocarray()])
LIBBSD_SELECT_ABI([stringlist], [stringlist sl_*() API])
LIBBSD_SELECT_ABI([sort], [BSD sort functions])
LIBBSD_SELECT_ABI([strl], [strlcpy()/strlcat()])
LIBBSD_SELECT_ABI([strmode], [strmode()])
LIBBSD_SELECT_ABI([strnstr], [strnstr()])
LIBBSD_SELECT_ABI([strtonum], [strtonum()])
LIBBSD_SELECT_ABI([strtox], [strtoi()/strtou()])
LIBBSD_SELECT_ABI([timeconv], [timeconv.h API])
LIBBSD_SELECT_ABI([transparent_libmd], [transparent libmd support])
LIBBSD_SELECT_ABI([vis], [vis API])
LIBBSD_SELECT_ABI([wcsl], [wcslcpy()/wcslcat()])
AS_IF([test "x$abi_funopen" = "xno" && \
test "x$ac_cv_func_funopen" != "xyes" && \
test "x$ac_cv_func_fopencookie" = "xyes"], [
AC_MSG_WARN([[can implement funopen() now based on newly added fopencooke(), report upstream]])
])
AC_SUBST([MD5_LIBS]) AC_SUBST([MD5_LIBS])
AC_SUBST([LIBBSD_LIBS]) AC_SUBST([LIBBSD_LIBS])
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
include/Makefile include/Makefile
man/Makefile man/Makefile
src/Makefile src/Makefile
src/libbsd.pc src/libbsd.pc
src/libbsd-ctor.pc src/libbsd-ctor.pc
src/libbsd-overlay.pc src/libbsd-overlay.pc
test/Makefile test/Makefile
]) ])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_OUTPUT AC_OUTPUT

View File

@ -12,77 +12,21 @@ nobase_include_HEADERS = \
bsd/netinet/ip_icmp.h \ bsd/netinet/ip_icmp.h \
bsd/bitstring.h \ bsd/bitstring.h \
bsd/bsd.h \ bsd/bsd.h \
bsd/err.h \
bsd/getopt.h \
bsd/grp.h \
bsd/inttypes.h \ bsd/inttypes.h \
bsd/libutil.h \ bsd/libutil.h \
bsd/md5.h \
bsd/nlist.h \
bsd/pwd.h \
bsd/readpassphrase.h \
bsd/stdio.h \ bsd/stdio.h \
bsd/stdlib.h \ bsd/stdlib.h \
bsd/string.h \ bsd/string.h \
bsd/unistd.h \
bsd/wchar.h \
# EOL
if ABI_ERR_H
nobase_include_HEADERS += \
bsd/err.h \
# EOL
endif
if ABI_BSD_GETOPT
nobase_include_HEADERS += \
bsd/getopt.h \
# EOL
endif
if ABI_MD5
nobase_include_HEADERS += \
bsd/md5.h \
# EOL
endif
if ABI_NLIST
nobase_include_HEADERS += \
bsd/nlist.h \
# EOL
endif
if ABI_READPASSPHRASE
nobase_include_HEADERS += \
bsd/readpassphrase.h \
# EOL
endif
if ABI_PWCACHE
nobase_include_HEADERS += \
bsd/grp.h \
bsd/pwd.h \
# EOL
endif
if ABI_STRINGLIST
nobase_include_HEADERS += \
bsd/stringlist.h \ bsd/stringlist.h \
# EOL
endif
if ABI_TIMECONV
nobase_include_HEADERS += \
bsd/timeconv.h \ bsd/timeconv.h \
# EOL bsd/unistd.h \
endif
if ABI_VIS
nobase_include_HEADERS += \
bsd/vis.h \ bsd/vis.h \
# EOL bsd/wchar.h \
endif $(nil)
do_header_subst = $(AM_V_GEN) $(SED) \
-e 's:^//\(.define LIBBSD_SYS_TIME_BITS\).*:\1 $(LIBBSD_SYS_TIME_BITS):' \
-e 's:^//\(.define LIBBSD_SYS_HAS_TIME64\).*:\1 $(LIBBSD_SYS_HAS_TIME64):' \
# EOL
install-data-hook:
$(do_header_subst) <$(DESTDIR)$(includedir)/bsd/sys/cdefs.h \
>$(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new
mv $(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new \
$(DESTDIR)$(includedir)/bsd/sys/cdefs.h

View File

@ -44,10 +44,8 @@
__BEGIN_DECLS __BEGIN_DECLS
int int
gid_from_group(const char *, gid_t *); gid_from_group(const char *, gid_t *);
#ifndef __APPLE__
const char * const char *
group_from_gid(gid_t, int); group_from_gid(gid_t, int);
#endif
__END_DECLS __END_DECLS
#endif #endif

View File

@ -24,10 +24,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _AIX
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
#include_next <md5.h> #include_next <md5.h>
#else #else
#include <md5.h> #include <md5.h>
#endif #endif
#endif

View File

@ -44,10 +44,8 @@
__BEGIN_DECLS __BEGIN_DECLS
int int
uid_from_user(const char *, uid_t *); uid_from_user(const char *, uid_t *);
#ifndef __APPLE__
const char * const char *
user_from_uid(uid_t, int); user_from_uid(uid_t, int);
#endif
__END_DECLS __END_DECLS
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2004-2024 Guillem Jover <guillem@hadrons.org> * Copyright © 2004-2005, 2009, 2011-2013 Guillem Jover <guillem@hadrons.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -44,18 +44,8 @@
#include <bsd/sys/cdefs.h> #include <bsd/sys/cdefs.h>
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#if defined(_AIX)
#include <stdarg.h>
#endif
__BEGIN_DECLS __BEGIN_DECLS
#if defined(_AIX)
int asprintf(char **strp, char const *fmt, ...)
__printflike(2, 3);
int vasprintf(char **strp, char const *fmt, va_list args)
__printflike(2, 0);
#endif
const char *fmtcheck(const char *, const char *); const char *fmtcheck(const char *, const char *);
/* XXX: The function requires cooperation from the system libc to store the /* XXX: The function requires cooperation from the system libc to store the

View File

@ -51,24 +51,16 @@
#include <stdint.h> #include <stdint.h>
__BEGIN_DECLS __BEGIN_DECLS
#if !defined(__APPLE__) && !defined(__sun)
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 36) || \
!defined(_DEFAULT_SOURCE)
uint32_t arc4random(void); uint32_t arc4random(void);
void arc4random_buf(void *_buf, size_t n);
uint32_t arc4random_uniform(uint32_t upper_bound);
#endif
void arc4random_stir(void); void arc4random_stir(void);
void arc4random_addrandom(unsigned char *dat, int datlen); void arc4random_addrandom(unsigned char *dat, int datlen);
#endif void arc4random_buf(void *_buf, size_t n);
uint32_t arc4random_uniform(uint32_t upper_bound);
int dehumanize_number(const char *str, int64_t *size); int dehumanize_number(const char *str, int64_t *size);
#if !defined(__APPLE__)
const char *getprogname(void); const char *getprogname(void);
void setprogname(const char *); void setprogname(const char *);
#endif
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort(void *base, size_t nmemb, size_t size, int mergesort(void *base, size_t nmemb, size_t size,
@ -80,9 +72,7 @@ int sradixsort(const unsigned char **base, int nmemb,
void *reallocf(void *ptr, size_t size); void *reallocf(void *ptr, size_t size);
#if !defined(__GLIBC__) || \ #if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 26) || \ (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
(__GLIBC_PREREQ(2, 26) && !__GLIBC_PREREQ(2, 29) && !defined(_GNU_SOURCE)) || \
(__GLIBC_PREREQ(2, 29) && !defined(_DEFAULT_SOURCE))
void *reallocarray(void *ptr, size_t nmemb, size_t size); void *reallocarray(void *ptr, size_t nmemb, size_t size);
#endif #endif
void *recallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size); void *recallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size);

View File

@ -41,19 +41,13 @@
#include <sys/types.h> #include <sys/types.h>
__BEGIN_DECLS __BEGIN_DECLS
#if !defined(__APPLE__) && \
(!defined(__GLIBC__) || !__GLIBC_PREREQ(2, 38) || !defined(_DEFAULT_SOURCE))
size_t strlcpy(char *dst, const char *src, size_t siz); size_t strlcpy(char *dst, const char *src, size_t siz);
size_t strlcat(char *dst, const char *src, size_t siz); size_t strlcat(char *dst, const char *src, size_t siz);
#endif
char *strnstr(const char *str, const char *find, size_t str_len); char *strnstr(const char *str, const char *find, size_t str_len);
#ifndef __APPLE__
void strmode(mode_t mode, char *str); void strmode(mode_t mode, char *str);
#endif
#if !defined(__GLIBC__) || \ #if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 25) || \ (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
!defined(_DEFAULT_SOURCE)
void explicit_bzero(void *buf, size_t len); void explicit_bzero(void *buf, size_t len);
#endif #endif
__END_DECLS __END_DECLS

View File

@ -37,9 +37,6 @@
#ifndef __is_identifier #ifndef __is_identifier
#define __is_identifier(x) 1 #define __is_identifier(x) 1
#endif #endif
#ifndef __has_builtin
#define __has_builtin(x) !__is_identifier(x)
#endif
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
/* /*
@ -86,10 +83,6 @@
#define _SYS_CDEFS_H #define _SYS_CDEFS_H
#endif #endif
/* Define the ABI for the current system. */
//#define LIBBSD_SYS_TIME_BITS 0
//#define LIBBSD_SYS_HAS_TIME64 0
#define LIBBSD_CONCAT(x, y) x ## y #define LIBBSD_CONCAT(x, y) x ## y
#define LIBBSD_STRING(x) #x #define LIBBSD_STRING(x) #x
@ -189,7 +182,7 @@
* require it. * require it.
*/ */
#ifndef __offsetof #ifndef __offsetof
# if LIBBSD_GCC_VERSION >= 0x0401 || __has_builtin(__builtin_offsetof) # 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

View File

@ -58,17 +58,4 @@ time_t _long_to_time(long tlong);
int _time_to_int(time_t t); int _time_to_int(time_t t);
time_t _int_to_time(int tint); time_t _int_to_time(int tint);
#if LIBBSD_SYS_TIME_BITS == 32 && LIBBSD_SYS_HAS_TIME64
#if defined _TIME_BITS && _TIME_BITS == 64
time_t LIBBSD_REDIRECT(_time32_to_time, (int32_t t32), _time32_to_time_time64);
int32_t LIBBSD_REDIRECT(_time_to_time32, (time_t t), _time_to_time32_time64);
time_t LIBBSD_REDIRECT(_time64_to_time, (int64_t t64), _time64_to_time_time64);
int64_t LIBBSD_REDIRECT(_time_to_time64, (time_t t), _time_to_time64_time64);
long LIBBSD_REDIRECT(_time_to_long, (time_t t), _time_to_long_time64);
time_t LIBBSD_REDIRECT(_long_to_time, (long tlong), _long_to_time_time64);
int LIBBSD_REDIRECT(_time_to_int, (time_t t), _time_to_int_time64);
time_t LIBBSD_REDIRECT(_int_to_time, (int tint), _int_to_time_time64);
#endif
#endif
#endif /* LIBBSD_TIMECONV_H */ #endif /* LIBBSD_TIMECONV_H */

View File

@ -47,7 +47,6 @@
#endif #endif
__BEGIN_DECLS __BEGIN_DECLS
#if !defined(__APPLE__)
extern int optreset; extern int optreset;
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
@ -56,16 +55,11 @@ extern int optreset;
#endif #endif
int bsd_getopt(int argc, char * const argv[], const char *shortopts); int bsd_getopt(int argc, char * const argv[], const char *shortopts);
#endif
mode_t getmode(const void *set, mode_t mode); mode_t getmode(const void *set, mode_t mode);
void *setmode(const char *mode_str); void *setmode(const char *mode_str);
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 34) || \
!defined(_DEFAULT_SOURCE)
void closefrom(int lowfd); void closefrom(int lowfd);
#endif
/* Compatibility with sendmail implementations. */ /* Compatibility with sendmail implementations. */
#define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e)) #define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))

View File

@ -93,7 +93,7 @@
* existing one in OpenBSD and Freedesktop's libbsd (the former having existed * existing one in OpenBSD and Freedesktop's libbsd (the former having existed
* for over ten years). Despite this incompatibility being reported during * for over ten years). Despite this incompatibility being reported during
* development (see http://gnats.netbsd.org/44977) they still shipped it. * development (see http://gnats.netbsd.org/44977) they still shipped it.
* Even more unfortunately FreeBSD and later macOS picked up this incompatible * Even more unfortunately FreeBSD and later MacOS picked up this incompatible
* implementation. * implementation.
* *
* Provide both implementations and default for now on the historical one to * Provide both implementations and default for now on the historical one to

View File

@ -50,10 +50,8 @@
__BEGIN_DECLS __BEGIN_DECLS
wchar_t *fgetwln(FILE *stream, size_t *len); wchar_t *fgetwln(FILE *stream, size_t *len);
#if !defined(__APPLE__)
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size); size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size); size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
#endif
__END_DECLS __END_DECLS
#endif #endif

View File

@ -1,7 +1,7 @@
# Copyright © 2021 Guillem Jover <guillem@hadrons.org> # Copyright © 2021 Guillem Jover <guillem@hadrons.org>
# LIBBSD_CHECK_COMPILER_FLAG # LIBBSD_CHECK_COMPILER_FLAG
# -------------------------- # -------------------------
AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [ AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1]) AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1])
AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [ AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [
@ -22,83 +22,3 @@ AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
]) ])
AS_VAR_POPDEF([libbsd_varname_cache]) AS_VAR_POPDEF([libbsd_varname_cache])
]) ])
# LIBBSD_HAS_GNU_INIT_ARRAY
# -------------------------
AC_DEFUN([LIBBSD_HAS_GNU_INIT_ARRAY], [
AC_CACHE_CHECK([for GNU .init_array section support],
[libbsd_cv_gnu_init_array_support], [
AC_RUN_IFELSE([
AC_LANG_SOURCE([[
static int rc = 1;
static void init(int argc) { if (argc == 1) rc = 0; }
void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
int main() { return rc; }
]])
], [
libbsd_cv_gnu_init_array_support=yes
], [
libbsd_cv_gnu_init_array_support=no
], [
AC_PREPROC_IFELSE([
AC_LANG_SOURCE([[
/* Look for a known libc that supports .init_array with the GNU extension
* to pass main() arguments to the init functions. */
#include <stdlib.h>
#if defined __GLIBC_PREREQ
# if __GLIBC_PREREQ(2, 4)
/* glibc supports GNU .init_array since 2.4. */
# else
# error glibc does not support GNU .init_array
# endif
#else
/*
* Basic SysV ABI .init_array support, init functions do not get arguments:
* - Bionic since its inception.
* - uClibc since 0.9.29.
*/
# error unknown whether libc supports GNU .init_array
#endif
]])
], [
libbsd_cv_gnu_init_array_support=yes
], [
libbsd_cv_gnu_init_array_support=no
])
])
])
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
[test "$libbsd_cv_gnu_init_array_support" = yes])
])
# LIBBSD_SELECT_API(name, desc)
# -----------------
AC_DEFUN([LIBBSD_SELECT_API], [
AS_IF([test -z "$AS_TR_SH([api_$1])"], [
AC_MSG_ERROR([missing API selection for $1])
], [test "$AS_TR_SH([api_$1])" = "unknown"], [
AC_MSG_ERROR([unknown ABI selection for $1])
], [test "$AS_TR_SH([api_$1])" = "yes"], [
AC_DEFINE(AS_TR_CPP([LIBBSD_API_$1]), [1], [Provide API for $2])
], [
AC_DEFINE(AS_TR_CPP([LIBBSD_API_$1]), [0])
])
AM_CONDITIONAL(AS_TR_CPP([API_$1]),
[test "x$AS_TR_SH([api_$1])" = "xyes"])
])
# LIBBSD_SELECT_ABI(name, desc)
# -----------------
AC_DEFUN([LIBBSD_SELECT_ABI], [
AS_IF([test -z "$AS_TR_SH([abi_$1])"], [
AC_MSG_ERROR([missing ABI selection for $1])
], [test "$AS_TR_SH([abi_$1])" = "unknown"], [
AC_MSG_ERROR([unknown ABI selection for $1])
], [test "$AS_TR_SH([abi_$1])" = "yes"], [
AC_DEFINE(AS_TR_CPP([LIBBSD_ABI_$1]), [1], [Provide ABI for $2])
], [
AC_DEFINE(AS_TR_CPP([LIBBSD_ABI_$1]), [0])
])
AM_CONDITIONAL(AS_TR_CPP([ABI_$1]),
[test "x$AS_TR_SH([abi_$1])" = "xyes"])
])

View File

@ -1,57 +0,0 @@
# Copyright © 2011-2024 Guillem Jover <guillem@hadrons.org>
# LIBBSD_CHECK_PROGNAME
# ---------------------
AC_DEFUN([LIBBSD_CHECK_PROGNAME], [
AC_MSG_CHECKING([for program_invocation_short_name])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#include <errno.h>
]], [[
const char *p = program_invocation_short_name;
]])
], [
AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
[Define to 1 if you have program_invocation_short_name])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
AC_MSG_CHECKING([for __progname])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#include <stdio.h>
extern char *__progname;
]], [[
printf("%s", __progname);
]])
], [
AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
])
# LIBBSD_CHECK_REGISTER_ATFORK
# ----------------------------
AC_DEFUN([LIBBSD_CHECK_REGISTER_ATFORK], [
AC_MSG_CHECKING([for __register_atfork])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#include <stddef.h>
extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
]], [[
__register_atfork(NULL, NULL, NULL, __dso_handle);
]])
], [
AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
[Define to 1 if you have __register_atfork])
AC_MSG_RESULT([yes])
], [
LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
AC_MSG_RESULT([no])
])
])

View File

@ -1,61 +0,0 @@
# Copyright © 2024 Guillem Jover <guillem@hadrons.org>
# LIBBSD_SYS_TIME64
# -----------------
# Check for availability of time64 support.
AC_DEFUN([LIBBSD_SYS_TIME64], [
# Check the default time_t size.
AC_CHECK_SIZEOF([time_t], [], [[
#undef _TIME_BITS
#include <time.h>
]])
AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
libbsd_sys_time_bits=64
], [
libbsd_sys_time_bits=32
])
AC_DEFINE_UNQUOTED([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits],
[The number of bits for the default system time_t ABI])
AC_SUBST([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits])
AS_UNSET([ac_cv_sizeof_time_t])
AM_CONDITIONAL([LIBBSD_SYS_IS_TIME32], [test "$libbsd_sys_time_bits" -eq 32])
# Check the whether the system supports 64-bit time_t.
AC_CHECK_SIZEOF([time_t], [], [[
#define _FILE_OFFSET_BITS 64
#define _TIME_BITS 64
#include <time.h>
]])
AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
libbsd_sys_has_time64=1
], [
libbsd_sys_has_time64=0
])
AC_DEFINE_UNQUOTED([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64],
[Enable if the system supports 64-bit time_t])
AC_SUBST([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64])
AM_CONDITIONAL([LIBBSD_SYS_HAS_TIME64], [test "$libbsd_sys_has_time64" -eq 1])
AS_IF([test "$libbsd_sys_time_bits" -eq 32 && \
test "$libbsd_sys_has_time64" -eq 1], [
abi_time64=yes
], [
abi_time64=no
])
LIBBSD_SELECT_ABI([time64], [explicit time64 time_t support])
AC_CHECK_SIZEOF([off_t], [], [[
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
]])
AS_IF([test $ac_cv_sizeof_off_t = 8], [
libbsd_sys_has_lfs=1
], [
libbsd_sys_has_lfs=0
])
AS_IF([test $libbsd_sys_has_lfs -eq 1 && \
test $libbsd_sys_time_bits -eq 32 && \
test $ac_cv_sizeof_time_t -eq 8], [
AC_DEFINE([_TIME_BITS], [64], [Enable 64-bit time_t support])
])
])

View File

@ -1,27 +0,0 @@
# Copyright © 2019, 2022 Guillem Jover <guillem@hadrons.org>
# LIBBSD_LINKER_VERSION_SCRIPT
# ----------------------------
AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
AC_CACHE_CHECK([if ld supports --version-script flag],
[libbsd_cv_version_script], [
echo "{ global: symbol; local: *; };" >conftest.map
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
extern int symbol(void);
int symbol(void) { return 0; }
]], [[
]])
], [
libbsd_cv_version_script=yes
], [
libbsd_cv_version_script=no
])
LDFLAGS="$save_LDFLAGS"
rm -f conftest.map
])
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
[test "x$libbsd_cv_version_script" = "xyes"])
])

View File

@ -2,16 +2,16 @@
EXTRA_DIST = \ EXTRA_DIST = \
mdX.3bsd \ mdX.3bsd \
# EOL $(nil)
CLEANFILES = \ CLEANFILES = \
md5.3bsd \ md5.3bsd \
# EOL $(nil)
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
md5.3bsd: $(srcdir)/mdX.3bsd md5.3bsd: $(srcdir)/mdX.3bsd
$(AM_V_GEN) $(SED) $(SED_MD5_SUBST) $< >$@ $(AM_V_GEN) $(SED) $(SED_MD5_SUBST) $< > $@
dist_man_MANS = \ dist_man_MANS = \
LIST_CLASS_ENTRY.3bsd \ LIST_CLASS_ENTRY.3bsd \
@ -141,6 +141,13 @@ dist_man_MANS = \
TAILQ_PREV.3bsd \ TAILQ_PREV.3bsd \
TAILQ_REMOVE.3bsd \ TAILQ_REMOVE.3bsd \
TAILQ_SWAP.3bsd \ TAILQ_SWAP.3bsd \
TIMESPEC_TO_TIMEVAL.3bsd \
TIMEVAL_TO_TIMESPEC.3bsd \
arc4random.3bsd \
arc4random_addrandom.3bsd \
arc4random_buf.3bsd \
arc4random_stir.3bsd \
arc4random_uniform.3bsd \
be16dec.3bsd \ be16dec.3bsd \
be16enc.3bsd \ be16enc.3bsd \
be32dec.3bsd \ be32dec.3bsd \
@ -159,6 +166,27 @@ dist_man_MANS = \
bitstr_size.3bsd \ bitstr_size.3bsd \
bitstring.3bsd \ bitstring.3bsd \
byteorder.3bsd \ byteorder.3bsd \
closefrom.3bsd \
dehumanize_number.3bsd \
errc.3bsd \
expand_number.3bsd \
explicit_bzero.3bsd \
fgetln.3bsd \
fgetwln.3bsd \
flopen.3bsd \
freezero.3bsd \
fmtcheck.3bsd \
fparseln.3bsd \
fpurge.3bsd \
funopen.3bsd \
getbsize.3bsd \
getmode.3bsd \
getpeereid.3bsd \
getprogname.3bsd \
gid_from_group.3bsd \
group_from_gid.3bsd \
heapsort.3bsd \
humanize_number.3bsd \
le16dec.3bsd \ le16dec.3bsd \
le16enc.3bsd \ le16enc.3bsd \
le32dec.3bsd \ le32dec.3bsd \
@ -166,270 +194,61 @@ dist_man_MANS = \
le64dec.3bsd \ le64dec.3bsd \
le64enc.3bsd \ le64enc.3bsd \
libbsd.7 \ libbsd.7 \
queue.3bsd \
timeradd.3bsd \
timerclear.3bsd \
timercmp.3bsd \
timerisset.3bsd \
timersub.3bsd \
timespecadd.3bsd \
timespecclear.3bsd \
timespeccmp.3bsd \
timespecisset.3bsd \
timespecsub.3bsd \
tree.3bsd \
# EOL
if API_TIME_MACROS
dist_man_MANS += \
TIMESPEC_TO_TIMEVAL.3bsd \
TIMEVAL_TO_TIMESPEC.3bsd \
# EOL
endif
if ABI_ACCMODE
dist_man_MANS += \
getmode.3bsd \
setmode.3bsd \
# EOL
endif
if ABI_ARC4RANDOM
dist_man_MANS += \
arc4random.3bsd \
arc4random_addrandom.3bsd \
arc4random_buf.3bsd \
arc4random_stir.3bsd \
arc4random_uniform.3bsd \
# EOL
endif
if ABI_CLOSEFROM
dist_man_MANS += \
closefrom.3bsd \
# EOL
endif
if ABI_ERRC
dist_man_MANS += \
errc.3bsd \
verrc.3bsd \
vwarnc.3bsd \
warnc.3bsd \
# EOL
endif
if ABI_EXPAND_NUMBER
dist_man_MANS += \
expand_number.3bsd \
# EOL
endif
if ABI_EXPLICIT_BZERO
dist_man_MANS += \
explicit_bzero.3bsd \
# EOL
endif
if ABI_FGETLN
dist_man_MANS += \
fgetln.3bsd \
fgetwln.3bsd \
fparseln.3bsd \
# EOL
endif
if ABI_FLOPEN
dist_man_MANS += \
flopen.3bsd \
# EOL
endif
if ABI_FMTCHECK
dist_man_MANS += \
fmtcheck.3bsd \
# EOL
endif
if ABI_FPURGE
dist_man_MANS += \
fpurge.3bsd \
# EOL
endif
if ABI_FREEZERO
dist_man_MANS += \
freezero.3bsd \
# EOL
endif
if ABI_FUNOPEN
dist_man_MANS += \
funopen.3bsd \
# EOL
endif
if ABI_GETBSIZE
dist_man_MANS += \
getbsize.3bsd \
# EOL
endif
if ABI_GETPEEREID
dist_man_MANS += \
getpeereid.3bsd \
# EOL
endif
if ABI_HUMANIZE_NUMBER
dist_man_MANS += \
dehumanize_number.3bsd \
humanize_number.3bsd \
# EOL
endif
if ABI_MD5
dist_man_MANS += \
md5.3bsd \ md5.3bsd \
# EOL mergesort.3bsd \
endif
if ABI_NLIST
dist_man_MANS += \
nlist.3bsd \ nlist.3bsd \
# EOL
endif
if ABI_PIDFILE
dist_man_MANS += \
pidfile.3bsd \ pidfile.3bsd \
pidfile_close.3bsd \ pidfile_close.3bsd \
pidfile_open.3bsd \ pidfile_open.3bsd \
pidfile_remove.3bsd \ pidfile_remove.3bsd \
pidfile_write.3bsd \ pidfile_write.3bsd \
# EOL pwcache.3bsd \
endif queue.3bsd \
radixsort.3bsd \
if ABI_PROCTITLE readpassphrase.3bsd \
dist_man_MANS += \ reallocarray.3bsd \
reallocf.3bsd \
recallocarray.3bsd \
setmode.3bsd \
setproctitle.3bsd \ setproctitle.3bsd \
setproctitle_init.3bsd \ setproctitle_init.3bsd \
# EOL
endif
if ABI_PROGNAME
dist_man_MANS += \
getprogname.3bsd \
setprogname.3bsd \ setprogname.3bsd \
# EOL
endif
if ABI_PWCACHE
dist_man_MANS += \
pwcache.3bsd \
gid_from_group.3bsd \
uid_from_user.3bsd \
# EOL
if ABI_NAME_FROM_ID
dist_man_MANS += \
group_from_gid.3bsd \
user_from_uid.3bsd \
# EOL
endif
endif
if ABI_READPASSPHRASE
dist_man_MANS += \
readpassphrase.3bsd \
# EOL
endif
if ABI_REALLOCARRAY
dist_man_MANS += \
reallocarray.3bsd \
# EOL
endif
if ABI_REALLOCF
dist_man_MANS += \
reallocf.3bsd \
# EOL
endif
if ABI_RECALLOCARRAY
dist_man_MANS += \
recallocarray.3bsd \
# EOL
endif
if ABI_SORT
dist_man_MANS += \
heapsort.3bsd \
mergesort.3bsd \
radixsort.3bsd \
sradixsort.3bsd \
# EOL
endif
if ABI_STRINGLIST
dist_man_MANS += \
sl_add.3bsd \ sl_add.3bsd \
sl_delete.3bsd \ sl_delete.3bsd \
sl_find.3bsd \ sl_find.3bsd \
sl_free.3bsd \ sl_free.3bsd \
sl_init.3bsd \ sl_init.3bsd \
sradixsort.3bsd \
stringlist.3bsd \ stringlist.3bsd \
# EOL
endif
if ABI_STRL
dist_man_MANS += \
strlcat.3bsd \ strlcat.3bsd \
strlcpy.3bsd \ strlcpy.3bsd \
# EOL
endif
if ABI_STRMODE
dist_man_MANS += \
strmode.3bsd \ strmode.3bsd \
# EOL
endif
if ABI_STRNSTR
dist_man_MANS += \
strnstr.3bsd \ strnstr.3bsd \
# EOL
endif
if ABI_STRTOX
dist_man_MANS += \
strtoi.3bsd \
strtou.3bsd \
# EOL
endif
if ABI_STRTONUM
dist_man_MANS += \
strtonum.3bsd \
# EOL
endif
if ABI_VIS
dist_man_MANS += \
strnunvis.3bsd \ strnunvis.3bsd \
strnvis.3bsd \ strnvis.3bsd \
strtoi.3bsd \
strtonum.3bsd \
strtou.3bsd \
strunvis.3bsd \ strunvis.3bsd \
strvis.3bsd \ strvis.3bsd \
strvisx.3bsd \ strvisx.3bsd \
timeradd.3bsd \
timerclear.3bsd \
timercmp.3bsd \
timerisset.3bsd \
timersub.3bsd \
timespec.3bsd \
timespecadd.3bsd \
timespecclear.3bsd \
timespeccmp.3bsd \
timespecisset.3bsd \
timespecsub.3bsd \
timeval.3bsd \
tree.3bsd \
uid_from_user.3bsd \
unvis.3bsd \ unvis.3bsd \
user_from_uid.3bsd \
vis.3bsd \ vis.3bsd \
# EOL
endif
if ABI_WCSL
dist_man_MANS += \
wcslcat.3bsd \ wcslcat.3bsd \
wcslcpy.3bsd \ wcslcpy.3bsd \
# EOL $(nil)
endif

View File

@ -1,100 +1 @@
.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $ .so man3/timeval.3bsd
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jukka Ruohonen.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 12, 2011
.Dt TIMEVAL_TO_TIMESPEC 3bsd
.Os
.Sh NAME
.Nm TIMEVAL_TO_TIMESPEC ,
.Nm TIMESPEC_TO_TIMEVAL
.Nd time structures conversion macros
.Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd
.Sh SYNOPSIS
.In sys/time.h
(See
.Xr libbsd 7
for include usage.)
.Ft void
.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
.Ft void
.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
.Sh DESCRIPTION
The
.Va timeval
structure represents elapsed time, in whole seconds,
and the rest of the elapsed time in microseconds.
.Pp
The
.Va timespec
structure represents elapsed time, in whole seconds,
and the rest of the elapsed time in nanoseconds.
.Pp
A microsecond is equal to one millionth of a second,
1000 nanoseconds, or 1/1000 milliseconds.
To ease the conversions, the macros
.Fn TIMEVAL_TO_TIMESPEC
and
.Fn TIMESPEC_TO_TIMEVAL
can be used to convert between
.Em struct timeval
and
.Em struct timespec .
.Sh EXAMPLES
It can be stressed that the traditional
.Tn UNIX
.Va timeval
and
.Va timespec
structures represent elapsed time, measured by the system clock.
The following sketch implements a function suitable
for use in a context where the
.Va timespec
structure is required for a conditional timeout:
.Bd -literal -offset indent
static void
example(struct timespec *spec, time_t minutes)
{
struct timeval elapsed;
(void)gettimeofday(&elapsed, NULL);
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
/* Add the offset for timeout in minutes. */
spec->tv_sec = spec->tv_sec + minutes * 60;
}
.Ed
.Pp
A better alternative would use the more precise
.Xr clock_gettime 2 .
.Sh SEE ALSO
.Xr timeradd 3bsd

View File

@ -1 +1 @@
.so man3/TIMESPEC_TO_TIMEVAL.3bsd .so man3/timeval.3bsd

View File

@ -1,11 +1,8 @@
.\" $NetBSD: arc4random.3,v 1.21 2016/07/15 21:19:19 wiz Exp $ .\" $OpenBSD: arc4random.3,v 1.34 2014/07/19 16:11:16 naddy Exp $
.\" .\"
.\" Copyright (c) 2014 The NetBSD Foundation, Inc. .\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
.\" All rights reserved. .\" All rights reserved.
.\" .\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Taylor R. Campbell.
.\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" modification, are permitted provided that the following conditions
.\" are met: .\" are met:
@ -14,29 +11,35 @@
.\" 2. Redistributions in binary form must reproduce the above copyright .\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the .\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution. .\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by Niels Provos.
.\" 4. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\" .\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd November 16, 2014 .\" Manual page, using -mandoc macros
.Dt arc4random 3bsd .\"
.Dd $Mdocdate: July 19 2014 $
.Dt ARC4RANDOM 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm arc4random , .Nm arc4random ,
.Nm arc4random_uniform ,
.Nm arc4random_buf , .Nm arc4random_buf ,
.Nm arc4random_uniform ,
.Nm arc4random_stir , .Nm arc4random_stir ,
.Nm arc4random_addrandom .Nm arc4random_addrandom
.Nd 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] .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
@ -48,208 +51,83 @@
for include usage.) for include usage.)
.Ft uint32_t .Ft uint32_t
.Fn arc4random "void" .Fn arc4random "void"
.Ft uint32_t
.Fn arc4random_uniform "uint32_t bound"
.Ft void .Ft void
.Fn arc4random_buf "void *buf" "size_t len" .Fn arc4random_buf "void *buf" "size_t nbytes"
.Ft uint32_t
.Fn arc4random_uniform "uint32_t upper_bound"
.Ft void .Ft void
.Fn arc4random_stir "void" .Fn arc4random_stir "void"
.Ft void .Ft void
.Fn arc4random_addrandom "unsigned char *buf" "int len" .Fn arc4random_addrandom "unsigned char *dat" "int datlen"
.Sh DESCRIPTION .Sh DESCRIPTION
The This family of functions provides higher quality data than those
.Nm described in
family of functions provides a cryptographic pseudorandom number
generator automatically seeded from the system entropy pool and safe to
use from multiple threads.
.Nm
is designed to prevent an adversary from guessing outputs,
unlike
.Xr rand 3
and
.Xr random 3 ,
and is faster and more convenient than reading from
.Pa /dev/urandom
directly.
.Pp
.Fn arc4random
returns an integer in [0, 2^32) chosen independently with uniform
distribution.
.Pp
.Fn arc4random_uniform
returns an integer in [0,
.Fa bound )
chosen independently with uniform distribution.
.Pp
.Fn arc4random_buf
stores
.Fa len
bytes into the memory pointed to by
.Fa buf ,
each byte chosen independently from [0, 256) with uniform
distribution.
.Pp
.Fn arc4random_stir
draws entropy from the operating system and incorporates it into the
library's PRNG state to influence future outputs.
.Pp
.Fn arc4random_addrandom
incorporates
.Fa len
bytes, which must be nonnegative, from the buffer
.Fa buf ,
into the library's PRNG state to influence future outputs.
.Pp
It is not necessary for an application to call
.Fn arc4random_stir
or
.Fn arc4random_addrandom
before calling other
.Nm
functions.
The first call to any
.Nm
function will initialize the PRNG state unpredictably from the system
entropy pool.
.Sh SECURITY MODEL
The
.Nm
functions provide the following security properties against three
different classes of attackers, assuming enough entropy is provided by
the operating system:
.Bl -enum -offset abcd
.It
An attacker who has seen some outputs of any of the
.Nm
functions cannot predict past or future unseen outputs.
.It
An attacker who has seen the library's PRNG state in memory cannot
predict past outputs.
.It
An attacker who has seen one process's PRNG state cannot predict past
or future outputs in other processes, particularly its parent or
siblings.
.El
.Pp
One
.Sq output
means the result of any single request to an
.Nm
function, no matter how short it is.
.Pp
The second property is sometimes called
.Sq forward secrecy ,
.Sq backtracking resistance ,
or
.Sq key erasure after each output .
.Sh IMPLEMENTATION NOTES
The
.Nm
functions are currently implemented using the ChaCha20 pseudorandom
function family.
For any 32-byte string
.Fa s ,
.Pf ChaCha20_ Fa s
is a function from 16-byte strings to 64-byte strings.
It is conjectured that if
.Fa s
is chosen with uniform distribution, then the distribution on
.Pf ChaCha20_ Fa s
is indistinguishable to a computationally bounded adversary from a
uniform distribution on all functions from 16-byte strings to 64-byte
strings.
.Pp
The PRNG state is a 32-byte ChaCha20 key
.Fa s .
Each request to
an
.Nm
function
.Bl -bullet -offset abcd -compact
.It
computes the 64-byte quantity
.Fa x
=
.Pf ChaCha20_ Fa s Ns Pq 0 ,
.It
splits
.Fa x
into two 32-byte quantities
.Fa s'
and
.Fa k ,
.It
replaces
.Fa s
by
.Fa s' ,
and
.It
uses
.Fa k
as output.
.El
.Pp
.Fn arc4random
yields the first four bytes of
.Fa k
as output directly.
.Fn arc4random_buf
either yields up to 32 bytes of
.Fa k
as output directly, or, for longer
requests, uses
.Fa k
as a ChaCha20 key and yields the concatenation
.Pf ChaCha20_ Fa k Ns Pq 0
||
.Pf ChaCha20_ Fa k Ns Pq 1
|| ... as output.
.Fn arc4random_uniform
repeats
.Fn arc4random
until it obtains an integer in [2^32 %
.Fa bound ,
2^32), and reduces that modulo
.Fa bound .
.Pp
The PRNG state is per-thread, unless memory allocation fails inside the
library, in which case some threads may share global PRNG state with a
mutex.
The global PRNG state is zeroed on fork in the parent via
.Xr pthread_atfork 3 ,
and the per-thread PRNG state is zeroed on fork in the child via
.Xr minherit 2
with
.Dv MAP_INHERIT_ZERO ,
so that the child cannot reuse or see the parent's PRNG state.
The PRNG state is reseeded automatically from the system entropy pool
on the first use of an
.Nm
function after zeroing.
.Pp
The first use of an
.Nm
function may abort the process in the highly unlikely event that
library initialization necessary to implement the security model fails.
Additionally,
.Fn arc4random_stir
and
.Fn arc4random_addrandom
may abort the process in the highly unlikely event that the operating
system fails to provide entropy.
.Sh SEE ALSO
.Xr rand 3 , .Xr rand 3 ,
.Xr random 3 , .Xr random 3 ,
.Xr rnd 4 , and
.Xr cprng 9 .Xr rand48 3 .
.Rs .Pp
.%A Daniel J. Bernstein Use of these functions is encouraged for almost all random number
.%T ChaCha, a variant of Salsa20 consumption because the other interfaces are deficient in either
.%D 2008-01-28 quality, portability, standardization, or availability.
.%O Document ID: 4027b5256e17b9796842e6d0f68b0b5e These functions can be called in almost all coding environments,
.%U http://cr.yp.to/papers.html#chacha including
.Re .Xr pthreads 3
and
.Xr chroot 2 .
.Pp
High quality 32-bit pseudo-random numbers are generated very quickly.
On each call, a cryptographic pseudo-random number generator is used
to generate a new result.
One data pool is used for all consumers in a process, so that consumption
under program flow can act as additional stirring.
The subsystem is re-seeded from the kernel random number subsystem using
.Xr getentropy 2
on a regular basis, and also upon
.Xr fork 2 .
.Pp
The
.Fn arc4random
function returns a single 32-bit value.
.Pp
The
.Fn arc4random_buf
function fills the region
.Fa buf
of length
.Fa nbytes
with random data.
.Pp
.Fn arc4random_uniform
will return a single 32-bit value, uniformly distributed but less than
.Fa upper_bound .
This is recommended over constructions like
.Dq Li arc4random() % upper_bound
as it avoids "modulo bias" when the upper bound is not a power of two.
In the worst case, this function may consume multiple iterations
to ensure uniformity; see the source code to understand the problem
and solution.
.Pp
The
.Fn arc4random_stir
function reads data from
.Xr getentropy 2
and uses it to re-seed the subsystem via
.Fn arc4random_addrandom .
.Pp
There is no need to call
.Fn arc4random_stir
before using
.Fn arc4random
functions family, since
they automatically initialize themselves.
.Sh RETURN VALUES
These functions are always successful, and no return value is
reserved to indicate an error.
.Sh SEE ALSO
.Xr rand 3 ,
.Xr rand48 3 ,
.Xr random 3
.Sh HISTORY .Sh HISTORY
These functions first appeared in These functions first appeared in
.Ox 2.1 , .Ox 2.1 ,
@ -257,85 +135,12 @@ These functions first appeared in
.Nx 1.6 , .Nx 1.6 ,
and and
.Dx 1.0 . .Dx 1.0 .
The functions
.Fn arc4random ,
.Fn arc4random_buf
and
.Fn arc4random_uniform
appeared in glibc 2.36.
.Sh BUGS
There is no way to get deterministic, reproducible results out of
.Nm
for testing purposes.
.Pp .Pp
The name The original version of this random number generator used the
.Sq arc4random RC4 (also known as ARC4) algorithm.
was chosen for hysterical raisins -- it was originally implemented In
using the RC4 stream cipher, which has been known since shortly after .Ox 5.5
it was published in 1994 to have observable biases in the output, and it was replaced with the ChaCha20 cipher, and it may be replaced
is now known to be broken badly enough to admit practical attacks in again in the future as cryptographic techniques advance.
the real world. A good mnemonic is
.\" Bob Jenkins, sci.crypt post dated 1994-09-16, message-id .Dq A Replacement Call for Random .
.\" <359qjg$55v$1@mhadg.production.compuserve.com>,
.\" https://groups.google.com/d/msg/sci.crypt/JsO3xEATGFA/-wO4ttv7BCYJ
.\"
.\" Andrew Roos, `A Class of Weak Keys in the RC4 Stream Cipher',
.\" sci.crypt posts dated 1995-09-22, message-ids
.\" <43u1eh$1j3@hermes.is.co.za> and <44ebge$llf@hermes.is.co.za>.
.\"
.\" Paul Crowley, `Small bias in RC4 experimentally verified', March
.\" 1998, http://www.ciphergoth.org/crypto/rc4/
Unfortunately, the library found widespread adoption and the name stuck
before anyone recognized that it was silly.
.Pp
The signature of
.Fn arc4random_addrandom
is silly.
There is no reason to require casts or accept negative lengths:
it should take a
.Vt void *
buffer and a
.Vt size_t
length.
But it's too late to change that now.
.Pp
.Fn arc4random_uniform
does not help to choose integers in [0,
.Fa n )
uniformly at random when
.Fa n
> 2^32.
.Pp
The security model of
.Nm
is stronger than many applications need, and stronger than other
operating systems provide.
For example, applications encrypting messages with random, but not
secret, initialization vectors need only prevent an adversary from
guessing future outputs, since past outputs will have been published
already.
.Pp
On the one hand,
.Nm
could be marginally faster if it were not necessary to prevent an
adversary who sees the state from predicting past outputs.
On the other hand, there are applications in the wild that use
.Nm
to generate key material, such as OpenSSH, so for the sake of
.Nx
users it would be imprudent to weaken the security model.
On the third hand, relying on the security model of
.Nm
in
.Nx
may lead you to an unpleasant surprise on another operating system
whose implementation of
.Nm
has a weaker security model.
.Pp
One may be tempted to create new APIs to accommodate different
security models and performance constraints without unpleasant
surprises on different operating systems.
This should not be done lightly, though, because there are already too
many different choices, and too many opportunities for programmers to
reach for one and pick the wrong one.

View File

@ -31,7 +31,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd July 19, 1993 .Dd July 19, 1993
.Dt bitstring 3bsd .Dt BITSTRING 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm bit_alloc , .Nm bit_alloc ,

View File

@ -25,7 +25,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd April 29, 2002 .Dd April 29, 2002
.Dt byteorder 3bsd .Dt BYTEORDER 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec , .Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,

View File

@ -26,7 +26,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd June 12, 2009 .Dd June 12, 2009
.Dt closefrom 3bsd .Dt CLOSEFROM 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm closefrom .Nm closefrom
@ -51,17 +51,8 @@ from the per-process object reference table.
Any errors encountered while closing file descriptors are ignored. Any errors encountered while closing file descriptors are ignored.
.Sh SEE ALSO .Sh SEE ALSO
.Xr close 2 .Xr close 2
.Sh STANDARDS
.Fn closefrom
is a
.Bx
and Solaris extension.
.Sh HISTORY .Sh HISTORY
The The
.Fn closefrom .Fn closefrom
function first appeared in Solaris 9, function first appeared in
.Ox 3.5 , .Fx 8.0 .
.Dx 1.2 ,
.Nx 3.0 ,
.Fx 8.0
and glibc 2.34.

View File

@ -28,7 +28,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd $Mdocdate: April 23 2014 $ .Dd $Mdocdate: April 23 2014 $
.Dt errc 3bsd .Dt ERRC 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm errc , .Nm errc ,

View File

@ -26,7 +26,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd August 15, 2010 .Dd August 15, 2010
.Dt expand_number 3bsd .Dt EXPAND_NUMBER 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm expand_number .Nm expand_number

View File

@ -30,7 +30,7 @@
.\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $ .\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
.\" .\"
.Dd $Mdocdate: January 22 2014 $ .Dd $Mdocdate: January 22 2014 $
.Dt explicit_bzero 3bsd .Dt EXPLICIT_BZERO 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm explicit_bzero .Nm explicit_bzero

View File

@ -29,7 +29,7 @@
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $ .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
.\" .\"
.Dd April 19, 1994 .Dd April 19, 1994
.Dt fgetln 3bsd .Dt FGETLN 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm fgetln .Nm fgetln

View File

@ -29,7 +29,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd July 16, 2004 .Dd July 16, 2004
.Dt fgetwln 3bsd .Dt FGETWLN 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm fgetwln .Nm fgetwln

View File

@ -26,7 +26,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd July 28, 2017 .Dd July 28, 2017
.Dt flopen 3bsd .Dt FLOPEN 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm flopen , .Nm flopen ,

View File

@ -27,7 +27,7 @@
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd June 14, 2014 .Dd June 14, 2014
.Dt fmtcheck 3bsd .Dt FMTCHECK 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm fmtcheck .Nm fmtcheck

View File

@ -23,7 +23,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd November 30, 2002 .Dd November 30, 2002
.Dt fparseln 3bsd .Dt FPARSELN 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm fparseln .Nm fparseln
@ -150,6 +150,4 @@ if it runs out of memory.
The The
.Fn fparseln .Fn fparseln
function first appeared in function first appeared in
.Nx 1.4 .Nx 1.4 .
and
.Fx 4.0 .

View File

@ -32,7 +32,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd $Mdocdate: November 4 2015 $ .Dd $Mdocdate: November 4 2015 $
.Dt fpurge 3bsd .Dt FPURGE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm fpurge .Nm fpurge

View File

@ -31,7 +31,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd March 19, 2004 .Dd March 19, 2004
.Dt funopen 3bsd .Dt FUNOPEN 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm funopen , .Nm funopen ,
@ -168,12 +168,9 @@ functions first appeared in
.Sh BUGS .Sh BUGS
The The
.Fn funopen .Fn funopen
function may not be portable to systems other than function
.Bx , may not be portable to systems other than
glibc- and musl-based ones .Bx .
(as the libbsd implementation is only provided when the system has
.Fn fopencookie
available).
.Pp .Pp
On On
.Fx , .Fx ,

View File

@ -29,7 +29,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd November 16, 2012 .Dd November 16, 2012
.Dt getbsize 3bsd .Dt GETBSIZE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm getbsize .Nm getbsize

View File

@ -26,7 +26,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd July 15, 2001 .Dd July 15, 2001
.Dt getpeereid 3bsd .Dt GETPEEREID 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm getpeereid .Nm getpeereid
@ -139,7 +139,4 @@ or the kernel returned invalid data.
The The
.Fn getpeereid .Fn getpeereid
function appeared in function appeared in
.Fx 4.6 , .Fx 4.6 .
.Nx 5.0
and
.Ox 3.0 .

View File

@ -1,4 +1,6 @@
.\" Copyright (c) 2022 Guillem Jover <guillem@hadrons.org> .\"
.\" Copyright (c) 2001 Christopher G. Demetriou
.\" All rights reserved.
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" modification, are permitted provided that the following conditions
@ -8,27 +10,34 @@
.\" 2. Redistributions in binary form must reproduce the above copyright .\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the .\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution. .\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products .\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed for the
.\" NetBSD Project. See http://www.netbsd.org/ for
.\" information about NetBSD.
.\" 4. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission. .\" 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.
.\" .\"
.Dd August 03, 2022 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.Dt getprogname 3bsd .\" 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.
.\"
.\" $FreeBSD$
.\"
.Dd May 1, 2001
.Dt GETPROGNAME 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm getprogname , .Nm getprogname ,
.Nm setprogname .Nm setprogname
.Nd get and set 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] .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
@ -45,39 +54,46 @@ for include usage.)
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn getprogname .Fn getprogname
returns a string with the current program name,
excluding any directory component.
The function will return
.Dv NULL
if it was unable to get the program name from any known source.
.Pp
The
.Fn setprogname
function sets the current program name,
stripping any directory component prefix.
The function will keep a reference to the passed string pointer,
so it must not be freed or modified while these functions might
be called.
.Pp
The implementations on most BSDs will try to initialize the program name
at program startup time, and
.Nm libbsd
will try to infer it from various known sources depending on the
target system.
But it is not a portable assumption that the program name will be set
without calling
.Fn setprogname ,
so portable programs should always call it after starting up.
.Sh SEE ALSO
.Xr setproctitle 3bsd .
.Sh HISTORY
The
.Fn setprogname
and and
.Fn setprogname
functions manipulate the name of the current program.
They are used by error-reporting routines to produce
consistent output.
.Pp
The
.Fn getprogname .Fn getprogname
functions first appeared in function returns the name of the program.
If the name has not been set yet, it will return
.Dv NULL .
.Pp
The
.Fn setprogname
function sets the name of the program to be the last component of the
.Fa progname
argument.
Since a pointer to the given string is kept as the program name,
it should not be modified for the rest of the program's lifetime.
.Pp
In
.Fx ,
the name of the program is set by the start-up code that is run before
.Fn main ;
thus,
running
.Fn setprogname
is not necessary.
Programs that desire maximum portability should still call it;
on another operating system,
these functions may be implemented in a portability library.
Calling
.Fn setprogname
allows the aforementioned library to learn the program name without
modifications to the start-up code.
.Sh SEE ALSO
.Xr err 3 ,
.Xr setproctitle 3bsd
.Sh HISTORY
These functions first appeared in
.Nx 1.6 , .Nx 1.6 ,
.Fx 4.4 , and made their way into
.Dx 2.1 .Fx 4.4 .
and
.Ox 5.4 .

View File

@ -33,7 +33,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd September 30, 2003 .Dd September 30, 2003
.Dt heapsort 3bsd .Dt HEAPSORT 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm heapsort , mergesort .Nm heapsort , mergesort

View File

@ -28,7 +28,7 @@
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd February 9, 2008 .Dd February 9, 2008
.Dt humanize_number 3bsd .Dt HUMANIZE_NUMBER 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm dehumanize_number , .Nm dehumanize_number ,
@ -166,9 +166,7 @@ represented a number that does not fit in
.Sh HISTORY .Sh HISTORY
.Fn humanize_number .Fn humanize_number
first appeared in first appeared in
.Nx 2.0 .Nx 2.0 .
and
.Fx 5.3 .
.Pp .Pp
.Fn dehumanize_number .Fn dehumanize_number
first appeared in first appeared in

View File

@ -1,6 +1,6 @@
.\" libbsd man page .\" libbsd man page
.\" .\"
.\" Copyright © 2017-2024 Guillem Jover <guillem@hadrons.org> .\" Copyright © 2017-2022 Guillem Jover <guillem@hadrons.org>
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions .\" modification, are permitted provided that the following conditions
@ -24,8 +24,8 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd January 8, 2024 .Dd Mar 30, 2022
.Dt libbsd 7 .Dt LIBBSD 7
.Os .Os
.Sh NAME .Sh NAME
.Nm libbsd .Nm libbsd
@ -42,7 +42,7 @@ The library can be used in an overlay mode, which is the preferred way, so
that the code is portable and requires no modification to the original BSD that the code is portable and requires no modification to the original BSD
code. code.
This can be done easily with the This can be done easily with the
.Xr pkgconf 1 .Xr pkg-config 1
library named library named
.Pa libbsd-overlay . .Pa libbsd-overlay .
Or by adding the system-specific include directory with the Or by adding the system-specific include directory with the
@ -59,12 +59,12 @@ The includes in this case should be the usual system ones, such as
.In unistd.h . .In unistd.h .
.Pp .Pp
The other way to use the library is to use the namespaced headers, The other way to use the library is to use the namespaced headers,
which is a discouraged way, being less portable as it makes using this is less portable as it makes using
.Nm libbsd .Nm libbsd
mandatory and it will not work on BSD-based systems, and requires mandatory and it will not work on BSD-based systems, and requires
modifying original BSD code. modifying original BSD code.
This can be done with the This can be done with the
.Xr pkgconf 1 .Xr pkg-config 1
library named library named
.Pa libbsd . .Pa libbsd .
The includes in this case should be namespaced with The includes in this case should be namespaced with
@ -76,10 +76,10 @@ The package also provides a
.Nm libbsd-ctor .Nm libbsd-ctor
static library that can be used to inject automatic constructors into a static library that can be used to inject automatic constructors into a
program so that the program so that the
.Xr setproctitle_init 3bsd .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 pkgconf 1 .Xr pkg-config 1
library named library named
.Pa libbsd-ctor . .Pa libbsd-ctor .
.Sh HEADERS .Sh HEADERS
@ -128,21 +128,20 @@ It only works in non-overlay mode.
.Bl -tag -width 4m -compact .Bl -tag -width 4m -compact
.It In bsd/bsd.h .It In bsd/bsd.h
.El .El
.Sh VARIANTS .Sh ALTERNATIVES
Some functions have different prototypes depending on the BSD where they Some functions have different prototypes depending on the BSD where they
originated from, and these various implementations provided are selectable originated from, and these various implementations provided are selectable
at build-time. at build-time.
.Pp .Pp
This is the list of functions that provide multiple implementations: This is the list of functions that provide multiple implementations:
.Pp .Bl -tag -width 4m
.Bl -tag -width 4m -compact .It Fn strnvis 3
.It Xr strnvis 3bsd .It Fn strnunvis 3
.It Xr strnunvis 3bsd
.Nx .Nx
added added
.Xr strnvis 3bsd .Fn strnvis 3
and and
.Xr strnunvis 3bsd .Fn strnunvis 3
but unfortunately made it incompatible with the existing one in but unfortunately made it incompatible with the existing one in
.Ox .Ox
and Freedesktop's libbsd (the former having existed for over ten years). and Freedesktop's libbsd (the former having existed for over ten years).
@ -150,13 +149,13 @@ Despite this incompatibility being reported during development (see
http://gnats.netbsd.org/44977) they still shipped it. http://gnats.netbsd.org/44977) they still shipped it.
Even more unfortunately Even more unfortunately
.Fx .Fx
and later macOS picked up this incompatible implementation. and later MacOS picked up this incompatible implementation.
.Pp .Pp
Provide both implementations and default for now to the historical one to Provide both implementations and default for now to the historical one to
avoid breakage, but we will switch to the avoid breakage, but we will switch to the
.Nx .Nx
one in a later release, which is internally consistent with the other one in a later release, which is internally consistent with the other
.Xr vis 3bsd .Xr vis 3
functions and is now more widespread. functions and is now more widespread.
Define Define
.Dv LIBBSD_NETBSD_VIS .Dv LIBBSD_NETBSD_VIS
@ -178,30 +177,30 @@ or non-buggy way; or because there are better more portable replacements now.
.Pp .Pp
This is the list of currently deprecated macros and functions: This is the list of currently deprecated macros and functions:
.Bl -tag -width 4m .Bl -tag -width 4m
.It Xr fgetln 3bsd .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
a limit of 32). a limit of 32).
Use Use
.Xr 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 Xr fgetwln 3bsd .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
a limit of 32). a limit of 32).
Use Use
.Xr fgetwc 3 .Fn fgetwc 3
instead, which is available in many systems and required by 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 Xr funopen 3bsd .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 glibc- and musl-based systems the On GNU systems the
.Xr fopencookie 3 .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.
@ -215,53 +214,31 @@ are present in all major
for example. for example.
.Pp .Pp
.Bl -tag -width 4m -compact .Bl -tag -width 4m -compact
.It Xr MD5Init 3 .It Fn MD5Init 3
.It Xr MD5Update 3 .It Fn MD5Update 3
.It Xr MD5Pad 3 .It Fn MD5Pad 3
.It Xr MD5Final 3 .It Fn MD5Final 3
.It Xr MD5Transform 3 .It Fn MD5Transform 3
.It Xr MD5End 3 .It Fn MD5End 3
.It Xr MD5File 3 .It Fn MD5File 3
.It Xr MD5FileChunk 3 .It Fn MD5FileChunk 3
.It Xr MD5Data 3 .It Fn MD5Data 3
The set of MD5 digest functions are now proxies for the implementations The set of MD5 digest functions are now proxies for the implementations
provided by the provided by the
.Nm libmd .Nm libmd
companion library, so it is advised to switch to use that directly instead. companion library, so it is advised to switch to use that directly instead.
.It Xr explicit_bzero 3bsd .It Fn explicit_bzero 3
This function is provided by This function is provided by
.Nm glibc .Nm glibc
2.25, and 2.25, and
.Nm musl .Nm musl
1.1.20. 1.1.20.
.It Xr reallocarray 3bsd .It Fn reallocarray 3
This function is provided by This function is provided by
.Nm glibc .Nm glibc
2.26, and 2.26, and
.Nm musl .Nm musl
1.2.2. 1.2.2.
.It Xr closefrom 3bsd
This function is provided by
.Nm glibc
2.34.
.It Xr arc4random 3bsd
.It Xr arc4random_buf 3bsd
.It Xr arc4random_uniform 3bsd
These functions are provided by
.Nm glibc
2.36.
Note that it does not provide the
.Xr arc4random_stir 3bsd
and
.Xr arc4random_addrandom 3bsd
functions.
.It Xr strlcpy 3bsd
.It Xr strlcat 3bsd
These functions are provided by
.Nm glibc
2.38, and
.Nm musl
0.5.0.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr arc4random 3bsd , .Xr arc4random 3bsd ,

View File

@ -29,7 +29,7 @@
.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $ .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
.\" .\"
.Dd April 19, 1994 .Dd April 19, 1994
.Dt nlist 3bsd .Dt NLIST 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm nlist .Nm nlist

View File

@ -25,7 +25,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd February 8, 2012 .Dd February 8, 2012
.Dt pidfile 3bsd .Dt PIDFILE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm pidfile_open , .Nm pidfile_open ,
@ -292,20 +292,6 @@ Probably called not from the process which used
.Xr open 2 , .Xr open 2 ,
.Xr daemon 3 , .Xr daemon 3 ,
.Xr flopen 3bsd .Xr flopen 3bsd
.Sh HISTORY
The functions
.Fn pidfile_open ,
.Fn pidfile_write ,
.Fn pidfile_close
and
.Fn pidfile_remove
first appeared in
.Fx 5.5 .
.Pp
The function
.Fn pidfile_fileno
first appeared in
.Fx 10.0 .
.Sh AUTHORS .Sh AUTHORS
.An -nosplit .An -nosplit
The The

View File

@ -28,7 +28,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd $Mdocdate: September 13 2018 $ .Dd $Mdocdate: September 13 2018 $
.Dt user_from_uid 3 .Dt USER_FROM_UID 3
.Os .Os
.Sh NAME .Sh NAME
.Nm user_from_uid , .Nm user_from_uid ,
@ -137,7 +137,7 @@ The
.Fn uid_from_user .Fn uid_from_user
and and
.Fn gid_from_group .Fn gid_from_group
functions first appeared in functions were ported from
.Nx 1.4 .Nx
and and first appeared in
.Ox 6.4 . .Ox 6.4 .

View File

@ -29,7 +29,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd September 8, 2016 .Dd September 8, 2016
.Dt queue 3bsd .Dt QUEUE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm SLIST_CLASS_ENTRY , .Nm SLIST_CLASS_ENTRY ,

View File

@ -30,7 +30,7 @@
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94 .\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
.\" .\"
.Dd January 27, 1994 .Dd January 27, 1994
.Dt radixsort 3bsd .Dt RADIXSORT 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm radixsort , .Nm radixsort ,

View File

@ -19,7 +19,7 @@
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\" .\"
.Dd $Mdocdate: March 6 2014 $ .Dd $Mdocdate: March 6 2014 $
.Dt readpassphrase 3bsd .Dt READPASSPHRASE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm readpassphrase .Nm readpassphrase
@ -165,12 +165,10 @@ will reprint the prompt and the user may then enter a passphrase.
The The
.Fn readpassphrase .Fn readpassphrase
function is an function is an
.Bx .Ox
extension and should not be used if portability is desired. extension and should not be used if portability is desired.
.Sh HISTORY .Sh HISTORY
The The
.Fn readpassphrase .Fn readpassphrase
function first appeared in function first appeared in
.Ox 2.9 .Ox 2.9 .
and
.Fx 4.6 .

View File

@ -33,7 +33,7 @@
.\" $OpenBSD: malloc.3,v 1.126 2019/09/14 13:16:50 otto Exp $ .\" $OpenBSD: malloc.3,v 1.126 2019/09/14 13:16:50 otto Exp $
.\" .\"
.Dd $Mdocdate: September 14 2019 $ .Dd $Mdocdate: September 14 2019 $
.Dt reallocarray 3bsd .Dt REALLOCARRAY 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm reallocarray , .Nm reallocarray ,
@ -283,18 +283,12 @@ The
.Fn reallocarray .Fn reallocarray
function appeared in function appeared in
.Ox 5.6 , .Ox 5.6 ,
.Dx 5.5
and glibc 2.26. and glibc 2.26.
.Pp
The The
.Fn recallocarray .Fn recallocarray
function appeared in function appeared in
.Ox 6.1 .Ox 6.1 .
and
.Dx 5.5 .
The The
.Fn freezero .Fn freezero
function appeared in function appeared in
.Ox 6.2 .Ox 6.2 .
and
.Dx 5.5 .

View File

@ -33,7 +33,7 @@
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ .\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
.\" .\"
.Dd September 26, 2009 .Dd September 26, 2009
.Dt reallocf 3bsd .Dt REALLOCF 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm reallocf .Nm reallocf

View File

@ -31,7 +31,7 @@
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $ .\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
.\" .\"
.Dd January 4, 2009 .Dd January 4, 2009
.Dt setmode 3bsd .Dt SETMODE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm getmode , .Nm getmode ,

View File

@ -20,8 +20,8 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.\" The following requests are required for all man pages. .\" The following requests are required for all man pages.
.Dd December 7, 2022 .Dd December 16, 1995
.Dt setproctitle 3bsd .Dt SETPROCTITLE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm setproctitle .Nm setproctitle
@ -31,6 +31,7 @@
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd] .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd .Lb libbsd
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h
.In unistd.h .In unistd.h
(See (See
.Xr libbsd 7 .Xr libbsd 7
@ -53,7 +54,7 @@ library routine only needs to be called (before any call to
and with and with
.Fn main .Fn main
arguments), if the automatic constructor support has not arguments), if the automatic constructor support has not
been linked in through the libbsd-ctor pkgconf file. been linked in through the libbsd-ctor pkg-config file.
.Pp .Pp
The title is set from the executable's name, followed by the The title is set from the executable's name, followed by the
result of a result of a
@ -112,8 +113,6 @@ The
.Fn setproctitle .Fn setproctitle
function function
first appeared in first appeared in
.Nx 1.0
and
.Fx 2.2 . .Fx 2.2 .
Other operating systems have Other operating systems have
similar functions. similar functions.

View File

@ -27,7 +27,7 @@
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd May 6, 2010 .Dd May 6, 2010
.Dt stringlist 3bsd .Dt STRINGLIST 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm stringlist , .Nm stringlist ,

View File

@ -14,8 +14,8 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: January 7 2024 $ .Dd $Mdocdate: May 31 2007 $
.Dt strlcpy 3bsd .Dt STRLCPY 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strlcpy , .Nm strlcpy ,
@ -192,7 +192,4 @@ and
functions first appeared in functions first appeared in
.Ox 2.4 , .Ox 2.4 ,
and made their appearance in and made their appearance in
.Nx 1.4.3 , .Fx 3.3 .
.Fx 3.3
and
glibc 2.38.

View File

@ -29,7 +29,7 @@
.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $ .\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
.\" .\"
.Dd July 28, 1994 .Dd July 28, 1994
.Dt strmode 3bsd .Dt STRMODE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strmode .Nm strmode

View File

@ -34,7 +34,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd October 11, 2001 .Dd October 11, 2001
.Dt strstr 3bsd .Dt STRSTR 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strnstr .Nm strnstr
@ -112,8 +112,3 @@ ptr = strnstr(largestring, smallstring, 4);
.Xr strspn 3 , .Xr strspn 3 ,
.Xr strtok 3 , .Xr strtok 3 ,
.Xr wcsstr 3 .Xr wcsstr 3
.Sh HISTORY
The
.Fn strnstr
function originated in
.Fx .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: strtoi.3,v 1.10 2024/02/10 18:43:51 andvar Exp $ .\" $NetBSD: strtoi.3,v 1.7 2017/07/03 21:32:50 wiz Exp $
.\" .\"
.\" Copyright (c) 1990, 1991, 1993 .\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -36,12 +36,12 @@
.\" Created by Kamil Rytarowski, based on ID: .\" Created by Kamil Rytarowski, based on ID:
.\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp .\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
.\" .\"
.Dd January 20, 2024 .Dd November 13, 2015
.Dt strtoi 3bsd .Dt STRTOI 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strtoi .Nm strtoi
.Nd convert a 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] .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
@ -63,7 +63,8 @@ for include usage.)
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn strtoi .Fn strtoi
function converts the string in function
converts the string in
.Fa nptr .Fa nptr
to an to an
.Ft intmax_t .Ft intmax_t
@ -76,7 +77,7 @@ and ensures that the result is always in the range [
.Fa lo .. .Fa lo ..
.Fa hi .Fa hi
]. ].
In addition it always places In adddition it always places
.Dv 0 .Dv 0
on success or a conversion status in the on success or a conversion status in the
.Fa rstatus .Fa rstatus
@ -121,11 +122,10 @@ is taken as 10 (decimal) unless the next character is
.Ql 0 , .Ql 0 ,
in which case it is taken as 8 (octal). in which case it is taken as 8 (octal).
.Pp .Pp
The remainder of the string is converted to an The remainder of the string is converted to a
.Em intmax_t .Em intmax_t
value in the obvious manner, value in the obvious manner,
stopping at the end of the string stopping at the first character which is not a valid digit
or at the first character which is not a valid digit
in the given base. in the given base.
(In bases above 10, the letter (In bases above 10, the letter
.Ql A .Ql A
@ -206,12 +206,6 @@ or the range given was invalid, i.e.
> >
.Fa hi . .Fa hi .
.El .El
.Pp
The range check is more important than the unconverted characters check,
and it is performed first.
If a program needs to know if there were unconverted characters when an
out of range number has been provided, it needs to supply and test
.Fa endptr.
.Sh SEE ALSO .Sh SEE ALSO
.Xr atof 3 , .Xr atof 3 ,
.Xr atoi 3 , .Xr atoi 3 ,
@ -239,7 +233,7 @@ function first appeared in
.Nx 7.0 . .Nx 7.0 .
.Ox .Ox
introduced the introduced the
.Xr strtonum 3bsd .Fn strtonum 3bsd
function for the same purpose, but the interface makes it impossible to function for the same purpose, but the interface makes it impossible to
properly differentiate illegal returns. properly differentiate illegal returns.
.Sh BUGS .Sh BUGS

View File

@ -16,7 +16,7 @@
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd January 18, 2015 .Dd January 18, 2015
.Dt strtonum 3bsd .Dt STRTONUM 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strtonum .Nm strtonum
@ -141,8 +141,8 @@ The string did not consist solely of digit characters.
.Xr strtoull 3 .Xr strtoull 3
.Sh STANDARDS .Sh STANDARDS
.Fn strtonum .Fn strtonum
is a is an
.Bx .Ox
extension. extension.
.Sh HISTORY .Sh HISTORY
.ds doc-operating-system-NetBSD-8.0 8.0 .ds doc-operating-system-NetBSD-8.0 8.0
@ -154,9 +154,9 @@ function first appeared in
was redesigned in was redesigned in
.Nx 8.0 .Nx 8.0
as as
.Xr strtoi 3bsd .Fn strtoi 3bsd
and and
.Xr strtou 3bsd . .Fn strtou 3bsd .
.Sh CAVEATS .Sh CAVEATS
The The
.Fn strtonum .Fn strtonum
@ -186,6 +186,6 @@ To overcome the shortcomings of
.Fn strtonum .Fn strtonum
.Nx .Nx
provides provides
.Xr strtou 3bsd .Fn strtou 3bsd
and and
.Xr strtoi 3bsd . .Fn strtoi 3bsd .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: strtou.3,v 1.8 2024/01/20 16:13:39 christos Exp $ .\" $NetBSD: strtou.3,v 1.7 2017/07/03 21:32:50 wiz Exp $
.\" .\"
.\" Copyright (c) 1990, 1991, 1993 .\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -36,12 +36,12 @@
.\" Created by Kamil Rytarowski, based on ID: .\" Created by Kamil Rytarowski, based on ID:
.\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp .\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
.\" .\"
.Dd January 20, 2024 .Dd November 13, 2015
.Dt strtou 3bsd .Dt STRTOU 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm strtou .Nm strtou
.Nd convert a string value 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] .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
@ -76,7 +76,7 @@ and ensures that the result is always in the range [
.Fa lo .. .Fa lo ..
.Fa hi .Fa hi
]. ].
In addition it always places In adddition it always places
.Dv 0 .Dv 0
on success or a conversion status in the on success or a conversion status in the
.Fa rstatus .Fa rstatus
@ -125,7 +125,7 @@ The remainder of the string is converted to an
.Em uintmax_t .Em uintmax_t
value in the obvious manner, value in the obvious manner,
stopping at the end of the string stopping at the end of the string
or at the first character which is not a valid digit or at the first character that does not produce a valid digit
in the given base. in the given base.
(In bases above 10, the letter (In bases above 10, the letter
.Ql A .Ql A
@ -200,18 +200,12 @@ In this case,
.Fa endptr .Fa endptr
points to the first unconverted character. points to the first unconverted character.
.It Bq Er ERANGE .It Bq Er ERANGE
The given string was out of range; the value converted has been clamped; The given string was out of range; the value converted has been clamped; or
or the range given was invalid, i.e. the range given was invalid, i.e.
.Fa lo .Fa lo
> >
.Fa hi . .Fa hi .
.El .El
.Pp
The range check is more important than the unconverted characters check,
and it is performed first.
If a program needs to know if there were unconverted characters when an
out of range number has been provided, it needs to supply and test
.Fa endptr.
.Sh SEE ALSO .Sh SEE ALSO
.Xr atof 3 , .Xr atof 3 ,
.Xr atoi 3 , .Xr atoi 3 ,
@ -226,20 +220,20 @@ out of range number has been provided, it needs to supply and test
.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
.Nx .Nx
extension. extension.
.Sh HISTORY .Sh HISTORY
.ds doc-operating-system-NetBSD-7.0 7.0
The The
.Fn strtou .Fn strtou
function first appeared in function first appeared in
.Nx 7.0 . .Nx 7.0 .
.Ox .Ox
introduced the introduced the
.Xr strtonum 3bsd .Fn strtonum 3bsd
function for the same purpose, but the interface makes it impossible to function for the same purpose, but the interface makes it impossible to
properly differentiate illegal returns. properly differentiate illegal returns.
.Sh BUGS .Sh BUGS

View File

@ -31,7 +31,7 @@
.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $ .\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
.\" .\"
.Dd June 7, 2010 .Dd June 7, 2010
.Dt timeradd 3bsd .Dt TIMERADD 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm timeradd , .Nm timeradd ,

1
man/timespec.3bsd Normal file
View File

@ -0,0 +1 @@
.so man3/timeval.3bsd

134
man/timeval.3bsd Normal file
View File

@ -0,0 +1,134 @@
.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jukka Ruohonen.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 12, 2011
.Dt TIMEVAL 3bsd
.Os
.Sh NAME
.Nm timeval ,
.Nm timespec
.Nd time structures
.Sh LIBRARY
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
.Lb libbsd
.Sh SYNOPSIS
.In sys/time.h
(See
.Xr libbsd 7
for include usage.)
.Ft void
.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
.Ft void
.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
.Sh DESCRIPTION
The
.In sys/time.h
header, included by
.In time.h ,
defines various structures related to time and timers.
.Bl -enum -offset 1n
.It
The following structure is used by
.Xr gettimeofday 2 ,
among others:
.Bd -literal -offset indent
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
.Ed
.Pp
The
.Va tv_sec
member represents the elapsed time, in whole seconds.
The
.Va tv_usec
member captures rest of the elapsed time,
represented as the number of microseconds.
.It
The following structure is used by
.Xr nanosleep 2 ,
among others:
.Bd -literal -offset indent
struct timespec {
time_t tv_sec;
long tv_nsec;
};
.Ed
.Pp
The
.Va tv_sec
member is again the elapsed time in whole seconds.
The
.Va tv_nsec
member represents the rest of the elapsed time in nanoseconds.
.Pp
A microsecond is equal to one millionth of a second,
1000 nanoseconds, or 1/1000 milliseconds.
To ease the conversions, the macros
.Fn TIMEVAL_TO_TIMESPEC
and
.Fn TIMESPEC_TO_TIMEVAL
can be used to convert between
.Em struct timeval
and
.Em struct timespec .
.El
.Sh EXAMPLES
It can be stressed that the traditional
.Tn UNIX
.Va timeval
and
.Va timespec
structures represent elapsed time, measured by the system clock.
The following sketch implements a function suitable
for use in a context where the
.Va timespec
structure is required for a conditional timeout:
.Bd -literal -offset indent
static void
example(struct timespec *spec, time_t minutes)
{
struct timeval elapsed;
(void)gettimeofday(&elapsed, NULL);
_DIAGASSERT(spec != NULL);
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
/* Add the offset for timeout in minutes. */
spec->tv_sec = spec->tv_sec + minutes * 60;
}
.Ed
.Pp
A better alternative would use the more precise
.Xr clock_gettime 2 .
.Sh SEE ALSO
.Xr timeradd 3bsd

View File

@ -24,7 +24,7 @@
.\" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" */ .\" */
.Dd May 10, 2019 .Dd May 10, 2019
.Dt tree 3bsd .Dt TREE 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm SPLAY_PROTOTYPE , .Nm SPLAY_PROTOTYPE ,
@ -562,9 +562,6 @@ main(void)
.Ed .Ed
.Sh SEE ALSO .Sh SEE ALSO
.Xr queue 3bsd .Xr queue 3bsd
.Sh HISTORY
The tree macros first appeared in
.Fx 4.6 .
.Sh NOTES .Sh NOTES
Trying to free a tree in the following way is a common error: Trying to free a tree in the following way is a common error:
.Bd -literal -offset indent .Bd -literal -offset indent

View File

@ -30,7 +30,7 @@
.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93 .\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
.\" .\"
.Dd March 12, 2011 .Dd March 12, 2011
.Dt unvis 3bsd .Dt UNVIS 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm unvis , .Nm unvis ,

View File

@ -1 +0,0 @@
.so man3/errc.3bsd

View File

@ -30,7 +30,7 @@
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93 .\" @(#)vis.3 8.1 (Berkeley) 6/9/93
.\" .\"
.Dd April 22, 2017 .Dd April 22, 2017
.Dt vis 3bsd .Dt VIS 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm vis , .Nm vis ,

View File

@ -1 +0,0 @@
.so man3/errc.3bsd

View File

@ -1 +0,0 @@
.so man3/errc.3bsd

View File

@ -36,7 +36,7 @@
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd March 4, 2009 .Dd March 4, 2009
.Dt wcslcpy 3bsd .Dt WCSLCPY 3bsd
.Os .Os
.Sh NAME .Sh NAME
.Nm wcslcat , .Nm wcslcat ,
@ -69,14 +69,3 @@ counterpart, such as
and and
.Fn wcslcpy , .Fn wcslcpy ,
which are BSD extensions. which are BSD extensions.
.Sh HISTORY
The
.Fn wcslcpy
and
.Fn wcslcat
functions first appeared in
.Ox 3.8 ,
.Nx 1.6 ,
.Fx 5.0
and
.Dx 2.1 .

View File

@ -5,14 +5,13 @@ AM_CPPFLAGS = \
-isystem $(top_srcdir)/include/bsd/ \ -isystem $(top_srcdir)/include/bsd/ \
-include $(top_builddir)/config.h \ -include $(top_builddir)/config.h \
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \ -DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-D__REENTRANT \ -D__REENTRANT
# EOL
if OS_WINDOWS if OS_WINDOWS
AM_CPPFLAGS += \ AM_CPPFLAGS += \
-D_CRT_SECURE_NO_WARNINGS \ -D_CRT_SECURE_NO_WARNINGS \
-D_CRT_NONSTDC_NO_WARNINGS \ -D_CRT_NONSTDC_NO_WARNINGS \
# EOL $(nil)
endif endif
libbsd_la_included_sources = \ libbsd_la_included_sources = \
@ -24,22 +23,22 @@ libbsd_la_included_sources = \
getentropy_osx.c \ getentropy_osx.c \
getentropy_solaris.c \ getentropy_solaris.c \
getentropy_win.c \ getentropy_win.c \
# EOL $(nil)
CLEANFILES = CLEANFILES =
EXTRA_DIST = \ EXTRA_DIST = \
libbsd.map.in \ libbsd.map \
libbsd.pc.in \ libbsd.pc.in \
libbsd-ctor.pc.in \ libbsd-ctor.pc.in \
libbsd-overlay.pc.in \ libbsd-overlay.pc.in \
$(libbsd_la_included_sources) \ $(libbsd_la_included_sources) \
# EOL $(nil)
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \ pkgconfig_DATA = \
libbsd.pc \ libbsd.pc \
libbsd-overlay.pc \ libbsd-overlay.pc \
# EOL $(nil)
lib_LTLIBRARIES = libbsd.la lib_LTLIBRARIES = libbsd.la
lib_LIBRARIES = lib_LIBRARIES =
@ -50,322 +49,98 @@ pkgconfig_DATA += libbsd-ctor.pc
lib_LIBRARIES += libbsd-ctor.a lib_LIBRARIES += libbsd-ctor.a
endif endif
EXTRA_libbsd_la_DEPENDENCIES = \ libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \ $(libbsd_la_included_sources) \
libbsd.map \ libbsd.map
libbsd.map.in \
# EOL
libbsd_la_LIBADD = \ libbsd_la_LIBADD = \
$(MD5_LIBS) \ $(MD5_LIBS) \
$(LIBBSD_LIBS) \ $(LIBBSD_LIBS) \
# EOL $(nil)
libbsd_la_LDFLAGS = \ libbsd_la_LDFLAGS = \
-no-undefined \ -version-number $(LIBBSD_ABI)
-version-number $(SOVERSION) \
# EOL
if HAVE_LINKER_VERSION_SCRIPT if HAVE_LINKER_VERSION_SCRIPT
libbsd_la_LDFLAGS += \ libbsd_la_LDFLAGS += \
-Wl,--version-script=libbsd.map \ -Wl,--version-script=$(srcdir)/libbsd.map
# EOL
else
libbsd_la_LDFLAGS += \
-export-symbols libbsd.sym \
# EOL
EXTRA_libbsd_la_DEPENDENCIES += \
libbsd.sym \
# EOL
endif endif
libbsd_la_SOURCES = \ libbsd_la_SOURCES = \
local-elf.h \
local-link.h \
# EOL
if ABI_ACCMODE
libbsd_la_SOURCES += \
setmode.c \
# EOL
endif
if ABI_ARC4RANDOM
if !HAVE_GETENTROPY
libbsd_la_SOURCES += \
getentropy.c \
# EOL
endif
libbsd_la_SOURCES += \
arc4random.c \ arc4random.c \
arc4random.h \ arc4random.h \
arc4random_linux.h \ arc4random_linux.h \
arc4random_uniform.c \ arc4random_uniform.c \
arc4random_unix.h \ arc4random_unix.h \
arc4random_win.h \ arc4random_win.h \
chacha_private.h \
# EOL
endif
if ABI_ASPRINTF
libbsd_la_SOURCES += \
asprintf.c \
vasprintf.c \
# EOL
endif
if ABI_BSD_GETOPT
libbsd_la_SOURCES += \
bsd_getopt.c \ bsd_getopt.c \
# EOL chacha_private.h \
endif
if ABI_CLOSEFROM
libbsd_la_SOURCES += \
closefrom.c \ closefrom.c \
# EOL
endif
if ABI_ERR
libbsd_la_SOURCES += \
err.c \
# EOL
endif
if ABI_ERRC
libbsd_la_SOURCES += \
errc.c \
# EOL
endif
if ABI_EXPAND_NUMBER
libbsd_la_SOURCES += \
expand_number.c \
# EOL
endif
if ABI_EXPLICIT_BZERO
libbsd_la_SOURCES += \
explicit_bzero.c \
# EOL
endif
if ABI_FGETLN
libbsd_la_SOURCES += \
fgetln.c \
fgetwln.c \
fparseln.c \
# EOL
endif
if ABI_FLOPEN
libbsd_la_SOURCES += \
flopen.c \
# EOL
endif
if ABI_FMTCHECK
libbsd_la_SOURCES += \
fmtcheck.c \
# EOL
endif
if ABI_FPURGE
libbsd_la_SOURCES += \
fpurge.c \
# EOL
endif
if ABI_FREEZERO
libbsd_la_SOURCES += \
freezero.c \
# EOL
endif
if ABI_FUNOPEN
libbsd_la_SOURCES += \
funopen.c \
# EOL
endif
if ABI_GETBSIZE
libbsd_la_SOURCES += \
getbsize.c \
# EOL
endif
if ABI_GETPEEREID
libbsd_la_SOURCES += \
getpeereid.c \
# EOL
endif
if ABI_HUMANIZE_NUMBER
libbsd_la_SOURCES += \
dehumanize_number.c \ dehumanize_number.c \
humanize_number.c \ err.c \
# EOL expand_number.c \
endif explicit_bzero.c \
fgetln.c \
if ABI_INET_NET_PTON freezero.c \
libbsd_la_SOURCES += \ fgetwln.c \
inet_net_pton.c \ flopen.c \
# EOL fmtcheck.c \
endif fparseln.c \
fpurge.c \
if ABI_MD5 funopen.c \
libbsd_la_SOURCES += \ getbsize.c \
md5.c \ getpeereid.c \
# EOL
endif
if ABI_NLIST
libbsd_la_SOURCES += \
nlist.c \
# EOL
endif
if ABI_PIDFILE
libbsd_la_SOURCES += \
pidfile.c \
# EOL
endif
if ABI_PROCTITLE
libbsd_la_SOURCES += \
setproctitle.c \
# EOL
endif
if ABI_PROGNAME
libbsd_la_SOURCES += \
progname.c \
# EOL
endif
if ABI_PWCACHE
libbsd_la_SOURCES += \
pwcache.c \
# EOL
endif
if ABI_READPASSPHRASE
libbsd_la_SOURCES += \
readpassphrase.c \
# EOL
endif
if ABI_REALLOCARRAY
libbsd_la_SOURCES += \
reallocarray.c \
# EOL
endif
if ABI_REALLOCF
libbsd_la_SOURCES += \
reallocf.c \
# EOL
endif
if ABI_RECALLOCARRAY
libbsd_la_SOURCES += \
recallocarray.c \
# EOL
endif
if ABI_SORT
libbsd_la_SOURCES += \
heapsort.c \ heapsort.c \
humanize_number.c \
inet_net_pton.c \
local-elf.h \
local-link.h \
md5.c \
merge.c \ merge.c \
nlist.c \
pidfile.c \
progname.c \
pwcache.c \
radixsort.c \ radixsort.c \
# EOL readpassphrase.c \
endif reallocarray.c \
reallocf.c \
if ABI_STRINGLIST recallocarray.c \
libbsd_la_SOURCES += \ setmode.c \
stringlist.c \ setproctitle.c \
# EOL
endif
if ABI_STRL
libbsd_la_SOURCES += \
strlcat.c \ strlcat.c \
strlcpy.c \ strlcpy.c \
# EOL stringlist.c \
endif
if ABI_STRMODE
libbsd_la_SOURCES += \
strmode.c \ strmode.c \
# EOL
endif
if ABI_STRNSTR
libbsd_la_SOURCES += \
strnstr.c \ strnstr.c \
# EOL
endif
if ABI_STRTONUM
libbsd_la_SOURCES += \
strtonum.c \
# EOL
endif
if ABI_STRTOX
libbsd_la_SOURCES += \
strtoi.c \ strtoi.c \
strtonum.c \
strtou.c \ strtou.c \
# EOL
endif
if ABI_TIMECONV
libbsd_la_SOURCES += \
timeconv.c \ timeconv.c \
# EOL
endif
if ABI_VIS
libbsd_la_SOURCES += \
unvis.c \ unvis.c \
vis.c \ vis.c \
# EOL
endif
if ABI_WCSL
libbsd_la_SOURCES += \
wcslcat.c \ wcslcat.c \
wcslcpy.c \ wcslcpy.c \
# EOL $(nil)
if !HAVE_GETENTROPY
libbsd_la_SOURCES += \
getentropy.c \
$(nil)
endif endif
if ABI_TRANSPARENT_LIBMD if NEED_TRANSPARENT_LIBMD
CLEANFILES += \ CLEANFILES += \
format.ld \ format.ld \
# EOL # EOL
endif endif
DISTCLEANFILES = \
libbsd.sym \
libbsd.map \
# EOL
libbsd_ctor_a_SOURCES = \ libbsd_ctor_a_SOURCES = \
setproctitle_ctor.c \ setproctitle_ctor.c \
# EOL $(nil)
# Generate the library map file with the pre-processor to selectively include if NEED_TRANSPARENT_LIBMD
# symbols depending on the host system, otherwise some linkers might fail.
libbsd.map: libbsd.map.in
$(AM_V_GEN) $(CPP) $(AM_CPPFLAGS) $(CPPFLAGS) -P - <$(srcdir)/libbsd.map.in >$@
# Generate a simple libtool symbol export list to be used as a fallback if
# there is no version script support.
libbsd.sym: libbsd.map
$(AM_V_GEN) $(SED) -ne 's/^[[:space:]]\{1,\}\([A-Za-z0-9_]\{1,\}\);/\1/p' libbsd.map >$@
if ABI_TRANSPARENT_LIBMD
TRANSPARENT_LIBMD_DEPENDS = format.ld TRANSPARENT_LIBMD_DEPENDS = format.ld
format.ld: format.ld:
$(CC) -shared -nostdlib -nostartfiles -x assembler /dev/null -o $@.so $(CC) -shared -nostdlib -nostartfiles -x assembler /dev/null -o $@.so
$(OBJDUMP) -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' >$@ $(OBJDUMP) -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' > $@
rm -f $@.so rm -f $@.so
endif endif
@ -377,7 +152,7 @@ install-exec-hook: $(TRANSPARENT_LIBMD_DEPENDS)
mv $(DESTDIR)$(libdir)/libbsd*.so.* \ mv $(DESTDIR)$(libdir)/libbsd*.so.* \
$(DESTDIR)$(runtimelibdir)/; \ $(DESTDIR)$(runtimelibdir)/; \
fi fi
if ABI_TRANSPARENT_LIBMD if NEED_TRANSPARENT_LIBMD
# The "GNU ld script" magic is required so that GNU ldconfig does not complain # The "GNU ld script" magic is required so that GNU ldconfig does not complain
# about an unknown format file. # about an unknown format file.
soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \ soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \

View File

@ -1,4 +1,4 @@
/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */ /* $OpenBSD: arc4random.c,v 1.53 2015/09/10 18:53:50 bcook Exp $ */
/* /*
* Copyright (c) 1996, David Mazieres <dm@uun.org> * Copyright (c) 1996, David Mazieres <dm@uun.org>
@ -50,8 +50,6 @@
#define BLOCKSZ 64 #define BLOCKSZ 64
#define RSBUFSZ (16*BLOCKSZ) #define RSBUFSZ (16*BLOCKSZ)
#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */
/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */ /* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
static struct _rs { static struct _rs {
size_t rs_have; /* valid bytes at end of rs_buf */ size_t rs_have; /* valid bytes at end of rs_buf */
@ -76,10 +74,10 @@ _rs_init(unsigned char *buf, size_t n)
if (rs == NULL) { if (rs == NULL) {
if (_rs_allocate(&rs, &rsx) == -1) if (_rs_allocate(&rs, &rsx) == -1)
_exit(1); abort();
} }
chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8); chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8, 0);
chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ); chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
} }
@ -110,7 +108,6 @@ static void
_rs_stir(void) _rs_stir(void)
{ {
unsigned char rnd[KEYSZ + IVSZ]; unsigned char rnd[KEYSZ + IVSZ];
uint32_t rekey_fuzz = 0;
if (getentropy(rnd, sizeof rnd) == -1) if (getentropy(rnd, sizeof rnd) == -1)
_getentropy_fail(); _getentropy_fail();
@ -125,10 +122,7 @@ _rs_stir(void)
rs->rs_have = 0; rs->rs_have = 0;
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
/* rekey interval should not be predictable */ rs->rs_count = 1600000;
chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz,
(uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz));
rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE);
} }
static inline void static inline void

View File

@ -1,43 +0,0 @@
/*
* Copyright © 2010-2024 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 <config.h>
#include <stdarg.h>
#include <stdio.h>
int
asprintf(char **strp, char const *fmt, ...)
{
va_list args;
int n;
va_start(args, fmt);
n = vasprintf(strp, fmt, args);
va_end(args);
return n;
}

View File

@ -4,7 +4,7 @@ D. J. Bernstein
Public domain. Public domain.
*/ */
/* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */ /* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned int u32; typedef unsigned int u32;
@ -52,7 +52,7 @@ static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k"; static const char tau[16] = "expand 16-byte k";
static void static void
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits) chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
{ {
const char *constants; const char *constants;

View File

@ -153,9 +153,6 @@ closefrom_procfs(int lowfd)
const char *errstr; const char *errstr;
int fd; int fd;
if (dent->d_name[0] == '.')
continue;
fd = strtonum(dent->d_name, lowfd, INT_MAX, &errstr); fd = strtonum(dent->d_name, lowfd, INT_MAX, &errstr);
if (errstr != NULL || fd == dirfd(dirp)) if (errstr != NULL || fd == dirfd(dirp))
continue; continue;

View File

@ -1,5 +1,6 @@
/* /*
* Copyright © 2019 Guillem Jover <guillem@hadrons.org> * Copyright © 2006 Robert Millan
* 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
@ -25,12 +26,58 @@
*/ */
#include <err.h> #include <err.h>
#ifdef LIBBSD_NEED_ERR_H_FUNCS
#include <errno.h> #include <errno.h>
#endif
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.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
warnc(int code, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vwarnc(code, format, ap);
va_end(ap);
}
void
verrc(int status, 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));
exit(status);
}
void
errc(int status, int code, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrc(status, code, format, ap);
va_end(ap);
}
#ifdef LIBBSD_NEED_ERR_H_FUNCS
void void
vwarn(const char *format, va_list ap) vwarn(const char *format, va_list ap)
{ {
@ -101,3 +148,4 @@ errx(int eval, const char *format, ...)
verrx(eval, format, ap); verrx(eval, format, ap);
va_end(ap); va_end(ap);
} }
#endif

View File

@ -1,75 +0,0 @@
/*
* Copyright © 2006 Robert Millan
* Copyright © 2011, 2019 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 <err.h>
#include <string.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
warnc(int code, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vwarnc(code, format, ap);
va_end(ap);
}
void
verrc(int status, 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));
exit(status);
}
void
errc(int status, int code, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrc(status, code, format, ap);
va_end(ap);
}

View File

@ -25,11 +25,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdio.h>
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "local-link.h" #include "local-link.h"

View File

@ -87,9 +87,6 @@ fgetwln(FILE *stream, size_t *lenp)
*lenp = wused; *lenp = wused;
return wused ? fb->wbuf : NULL; return wused ? fb->wbuf : NULL;
} }
/* XXX: Ideally we'd recommend getwline(3), but unfortunately even though it
* was part of the ISO/IEC TR 24731-2:2010 draft, it did not make it into C11
* and is not widely implemented. */
libbsd_link_warning(fgetwln, libbsd_link_warning(fgetwln,
"The fgetwln() function cannot be safely ported, use fgetwc(3) " "The fgetwln() function cannot be safely ported, use fgetwc(3) "
"instead, as it is supported by C99 and POSIX.1-2001."); "instead, as it is supported by C99 and POSIX.1-2001.");

View File

@ -38,27 +38,6 @@
#include <libutil.h> #include <libutil.h>
static int
lock_file(int fd, int flags)
{
int operation;
#if HAVE_FLOCK
operation = LOCK_EX;
if (flags & O_NONBLOCK)
operation |= LOCK_NB;
return flock(fd, operation);
#else
if (flags & O_NONBLOCK)
operation = F_TLOCK;
else
operation = F_LOCK;
return lockf(fd, operation, 0);
#endif
}
/* /*
* Reliably open and lock a file. * Reliably open and lock a file.
* *
@ -70,7 +49,7 @@ lock_file(int fd, int flags)
static int static int
vflopenat(int dirfd, const char *path, int flags, va_list ap) vflopenat(int dirfd, const char *path, int flags, va_list ap)
{ {
int fd, serrno, trunc; int fd, operation, serrno, trunc;
struct stat sb, fsb; struct stat sb, fsb;
mode_t mode; mode_t mode;
@ -83,6 +62,10 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */ mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
} }
operation = LOCK_EX;
if (flags & O_NONBLOCK)
operation |= LOCK_NB;
trunc = (flags & O_TRUNC); trunc = (flags & O_TRUNC);
flags &= ~O_TRUNC; flags &= ~O_TRUNC;
@ -90,7 +73,7 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
if ((fd = openat(dirfd, path, flags, mode)) == -1) if ((fd = openat(dirfd, path, flags, mode)) == -1)
/* non-existent or no access */ /* non-existent or no access */
return (-1); return (-1);
if (lock_file(fd, flags) == -1) { if (flock(fd, operation) == -1) {
/* unsupported or interrupted */ /* unsupported or interrupted */
serrno = errno; serrno = errno;
(void)close(fd); (void)close(fd);

View File

@ -26,9 +26,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#if HAVE_STDIO_EXT_H
#include <stdio_ext.h> #include <stdio_ext.h>
#endif
#ifdef HAVE___FPURGE #ifdef HAVE___FPURGE
int int

View File

@ -65,7 +65,7 @@ funopen_write(void *cookie, const char *buf, size_t size)
} }
static int static int
funopen_seek(void *cookie, off_t *offset, int whence) funopen_seek(void *cookie, off64_t *offset, int whence)
{ {
struct funopen_cookie *cookiewrap = cookie; struct funopen_cookie *cookiewrap = cookie;
off_t soff = *offset; off_t soff = *offset;
@ -137,6 +137,12 @@ funopen(const void *cookie,
return fopencookie(cookiewrap, mode, funcswrap); return fopencookie(cookiewrap, mode, funcswrap);
} }
#elif defined(__MUSL__)
/*
* This is unimplementable on musl based systems, and upstream has stated
* they will not add the needed support to implement it. Just ignore this
* interface there, as it has never been provided anyway.
*/
#else #else
#error "Function funopen() needs to be ported." #error "Function funopen() needs to be ported or disabled."
#endif #endif

View File

@ -415,17 +415,17 @@ getentropy_fallback(void *buf, size_t len)
#ifdef HAVE_GETAUXVAL #ifdef HAVE_GETAUXVAL
#ifdef AT_RANDOM #ifdef AT_RANDOM
/* Not as random as you think but we take what we are given */ /* Not as random as you think but we take what we are given */
p = (char *) ((intptr_t) getauxval(AT_RANDOM)); p = (char *) getauxval(AT_RANDOM);
if (p) if (p)
HR(p, 16); HR(p, 16);
#endif #endif
#ifdef AT_SYSINFO_EHDR #ifdef AT_SYSINFO_EHDR
p = (char *) ((intptr_t) getauxval(AT_SYSINFO_EHDR)); p = (char *) getauxval(AT_SYSINFO_EHDR);
if (p) if (p)
HR(p, pgs); HR(p, pgs);
#endif #endif
#ifdef AT_BASE #ifdef AT_BASE
p = (char *) ((intptr_t) getauxval(AT_BASE)); p = (char *) getauxval(AT_BASE);
if (p) if (p)
HD(p); HD(p);
#endif #endif

View File

@ -9,5 +9,4 @@ Version: @VERSION@
URL: https://libbsd.freedesktop.org/ URL: https://libbsd.freedesktop.org/
Libs: -L${libdir} -lbsd Libs: -L${libdir} -lbsd
Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@ Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@
# We use -isystem instead of -I due the overlay via #include_next usage.
Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY

View File

@ -1,72 +1,42 @@
#include "config.h"
LIBBSD_0.0 { LIBBSD_0.0 {
global: global:
#if LIBBSD_ABI_ARC4RANDOM
arc4random; arc4random;
#endif
#if LIBBSD_ABI_ARC4RANDOM_STIR
arc4random_stir; arc4random_stir;
arc4random_addrandom; arc4random_addrandom;
#endif
#if LIBBSD_ABI_BSD_GETOPT
bsd_getopt; bsd_getopt;
optreset; optreset;
#endif
#if LIBBSD_ABI_ERRC
errc; errc;
warnc; warnc;
verrc; verrc;
vwarnc; vwarnc;
#endif
#if LIBBSD_ABI_FGETLN
fgetln; fgetln;
#endif
#if LIBBSD_ABI_FMTCHECK
fmtcheck; fmtcheck;
#endif
#if LIBBSD_ABI_SORT
heapsort; heapsort;
#endif
#if LIBBSD_ABI_HUMANIZE_NUMBER
humanize_number; humanize_number;
#endif
#if LIBBSD_ABI_INET_NET_PTON inet_net_pton; /* XXX: Already provided by glibc, remove. */
inet_net_pton;
#endif
#if LIBBSD_ABI_PROGNAME
getprogname; getprogname;
setprogname; setprogname;
#endif
#if LIBBSD_ABI_STRL
strlcpy; strlcpy;
strlcat; strlcat;
#endif
#if LIBBSD_ABI_ACCMODE
setmode; setmode;
getmode; getmode;
#endif
#if LIBBSD_ABI_VIS
vis; vis;
strvis; strvis;
strvisx; strvisx;
unvis; unvis;
strunvis; strunvis;
strunvisx; strunvisx;
#endif
#if LIBBSD_ABI_MD5 /* The following functions are provided via the system libc or libmd
* implementations. */
MD5Init; MD5Init;
MD5Update; MD5Update;
MD5Pad; MD5Pad;
@ -76,138 +46,88 @@ LIBBSD_0.0 {
MD5File; MD5File;
MD5FileChunk; MD5FileChunk;
MD5Data; MD5Data;
#endif
local: local:
*; *;
}; };
LIBBSD_0.1 { LIBBSD_0.1 {
#if LIBBSD_ABI_STRMODE
strmode; strmode;
#endif
#if LIBBSD_ABI_NLIST __fdnlist; /* Private symbol, but libkvm uses it. */
/* Private symbol, but libkvm uses it. */
__fdnlist;
nlist; nlist;
#endif
} LIBBSD_0.0; } LIBBSD_0.0;
LIBBSD_0.2 { LIBBSD_0.2 {
#if LIBBSD_ABI_STRTONUM
strtonum; strtonum;
#endif
#if LIBBSD_ABI_VIS
strnvis; strnvis;
strnunvis; strnunvis;
#endif
#if LIBBSD_ABI_HUMANIZE_NUMBER
dehumanize_number; dehumanize_number;
#endif
#if LIBBSD_ABI_READPASSPHRASE
readpassphrase; readpassphrase;
#endif
#if LIBBSD_ABI_FLOPEN
flopen; flopen;
#endif
#if LIBBSD_ABI_PIDFILE
pidfile_open; pidfile_open;
pidfile_write; pidfile_write;
pidfile_close; pidfile_close;
pidfile_remove; pidfile_remove;
#endif
#if LIBBSD_ABI_ARC4RANDOM
arc4random_buf; arc4random_buf;
arc4random_uniform; arc4random_uniform;
#endif
} LIBBSD_0.1; } LIBBSD_0.1;
LIBBSD_0.3 { LIBBSD_0.3 {
#if LIBBSD_ABI_REALLOCF
reallocf; reallocf;
#endif
#if LIBBSD_ABI_GETPEEREID
getpeereid; getpeereid;
#endif
#if LIBBSD_ABI_SORT
mergesort; mergesort;
radixsort; radixsort;
sradixsort; sradixsort;
#endif
#if LIBBSD_ABI_FPURGE
fpurge; fpurge;
#endif
} LIBBSD_0.2; } LIBBSD_0.2;
LIBBSD_0.4 { LIBBSD_0.4 {
#if LIBBSD_ABI_CLOSEFROM
closefrom; closefrom;
#endif
#if LIBBSD_ABI_EXPAND_NUMBER
expand_number; expand_number;
#endif
} LIBBSD_0.3; } LIBBSD_0.3;
LIBBSD_0.5 { LIBBSD_0.5 {
#if LIBBSD_ABI_FGETLN
fgetwln; fgetwln;
fparseln; fparseln;
#endif
#if LIBBSD_ABI_PROCTITLE
/* Introduced in 0.2 as a stub, implemented in 0.5. */ /* Introduced in 0.2 as a stub, implemented in 0.5. */
setproctitle; setproctitle;
#endif
#if LIBBSD_ABI_STRNSTR
strnstr; strnstr;
#endif
#if LIBBSD_ABI_WCSL
wcslcat; wcslcat;
wcslcpy; wcslcpy;
#endif
} LIBBSD_0.4; } LIBBSD_0.4;
LIBBSD_0.6 { LIBBSD_0.6 {
#if LIBBSD_ABI_PROCTITLE
/* Exported to cope with the constructor+dlopen+threads mess. */ /* Exported to cope with the constructor+dlopen+threads mess. */
setproctitle_init; setproctitle_init;
#endif
} LIBBSD_0.5; } LIBBSD_0.5;
LIBBSD_0.7 { LIBBSD_0.7 {
#if LIBBSD_ABI_GETBSIZE
getbsize; getbsize;
#endif
#if LIBBSD_ABI_FUNOPEN /* This symbol might not be present on some specific systems, such
* as musl based ones. It might need to be removed on SOVERSION bump,
* as it cannot be portabily implemented everywhere. */
funopen; funopen;
#endif
#if LIBBSD_ABI_REALLOCARRAY
reallocarray; reallocarray;
#endif
#if LIBBSD_ABI_STRINGLIST
sl_init; sl_init;
sl_add; sl_add;
sl_free; sl_free;
sl_find; sl_find;
#endif
#if LIBBSD_ABI_TIMECONV
_time32_to_time; _time32_to_time;
_time_to_time32; _time_to_time32;
_time64_to_time; _time64_to_time;
@ -216,30 +136,20 @@ LIBBSD_0.7 {
_long_to_time; _long_to_time;
_time_to_int; _time_to_int;
_int_to_time; _int_to_time;
#endif
} LIBBSD_0.6; } LIBBSD_0.6;
LIBBSD_0.8 { LIBBSD_0.8 {
#if LIBBSD_ABI_EXPLICIT_BZERO
explicit_bzero; explicit_bzero;
#endif
} LIBBSD_0.7; } LIBBSD_0.7;
LIBBSD_0.9 { LIBBSD_0.9 {
#if LIBBSD_ABI_FLOPEN
flopenat; flopenat;
#endif
#if LIBBSD_ABI_PIDFILE
pidfile_fileno; pidfile_fileno;
#endif
#if LIBBSD_ABI_STRTOX
strtoi; strtoi;
strtou; strtou;
#endif
#if LIBBSD_ABI_VIS
nvis; nvis;
snvis; snvis;
stravis; stravis;
@ -251,21 +161,19 @@ LIBBSD_0.9 {
strsvis; strsvis;
strsvisx; strsvisx;
svis; svis;
#endif
} LIBBSD_0.8; } LIBBSD_0.8;
LIBBSD_0.9.1 { LIBBSD_0.9.1 {
#if LIBBSD_ABI_VIS
/* The strnvis() and strnunvis() symbols changed prototype to match /* The strnvis() and strnunvis() symbols changed prototype to match
* the NetBSD implementation. Provided as versioned nodes in 0.9.1, and * the NetBSD implementation. Provided as versioned nodes in 0.9.1, and
* exposed here explicitly so that we can redirect at compile-time. */ * exposed here explicitly so that we can redirect at compile-time. */
strnvis_netbsd; strnvis_netbsd;
strnunvis_netbsd; strnunvis_netbsd;
#endif
} LIBBSD_0.9; } LIBBSD_0.9;
LIBBSD_0.10.0 { LIBBSD_0.10.0 {
#if LIBBSD_ABI_ERR /* These BSD extensions are available on GNU systems, but not on other
* systems such as Windows or musl libc based ones. */
vwarn; vwarn;
vwarnx; vwarnx;
warn; warn;
@ -274,46 +182,16 @@ LIBBSD_0.10.0 {
verrx; verrx;
err; err;
errx; errx;
#endif
} LIBBSD_0.9.1; } LIBBSD_0.9.1;
LIBBSD_0.11.0 { LIBBSD_0.11.0 {
#if LIBBSD_ABI_VIS
strnvisx; strnvisx;
#endif
#if LIBBSD_ABI_RECALLOCARRAY
recallocarray; recallocarray;
#endif
#if LIBBSD_ABI_FREEZERO
freezero; freezero;
#endif
#if LIBBSD_ABI_ID_FROM_NAME
gid_from_group; gid_from_group;
uid_from_user;
#endif
#if LIBBSD_ABI_NAME_FROM_ID
user_from_uid;
group_from_gid; group_from_gid;
#endif uid_from_user;
user_from_uid;
} LIBBSD_0.10.0; } LIBBSD_0.10.0;
LIBBSD_0.12.0 {
#if LIBBSD_ABI_ASPRINTF
vasprintf;
asprintf;
#endif
#if LIBBSD_ABI_TIMECONV && LIBBSD_ABI_TIME64
_time32_to_time_time64;
_time_to_time32_time64;
_time64_to_time_time64;
_time_to_time64_time64;
_time_to_long_time64;
_long_to_time_time64;
_time_to_int_time64;
_int_to_time_time64;
#endif
} LIBBSD_0.11.0;

View File

@ -230,7 +230,7 @@
#if defined(__LITTLE_ENDIAN__) #if defined(__LITTLE_ENDIAN__)
#define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_DATA ELFDATA2LSB
#elif defined(__BIG_ENDIAN__) #elif defined(__BIG_ENDIAN__)
#define ELF_TARG_DATA ELFDATA2MSB #define ELF_TARG_DATA ELFDATA2LMSB
#else #else
#error Unknown SH endianness #error Unknown SH endianness
#endif #endif

View File

@ -29,56 +29,42 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifdef __ELF__
#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
#else
#define libbsd_link_warning(symbol, msg)
#endif
#if defined(__APPLE__) #ifdef __ELF__
#define libbsd_strong_alias(symbol, alias) \
__asm__(".globl _" #alias); \
__asm__(".set _" #alias ", _" #symbol); \
extern __typeof(symbol) alias
#elif !defined(_MSC_VER)
#define libbsd_strong_alias(symbol, alias) \
extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
#endif
#if defined(__ELF__) && !defined(__sun)
# if __has_attribute(symver) # if __has_attribute(symver)
/* The symver attribute is supported since gcc 10.x. */ /* The symver attribute is supported since gcc 10.x. */
#define libbsd_symver_default(symbol, alias, version) \ #define libbsd_symver_default(alias, symbol, version) \
extern __typeof__(symbol) symbol \ extern __typeof__(symbol) symbol \
__attribute__((__symver__(#alias "@@" #version))) __attribute__((__symver__(#alias "@@" #version)))
#define libbsd_symver_variant(symbol, alias, version) \ #define libbsd_symver_variant(alias, symbol, version) \
extern __typeof__(symbol) symbol \ extern __typeof__(symbol) symbol \
__attribute__((__symver__(#alias "@" #version))) __attribute__((__symver__(#alias "@" #version)))
#define libbsd_symver_weak(symbol, alias, version) \ #define libbsd_symver_weak(alias, symbol, version) \
extern __typeof__(symbol) symbol \ extern __typeof__(symbol) symbol \
__attribute__((__symver__(#alias "@" #version), __weak__)) __attribute__((__symver__(#alias "@" #version), __weak__))
# else # else
#define libbsd_symver_default(symbol, alias, version) \ #define libbsd_symver_default(alias, symbol, version) \
__asm__(".symver " #symbol "," #alias "@@" #version) __asm__(".symver " #symbol "," #alias "@@" #version)
#define libbsd_symver_variant(symbol, alias, version) \ #define libbsd_symver_variant(alias, symbol, version) \
__asm__(".symver " #symbol "," #alias "@" #version) __asm__(".symver " #symbol "," #alias "@" #version)
#define libbsd_symver_weak(symbol, alias, version) \ #define libbsd_symver_weak(alias, symbol, version) \
libbsd_symver_variant(symbol, alias, version); \ libbsd_symver_variant(alias, symbol, version); \
extern __typeof__(symbol) alias \ extern __typeof__(symbol) alias \
__attribute__((__weak__)) __attribute__((__weak__))
# endif # endif
#else #else
#define libbsd_symver_default(symbol, alias, version) \ #define libbsd_symver_default(alias, symbol, version) \
libbsd_strong_alias(symbol, alias) extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
#define libbsd_symver_variant(symbol, alias, version) #define libbsd_symver_variant(alias, symbol, version)
#define libbsd_symver_weak(symbol, alias, version) #define libbsd_symver_weak(alias, symbol, version)
#endif #endif
#endif #endif

View File

@ -37,7 +37,7 @@ libbsd_MD5Init(MD5_CTX *context)
libbsd_link_warning(MD5Init, libbsd_link_warning(MD5Init,
"The MD5Init() function in libbsd is a deprecated wrapper, " "The MD5Init() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Init, MD5Init, LIBBSD_0.0); libbsd_symver_weak(MD5Init, libbsd_MD5Init, LIBBSD_0.0);
void void
libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len) libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
@ -47,7 +47,7 @@ libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
libbsd_link_warning(MD5Update, libbsd_link_warning(MD5Update,
"The MD5Update() function in libbsd is a deprecated wrapper, " "The MD5Update() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Update, MD5Update, LIBBSD_0.0); libbsd_symver_weak(MD5Update, libbsd_MD5Update, LIBBSD_0.0);
void void
libbsd_MD5Pad(MD5_CTX *context) libbsd_MD5Pad(MD5_CTX *context)
@ -57,7 +57,7 @@ libbsd_MD5Pad(MD5_CTX *context)
libbsd_link_warning(MD5Pad, libbsd_link_warning(MD5Pad,
"The MD5Pad() function in libbsd is a deprecated wrapper, " "The MD5Pad() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Pad, MD5Pad, LIBBSD_0.0); libbsd_symver_weak(MD5Pad, libbsd_MD5Pad, LIBBSD_0.0);
void void
libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context) libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
@ -67,7 +67,7 @@ libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
libbsd_link_warning(MD5Final, libbsd_link_warning(MD5Final,
"The MD5Final() function in libbsd is a deprecated wrapper, " "The MD5Final() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Final, MD5Final, LIBBSD_0.0); libbsd_symver_weak(MD5Final, libbsd_MD5Final, LIBBSD_0.0);
void void
libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH]) libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
@ -77,7 +77,7 @@ libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
libbsd_link_warning(MD5Transform, libbsd_link_warning(MD5Transform,
"The MD5Transform() function in libbsd is a deprecated wrapper, " "The MD5Transform() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Transform, MD5Transform, LIBBSD_0.0); libbsd_symver_weak(MD5Transform, libbsd_MD5Transform, LIBBSD_0.0);
char * char *
libbsd_MD5End(MD5_CTX *context, char *buf) libbsd_MD5End(MD5_CTX *context, char *buf)
@ -87,7 +87,7 @@ libbsd_MD5End(MD5_CTX *context, char *buf)
libbsd_link_warning(MD5End, libbsd_link_warning(MD5End,
"The MD5End() function in libbsd is a deprecated wrapper, " "The MD5End() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5End, MD5End, LIBBSD_0.0); libbsd_symver_weak(MD5End, libbsd_MD5End, LIBBSD_0.0);
char * char *
libbsd_MD5File(const char *filename, char *buf) libbsd_MD5File(const char *filename, char *buf)
@ -97,7 +97,7 @@ libbsd_MD5File(const char *filename, char *buf)
libbsd_link_warning(MD5File, libbsd_link_warning(MD5File,
"The MD5File() function in libbsd is a deprecated wrapper, " "The MD5File() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5File, MD5File, LIBBSD_0.0); libbsd_symver_weak(MD5File, libbsd_MD5File, LIBBSD_0.0);
char * char *
libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length) libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
@ -107,7 +107,7 @@ libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
libbsd_link_warning(MD5FileChunk, libbsd_link_warning(MD5FileChunk,
"The MD5FileChunk() function in libbsd is a deprecated wrapper, " "The MD5FileChunk() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5FileChunk, MD5FileChunk, LIBBSD_0.0); libbsd_symver_weak(MD5FileChunk, libbsd_MD5FileChunk, LIBBSD_0.0);
char * char *
libbsd_MD5Data(const uint8_t *data, size_t len, char *buf) libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
@ -117,4 +117,4 @@ libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
libbsd_link_warning(MD5Data, libbsd_link_warning(MD5Data,
"The MD5Data() function in libbsd is a deprecated wrapper, " "The MD5Data() function in libbsd is a deprecated wrapper, "
"use libmd instead."); "use libmd instead.");
libbsd_symver_weak(libbsd_MD5Data, MD5Data, LIBBSD_0.0); libbsd_symver_weak(MD5Data, libbsd_MD5Data, LIBBSD_0.0);

View File

@ -84,8 +84,9 @@ static void insertionsort(unsigned char *, size_t, size_t,
*/ */
/* Assumption: PSIZE is a power of 2. */ /* Assumption: PSIZE is a power of 2. */
#define EVAL(p) (unsigned char **) \ #define EVAL(p) (unsigned char **) \
((unsigned char *)0 + \
(((unsigned char *)p + PSIZE - 1 - \ (((unsigned char *)p + PSIZE - 1 - \
(unsigned char *)0) & ~(PSIZE - 1)) (unsigned char *)0) & ~(PSIZE - 1)))
/* /*
* Arguments are as for qsort. * Arguments are as for qsort.

View File

@ -35,9 +35,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_PROCINFO_H
#include <procinfo.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -65,14 +62,6 @@ getprogname(void)
/* getexecname(3) returns an absolute pathname, normalize it. */ /* getexecname(3) returns an absolute pathname, normalize it. */
if (__progname == NULL) if (__progname == NULL)
setprogname(getexecname()); setprogname(getexecname());
#elif defined(_AIX)
if (__progname == NULL) {
struct procentry64 procs;
pid_t pid = getpid ();
if (getprocs64(&procs, sizeof procs, NULL, 0, &pid, 1) > 0)
__progname = strdup(procs.pi_comm);
}
#elif defined(_WIN32) #elif defined(_WIN32)
if (__progname == NULL) { if (__progname == NULL) {
WCHAR *wpath = NULL; WCHAR *wpath = NULL;
@ -137,8 +126,6 @@ done:
free(wpath); free(wpath);
free(mbname); free(mbname);
} }
#else
#error "Function getprogname() needs to be ported."
#endif #endif
return __progname; return __progname;

View File

@ -83,12 +83,8 @@ typedef struct gidc {
* cache both hits and misses. * cache both hits and misses.
*/ */
#ifndef HAVE_USER_FROM_UID
static UIDC **uidtb; /* uid to name cache */ static UIDC **uidtb; /* uid to name cache */
#endif
#ifndef HAVE_GROUP_FROM_GID
static GIDC **gidtb; /* gid to name cache */ static GIDC **gidtb; /* gid to name cache */
#endif
static UIDC **usrtb; /* user name to uid cache */ static UIDC **usrtb; /* user name to uid cache */
static GIDC **grptb; /* group name to gid cache */ static GIDC **grptb; /* group name to gid cache */
@ -107,7 +103,6 @@ st_hash(const char *name, size_t len, int tabsz)
return key % tabsz; return key % tabsz;
} }
#ifndef HAVE_USER_FROM_UID
/* /*
* uidtb_start * uidtb_start
* creates an an empty uidtb * creates an an empty uidtb
@ -129,9 +124,7 @@ uidtb_start(void)
} }
return 0; return 0;
} }
#endif
#ifndef HAVE_GROUP_FROM_GID
/* /*
* gidtb_start * gidtb_start
* creates an an empty gidtb * creates an an empty gidtb
@ -153,7 +146,6 @@ gidtb_start(void)
} }
return 0; return 0;
} }
#endif
/* /*
* usrtb_start * usrtb_start
@ -199,7 +191,6 @@ grptb_start(void)
return 0; return 0;
} }
#ifndef HAVE_USER_FROM_UID
/* /*
* user_from_uid() * user_from_uid()
* caches the name (if any) for the uid. If noname clear, we always * caches the name (if any) for the uid. If noname clear, we always
@ -260,9 +251,7 @@ user_from_uid(uid_t uid, int noname)
} }
return ptr->name; return ptr->name;
} }
#endif
#ifndef HAVE_GROUP_FROM_GID
/* /*
* group_from_gid() * group_from_gid()
* caches the name (if any) for the gid. If noname clear, we always * caches the name (if any) for the gid. If noname clear, we always
@ -323,7 +312,6 @@ group_from_gid(gid_t gid, int noname)
} }
return ptr->name; return ptr->name;
} }
#endif
/* /*
* uid_from_user() * uid_from_user()

View File

@ -36,15 +36,6 @@
#define TCSASOFT 0 #define TCSASOFT 0
#endif #endif
#ifndef _NSIG
#if defined(NSIG)
#define _NSIG NSIG
#else
/* The SIGRTMAX define might be set to a function such as sysconf(). */
#define _NSIG (SIGRTMAX + 1)
#endif
#endif
static volatile sig_atomic_t signo[_NSIG]; static volatile sig_atomic_t signo[_NSIG];
static void handler(int); static void handler(int);

View File

@ -36,7 +36,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stddef.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
@ -145,13 +144,12 @@ common: if (set->cmd2 & CMD2_CLR) {
#define ADDCMD(a, b, c, d) do { \ #define ADDCMD(a, b, c, d) do { \
if (set >= endset) { \ if (set >= endset) { \
ptrdiff_t setdiff = set - saveset; \
BITCMD *newset; \ BITCMD *newset; \
setlen += SET_LEN_INCR; \ setlen += SET_LEN_INCR; \
newset = reallocarray(saveset, setlen, sizeof(BITCMD)); \ newset = reallocarray(saveset, setlen, sizeof(BITCMD)); \
if (newset == NULL) \ if (newset == NULL) \
goto out; \ goto out; \
set = newset + setdiff; \ set = newset + (set - saveset); \
saveset = newset; \ saveset = newset; \
endset = newset + (setlen - 2); \ endset = newset + (setlen - 2); \
} \ } \

View File

@ -33,10 +33,6 @@
#include <string.h> #include <string.h>
#include "local-link.h" #include "local-link.h"
#if !HAVE_DECL_ENVIRON
extern char **environ;
#endif
static struct { static struct {
/* Original value. */ /* Original value. */
const char *arg0; const char *arg0;
@ -284,22 +280,24 @@ setproctitle_impl(const char *fmt, ...)
if (nul < SPT.nul) { if (nul < SPT.nul) {
*SPT.nul = '.'; *SPT.nul = '.';
} else if (nul == SPT.nul && (nul + 1) < SPT.end) { } else if (nul == SPT.nul && &nul[1] < SPT.end) {
*SPT.nul = ' '; *SPT.nul = ' ';
*++nul = '\0'; *++nul = '\0';
} }
} }
libbsd_symver_default(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. */
#if defined(libbsd_strong_alias) #ifdef HAVE_TYPEOF
libbsd_strong_alias(setproctitle_impl, setproctitle_stub); extern __typeof__(setproctitle_impl)
setproctitle_stub
__attribute__((__alias__("setproctitle_impl")));
#else #else
void void
setproctitle_stub(const char *fmt, ...) setproctitle_stub(const char *fmt, ...)
__attribute__((__alias__("setproctitle_impl"))); __attribute__((__alias__("setproctitle_impl")));
#endif #endif
libbsd_symver_variant(setproctitle_stub, setproctitle, LIBBSD_0.2); libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);

View File

@ -38,7 +38,7 @@
* *
* To avoid any other possible fallout, the constructor is split into a * To avoid any other possible fallout, the constructor is split into a
* new static library that needs to be linked explicitly into programs * new static library that needs to be linked explicitly into programs
* using setproctitle(). As an additional safety measure the pkgconf(1) * using setproctitle(). As an additional safety measure the pkg-config
* linker flags will mark the program as not allowing to be dlopen()ed * linker flags will mark the program as not allowing to be dlopen()ed
* so that we make sure to avoid the problem described above. * so that we make sure to avoid the problem described above.
*/ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: _strtoi.h,v 1.3 2024/01/20 16:13:39 christos Exp $ */ /* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */
/*- /*-
* Copyright (c) 1990, 1993 * Copyright (c) 1990, 1993
@ -32,7 +32,7 @@
* NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
* *
* Created by Kamil Rytarowski, based on ID: * Created by Kamil Rytarowski, based on ID:
* NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joe
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
@ -73,25 +73,25 @@ strtoi(const char *__restrict nptr,
*rstatus = errno; *rstatus = errno;
errno = serrno; errno = serrno;
/* No digits were found */ if (*rstatus == 0) {
if (*rstatus == 0 && nptr == *endptr) /* No digits were found */
*rstatus = ECANCELED; if (nptr == *endptr)
*rstatus = ECANCELED;
/* There are further characters after number */
else if (**endptr != '\0')
*rstatus = ENOTSUP;
}
if (im < lo) { if (im < lo) {
if (*rstatus == 0) if (*rstatus == 0)
*rstatus = ERANGE; *rstatus = ERANGE;
return lo; return lo;
} }
if (im > hi) { if (im > hi) {
if (*rstatus == 0) if (*rstatus == 0)
*rstatus = ERANGE; *rstatus = ERANGE;
return hi; return hi;
} }
/* There are further characters after number */
if (*rstatus == 0 && **endptr != '\0')
*rstatus = ENOTSUP;
return im; return im;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: strtonum.c,v 1.7 2024/01/20 16:13:39 christos Exp $ */ /* $NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $ */
/*- /*-
* Copyright (c) 2014 The NetBSD Foundation, Inc. * Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
@ -42,34 +42,21 @@ strtonum(const char *nptr, long long minval, long long maxval,
int e; int e;
long long rv; long long rv;
const char *resp; const char *resp;
char *eptr;
if (errstr == NULL) if (errstr == NULL)
errstr = &resp; errstr = &resp;
if (minval > maxval) rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, &e);
goto out;
rv = (long long)strtoi(nptr, &eptr, 10, minval, maxval, &e); if (e == 0) {
switch (e) {
case 0:
*errstr = NULL; *errstr = NULL;
return rv; return rv;
case ECANCELED:
case ENOTSUP:
case EINVAL:
goto out;
case ERANGE:
if (*eptr)
goto out;
*errstr = rv == maxval ? "too large" : "too small";
return 0;
default:
abort();
} }
out: if (e == ERANGE)
*errstr = "invalid"; *errstr = (rv == maxval ? "too large" : "too small");
else
*errstr = "invalid";
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: _strtoi.h,v 1.3 2024/01/20 16:13:39 christos Exp $ */ /* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */
/*- /*-
* Copyright (c) 1990, 1993 * Copyright (c) 1990, 1993
@ -73,25 +73,25 @@ strtou(const char *__restrict nptr,
*rstatus = errno; *rstatus = errno;
errno = serrno; errno = serrno;
/* No digits were found */ if (*rstatus == 0) {
if (*rstatus == 0 && nptr == *endptr) /* No digits were found */
*rstatus = ECANCELED; if (nptr == *endptr)
*rstatus = ECANCELED;
/* There are further characters after number */
else if (**endptr != '\0')
*rstatus = ENOTSUP;
}
if (im < lo) { if (im < lo) {
if (*rstatus == 0) if (*rstatus == 0)
*rstatus = ERANGE; *rstatus = ERANGE;
return lo; return lo;
} }
if (im > hi) { if (im > hi) {
if (*rstatus == 0) if (*rstatus == 0)
*rstatus = ERANGE; *rstatus = ERANGE;
return hi; return hi;
} }
/* There are further characters after number */
if (*rstatus == 0 && **endptr != '\0')
*rstatus = ENOTSUP;
return im; return im;
} }

Some files were not shown because too many files have changed in this diff Show More