├── .gitignore
├── .gitlab-ci.yml
├── COPYING
├── Makefile.am
├── README
├── TODO
├── autogen
├── configure.ac
├── get-version
├── include
├── Makefile.am
└── bsd
│ ├── bitstring.h
│ ├── bsd.h
│ ├── err.h
│ ├── getopt.h
│ ├── grp.h
│ ├── inttypes.h
│ ├── libutil.h
│ ├── md5.h
│ ├── netinet
│ └── ip_icmp.h
│ ├── nlist.h
│ ├── pwd.h
│ ├── readpassphrase.h
│ ├── stdio.h
│ ├── stdlib.h
│ ├── string.h
│ ├── stringlist.h
│ ├── sys
│ ├── bitstring.h
│ ├── cdefs.h
│ ├── endian.h
│ ├── param.h
│ ├── poll.h
│ ├── queue.h
│ ├── time.h
│ └── tree.h
│ ├── timeconv.h
│ ├── unistd.h
│ ├── vis.h
│ └── wchar.h
├── m4
├── .gitignore
├── libbsd-compiler.m4
├── libbsd-funcs.m4
├── libbsd-large.m4
└── libbsd-linker.m4
├── man
├── .gitignore
├── LIST_CLASS_ENTRY.3bsd
├── LIST_CLASS_HEAD.3bsd
├── LIST_EMPTY.3bsd
├── LIST_ENTRY.3bsd
├── LIST_FIRST.3bsd
├── LIST_FOREACH.3bsd
├── LIST_FOREACH_FROM.3bsd
├── LIST_FOREACH_FROM_SAFE.3bsd
├── LIST_FOREACH_SAFE.3bsd
├── LIST_HEAD.3bsd
├── LIST_HEAD_INITIALIZER.3bsd
├── LIST_INIT.3bsd
├── LIST_INSERT_AFTER.3bsd
├── LIST_INSERT_BEFORE.3bsd
├── LIST_INSERT_HEAD.3bsd
├── LIST_NEXT.3bsd
├── LIST_PREV.3bsd
├── LIST_REMOVE.3bsd
├── LIST_SWAP.3bsd
├── Makefile.am
├── RB_EMPTY.3bsd
├── RB_ENTRY.3bsd
├── RB_FIND.3bsd
├── RB_FOREACH.3bsd
├── RB_FOREACH_REVERSE.3bsd
├── RB_GENERATE.3bsd
├── RB_GENERATE_STATIC.3bsd
├── RB_HEAD.3bsd
├── RB_INIT.3bsd
├── RB_INITIALIZER.3bsd
├── RB_INSERT.3bsd
├── RB_LEFT.3bsd
├── RB_MAX.3bsd
├── RB_MIN.3bsd
├── RB_NEXT.3bsd
├── RB_NFIND.3bsd
├── RB_PARENT.3bsd
├── RB_PREV.3bsd
├── RB_PROTOTYPE.3bsd
├── RB_PROTOTYPE_STATIC.3bsd
├── RB_REMOVE.3bsd
├── RB_RIGHT.3bsd
├── RB_ROOT.3bsd
├── SLIST_CLASS_ENTRY.3bsd
├── SLIST_CLASS_HEAD.3bsd
├── SLIST_EMPTY.3bsd
├── SLIST_ENTRY.3bsd
├── SLIST_FIRST.3bsd
├── SLIST_FOREACH.3bsd
├── SLIST_FOREACH_FROM.3bsd
├── SLIST_FOREACH_FROM_SAFE.3bsd
├── SLIST_FOREACH_SAFE.3bsd
├── SLIST_HEAD.3bsd
├── SLIST_HEAD_INITIALIZER.3bsd
├── SLIST_INIT.3bsd
├── SLIST_INSERT_AFTER.3bsd
├── SLIST_INSERT_HEAD.3bsd
├── SLIST_NEXT.3bsd
├── SLIST_REMOVE.3bsd
├── SLIST_REMOVE_AFTER.3bsd
├── SLIST_REMOVE_HEAD.3bsd
├── SLIST_REMOVE_PREVPTR.3bsd
├── SLIST_SWAP.3bsd
├── SPLAY_EMPTY.3bsd
├── SPLAY_ENTRY.3bsd
├── SPLAY_FIND.3bsd
├── SPLAY_FOREACH.3bsd
├── SPLAY_GENERATE.3bsd
├── SPLAY_HEAD.3bsd
├── SPLAY_INIT.3bsd
├── SPLAY_INITIALIZER.3bsd
├── SPLAY_INSERT.3bsd
├── SPLAY_LEFT.3bsd
├── SPLAY_MAX.3bsd
├── SPLAY_MIN.3bsd
├── SPLAY_NEXT.3bsd
├── SPLAY_PROTOTYPE.3bsd
├── SPLAY_REMOVE.3bsd
├── SPLAY_RIGHT.3bsd
├── SPLAY_ROOT.3bsd
├── STAILQ_CLASS_ENTRY.3bsd
├── STAILQ_CLASS_HEAD.3bsd
├── STAILQ_CONCAT.3bsd
├── STAILQ_EMPTY.3bsd
├── STAILQ_ENTRY.3bsd
├── STAILQ_FIRST.3bsd
├── STAILQ_FOREACH.3bsd
├── STAILQ_FOREACH_FROM.3bsd
├── STAILQ_FOREACH_FROM_SAFE.3bsd
├── STAILQ_FOREACH_SAFE.3bsd
├── STAILQ_HEAD.3bsd
├── STAILQ_HEAD_INITIALIZER.3bsd
├── STAILQ_INIT.3bsd
├── STAILQ_INSERT_AFTER.3bsd
├── STAILQ_INSERT_HEAD.3bsd
├── STAILQ_INSERT_TAIL.3bsd
├── STAILQ_LAST.3bsd
├── STAILQ_NEXT.3bsd
├── STAILQ_REMOVE.3bsd
├── STAILQ_REMOVE_AFTER.3bsd
├── STAILQ_REMOVE_HEAD.3bsd
├── STAILQ_SWAP.3bsd
├── TAILQ_CLASS_ENTRY.3bsd
├── TAILQ_CLASS_HEAD.3bsd
├── TAILQ_CONCAT.3bsd
├── TAILQ_EMPTY.3bsd
├── TAILQ_ENTRY.3bsd
├── TAILQ_FIRST.3bsd
├── TAILQ_FOREACH.3bsd
├── TAILQ_FOREACH_FROM.3bsd
├── TAILQ_FOREACH_FROM_SAFE.3bsd
├── TAILQ_FOREACH_REVERSE.3bsd
├── TAILQ_FOREACH_REVERSE_FROM.3bsd
├── TAILQ_FOREACH_REVERSE_FROM_SAFE.3bsd
├── TAILQ_FOREACH_REVERSE_SAFE.3bsd
├── TAILQ_FOREACH_SAFE.3bsd
├── TAILQ_HEAD.3bsd
├── TAILQ_HEAD_INITIALIZER.3bsd
├── TAILQ_INIT.3bsd
├── TAILQ_INSERT_AFTER.3bsd
├── TAILQ_INSERT_BEFORE.3bsd
├── TAILQ_INSERT_HEAD.3bsd
├── TAILQ_INSERT_TAIL.3bsd
├── TAILQ_LAST.3bsd
├── TAILQ_NEXT.3bsd
├── TAILQ_PREV.3bsd
├── TAILQ_REMOVE.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
├── be16enc.3bsd
├── be32dec.3bsd
├── be32enc.3bsd
├── be64dec.3bsd
├── be64enc.3bsd
├── bit_alloc.3bsd
├── bit_clear.3bsd
├── bit_decl.3bsd
├── bit_ffc.3bsd
├── bit_ffs.3bsd
├── bit_nclear.3bsd
├── bit_nset.3bsd
├── bit_set.3bsd
├── bit_test.3bsd
├── bitstr_size.3bsd
├── bitstring.3bsd
├── byteorder.3bsd
├── closefrom.3bsd
├── dehumanize_number.3bsd
├── errc.3bsd
├── expand_number.3bsd
├── explicit_bzero.3bsd
├── fgetln.3bsd
├── fgetwln.3bsd
├── flopen.3bsd
├── fmtcheck.3bsd
├── fparseln.3bsd
├── fpurge.3bsd
├── freezero.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
├── le16enc.3bsd
├── le32dec.3bsd
├── le32enc.3bsd
├── le64dec.3bsd
├── le64enc.3bsd
├── libbsd.7
├── mdX.3bsd
├── mergesort.3bsd
├── nlist.3bsd
├── pidfile.3bsd
├── pidfile_close.3bsd
├── pidfile_open.3bsd
├── pidfile_remove.3bsd
├── pidfile_write.3bsd
├── pwcache.3bsd
├── queue.3bsd
├── radixsort.3bsd
├── readpassphrase.3bsd
├── reallocarray.3bsd
├── reallocf.3bsd
├── recallocarray.3bsd
├── setmode.3bsd
├── setproctitle.3bsd
├── setproctitle_init.3bsd
├── setprogname.3bsd
├── sl_add.3bsd
├── sl_delete.3bsd
├── sl_find.3bsd
├── sl_free.3bsd
├── sl_init.3bsd
├── sradixsort.3bsd
├── stringlist.3bsd
├── strlcat.3bsd
├── strlcpy.3bsd
├── strmode.3bsd
├── strnstr.3bsd
├── strnunvis.3bsd
├── strnvis.3bsd
├── strtoi.3bsd
├── strtonum.3bsd
├── strtou.3bsd
├── strunvis.3bsd
├── strvis.3bsd
├── strvisx.3bsd
├── timeradd.3bsd
├── timerclear.3bsd
├── timercmp.3bsd
├── timerisset.3bsd
├── timersub.3bsd
├── timespecadd.3bsd
├── timespecclear.3bsd
├── timespeccmp.3bsd
├── timespecisset.3bsd
├── timespecsub.3bsd
├── tree.3bsd
├── uid_from_user.3bsd
├── unvis.3bsd
├── user_from_uid.3bsd
├── verrc.3bsd
├── vis.3bsd
├── vwarnc.3bsd
├── warnc.3bsd
├── wcslcat.3bsd
└── wcslcpy.3bsd
├── src
├── Makefile.am
├── arc4random.c
├── arc4random.h
├── arc4random_linux.h
├── arc4random_uniform.c
├── arc4random_unix.h
├── arc4random_win.h
├── asprintf.c
├── bsd_getopt.c
├── chacha_private.h
├── closefrom.c
├── dehumanize_number.c
├── err.c
├── errc.c
├── expand_number.c
├── explicit_bzero.c
├── fgetln.c
├── fgetwln.c
├── flopen.c
├── fmtcheck.c
├── fparseln.c
├── fpurge.c
├── freezero.c
├── funopen.c
├── getbsize.c
├── getentropy.c
├── getentropy_aix.c
├── getentropy_bsd.c
├── getentropy_hpux.c
├── getentropy_hurd.c
├── getentropy_linux.c
├── getentropy_osx.c
├── getentropy_solaris.c
├── getentropy_win.c
├── getpeereid.c
├── heapsort.c
├── humanize_number.c
├── inet_net_pton.c
├── libbsd-ctor.pc.in
├── libbsd-overlay.pc.in
├── libbsd.map.in
├── libbsd.pc.in
├── local-elf.h
├── local-link.h
├── md5.c
├── merge.c
├── nlist.c
├── pidfile.c
├── progname.c
├── pwcache.c
├── radixsort.c
├── readpassphrase.c
├── reallocarray.c
├── reallocf.c
├── recallocarray.c
├── setmode.c
├── setproctitle.c
├── setproctitle_ctor.c
├── stringlist.c
├── strlcat.c
├── strlcpy.c
├── strmode.c
├── strnstr.c
├── strtoi.c
├── strtonum.c
├── strtou.c
├── timeconv.c
├── unvis.c
├── vasprintf.c
├── vis.c
├── wcslcat.c
└── wcslcpy.c
└── test
├── .gitignore
├── Makefile.am
├── arc4random.c
├── bzero.c
├── closefrom.c
├── endian.c
├── explicit_bzero.c
├── fgetln.c
├── fparseln.c
├── fpurge.c
├── funopen.c
├── headers-overlay.sh
├── headers-system.sh
├── humanize.c
├── md5.c
├── nlist.c
├── overlay.c
├── proctitle.c
├── progname.c
├── pwcache.c
├── setmode.c
├── strl.c
├── strmode.c
├── strnstr.c
├── strtonum.c
├── test-stream.c
├── test-stream.h
├── timeconv32.c
├── timeconv64.c
├── vis-openbsd.c
└── vis.c
/.gitignore:
--------------------------------------------------------------------------------
1 | ChangeLog
2 | *~
3 | *.pc
4 | *.la
5 | *.lo
6 | *.o
7 | *.so*
8 | *.a
9 | *.log
10 | *.trs
11 | *.gcda
12 | *.gcno
13 | *.sym
14 | *.map
15 | .dirstamp
16 | .deps/
17 | .libs/
18 | Makefile
19 | Makefile.in
20 | aclocal.m4
21 | autom4te.cache/
22 | build-aux/
23 | configure
24 | config.*
25 | format.ld
26 | libtool
27 | stamp-h1
28 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | .vpath-tests:
2 | script:
3 | - ./autogen
4 | - mkdir -p build-tree
5 | - cd build-tree
6 | - ../configure
7 | - make check
8 |
9 | .unit-tests:
10 | script:
11 | - ./autogen && ./configure
12 | - make check
13 |
14 | .unit-tests-asan:
15 | script:
16 | - ./autogen && ./configure --enable-sanitize
17 | - make check
18 |
19 | .coverage:
20 | script:
21 | - ./autogen && ./configure --disable-static
22 | - make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
23 | - gcovr -s -e test/
24 | coverage: /^TOTAL.*\s+(\d+\%)$/
25 |
26 | .debian:
27 | image: debian:latest
28 | stage: test
29 | before_script:
30 | - apt-get update -qq
31 | - apt-get install -qq -y --no-install-recommends
32 | git gcc make autoconf automake libtool libmd-dev gcovr
33 |
34 | .alpine:
35 | image: alpine:latest
36 | stage: test
37 | before_script:
38 | - apk add --no-cache git gcc make autoconf automake libtool
39 | bsd-compat-headers linux-headers libmd-dev musl-dev gcovr
40 |
41 | vpath-tests:debian:
42 | extends: [.debian, .vpath-tests]
43 |
44 | unit-tests:debian:
45 | extends: [.debian, .unit-tests-asan]
46 |
47 | coverage:debian:
48 | extends: [.debian, .coverage]
49 |
50 | unit-tests:alpine:
51 | extends: [.alpine, .unit-tests]
52 |
53 | coverage:alpine:
54 | extends: [.alpine, .coverage]
55 |
--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | ## Process this file with automake to produce Makefile.in
2 |
3 | SUBDIRS = \
4 | include \
5 | man \
6 | src \
7 | test \
8 | # EOL
9 |
10 | ACLOCAL_AMFLAGS = -I m4
11 |
12 | EXTRA_DIST = \
13 | autogen \
14 | get-version \
15 | # EOL
16 |
17 | dist-hook:
18 | echo $(VERSION) >$(distdir)/.dist-version
19 | if [ -d .git ]; then \
20 | XDG_CONFIG_HOME= HOME= git log --stat -C >$(distdir)/ChangeLog; \
21 | fi
22 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | libbsd - Utility functions from BSD systems
2 |
3 | This library provides useful functions commonly found on BSD systems,
4 | and lacking on others like GNU systems, thus making it easier to port
5 | projects with strong BSD origins, without needing to embed the same
6 | code over and over again on each project.
7 |
8 | A BSD compatible message-digest library is required, on systems where
9 | this is not provided by its libc or libmd libraries, the canonical
10 | implementation to use is .
11 |
12 |
13 | Releases
14 | --------
15 |
16 |
17 |
18 |
19 | Mailing List
20 | ------------
21 |
22 | The subscription interface and web archives can be found at:
23 |
24 |
25 |
26 | The mail address is:
27 |
28 | libbsd@lists.freedesktop.org
29 |
30 |
31 | Source Repository
32 | -----------------
33 |
34 | The primary repository can be browsed at:
35 |
36 |
37 |
38 | and cloned from:
39 |
40 |
41 |
42 |
43 | Building from git source
44 | ------------------------
45 |
46 | To prepare the libbsd source tree from git before starting the build process
47 | some required software needs to be installed:
48 |
49 | GNU autoconf >= 2.67
50 | GNU automake >= 1.9
51 | GNU libtool >= 2.0
52 |
53 | After installing the needed software, and running the following command on
54 | the git tree:
55 |
56 | $ ./autogen
57 |
58 | the source should be roughly equivalent to the distributed tar source.
59 |
60 |
61 | Building from tar source
62 | ------------------------
63 |
64 | The minimum software required to configure and build dpkg from a tarball is:
65 |
66 | C89 compiler
67 | make
68 |
69 | The following software might be required depending on the system:
70 |
71 | libmd (whenever the libc does not provide the needed digest functions)
72 |
73 | The build process is done by running the usual «./configure; make». To
74 | see all available configuration options please run «./configure --help».
75 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | * Migrate portable functions from GNU/kFreeBSD's libfreebsd.
2 | * Add more functions used by ported packages (check openssh).
3 | * Add more unit tests.
4 | * Add missing man pages.
5 | - bsd_getopt.
6 | - timeconv?
7 | * Add a README.import file.
8 | * Update man pages:
9 | - Document when each interface was added on every BSD, and libbsd.
10 | * Handle LFS properly. By default the library emits LFS objects, but might
11 | be used by non-LFS objects. We should either provide foo and foo64
12 | functions and appropriate mappings on _FILE_OFFSET_BITS=64,
13 | _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE. Or error out when the off_t
14 | used by the code including us does not match a 64-bit type.
15 |
--------------------------------------------------------------------------------
/autogen:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | mkdir -p m4
4 | autoreconf -f -i
5 | rm -rf autom4te.cache
6 |
--------------------------------------------------------------------------------
/get-version:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # get-version
4 | #
5 | # Copyright © 2009 Guillem Jover
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions
9 | # are met:
10 | # 1. Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. The name of the author may not be used to endorse or promote products
16 | # derived from this software without specific prior written permission.
17 | #
18 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 | # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 | # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | if [ -f .dist-version ]; then
30 | # Get the version from the file distributed in the tarball.
31 | version=$(cat .dist-version)
32 | elif [ -d .git ]; then
33 | # Ger the version from the git repository.
34 | version=$(git describe --abbrev=4 HEAD 2>/dev/null)
35 |
36 | # Check if we are on a dirty checkout.
37 | git update-index --refresh -q >/dev/null
38 | dirty=$(git diff-index --name-only HEAD 2>/dev/null)
39 | if [ -n "$dirty" ]; then
40 | version="$version-dirty"
41 | fi
42 | else
43 | echo "error: cannot get project version." 1>&2
44 | exit 1
45 | fi
46 |
47 | # Use printf to avoid the trailing new line that m4_esyscmd would not handle.
48 | printf "$version"
49 |
--------------------------------------------------------------------------------
/include/Makefile.am:
--------------------------------------------------------------------------------
1 | ## Process this file with automake to produce Makefile.in
2 |
3 | nobase_include_HEADERS = \
4 | bsd/sys/bitstring.h \
5 | bsd/sys/cdefs.h \
6 | bsd/sys/endian.h \
7 | bsd/sys/param.h \
8 | bsd/sys/poll.h \
9 | bsd/sys/queue.h \
10 | bsd/sys/time.h \
11 | bsd/sys/tree.h \
12 | bsd/netinet/ip_icmp.h \
13 | bsd/bitstring.h \
14 | bsd/bsd.h \
15 | bsd/inttypes.h \
16 | bsd/libutil.h \
17 | bsd/stdio.h \
18 | bsd/stdlib.h \
19 | bsd/string.h \
20 | bsd/unistd.h \
21 | bsd/wchar.h \
22 | # EOL
23 |
24 | if ABI_ERR_H
25 | nobase_include_HEADERS += \
26 | bsd/err.h \
27 | # EOL
28 | endif
29 |
30 | if ABI_BSD_GETOPT
31 | nobase_include_HEADERS += \
32 | bsd/getopt.h \
33 | # EOL
34 | endif
35 |
36 | if ABI_MD5
37 | nobase_include_HEADERS += \
38 | bsd/md5.h \
39 | # EOL
40 | endif
41 |
42 | if ABI_NLIST
43 | nobase_include_HEADERS += \
44 | bsd/nlist.h \
45 | # EOL
46 | endif
47 |
48 | if ABI_READPASSPHRASE
49 | nobase_include_HEADERS += \
50 | bsd/readpassphrase.h \
51 | # EOL
52 | endif
53 |
54 | if ABI_PWCACHE
55 | nobase_include_HEADERS += \
56 | bsd/grp.h \
57 | bsd/pwd.h \
58 | # EOL
59 | endif
60 |
61 | if ABI_STRINGLIST
62 | nobase_include_HEADERS += \
63 | bsd/stringlist.h \
64 | # EOL
65 | endif
66 |
67 | if ABI_TIMECONV
68 | nobase_include_HEADERS += \
69 | bsd/timeconv.h \
70 | # EOL
71 | endif
72 |
73 | if ABI_VIS
74 | nobase_include_HEADERS += \
75 | bsd/vis.h \
76 | # EOL
77 | endif
78 |
79 | do_header_subst = $(AM_V_GEN) $(SED) \
80 | -e 's:^//\(.define LIBBSD_SYS_TIME_BITS\).*:\1 $(LIBBSD_SYS_TIME_BITS):' \
81 | -e 's:^//\(.define LIBBSD_SYS_HAS_TIME64\).*:\1 $(LIBBSD_SYS_HAS_TIME64):' \
82 | # EOL
83 |
84 | install-data-hook:
85 | $(do_header_subst) <$(DESTDIR)$(includedir)/bsd/sys/cdefs.h \
86 | >$(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new
87 | mv $(DESTDIR)$(includedir)/bsd/sys/cdefs.h.new \
88 | $(DESTDIR)$(includedir)/bsd/sys/cdefs.h
89 |
--------------------------------------------------------------------------------
/include/bsd/bitstring.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | /* For compatibility with NetBSD and OpenBSD. */
28 | #ifdef LIBBSD_OVERLAY
29 | #include
30 | #else
31 | #include
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/bsd/bsd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2004, 2005, 2006 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef LIBBSD_H
28 | #define LIBBSD_H
29 |
30 | #ifdef LIBBSD_OVERLAY
31 | #warning "This header is meant to be used w/o the libbsd overlay."
32 | #else
33 | /*
34 | * Include all bsd compat headers.
35 | */
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #endif
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/include/bsd/err.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2006 Robert Millan
3 | * Copyright © 2009, 2011 Guillem Jover
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #ifdef LIBBSD_OVERLAY
29 | #include
30 | #if __has_include_next()
31 | #include_next
32 | #else
33 | #define LIBBSD_NEED_ERR_H_FUNCS
34 | #endif
35 | #else
36 | #include
37 | #if __has_include()
38 | #include
39 | #else
40 | #define LIBBSD_NEED_ERR_H_FUNCS
41 | #endif
42 | #endif
43 |
44 | #ifndef LIBBSD_ERR_H
45 | #define LIBBSD_ERR_H
46 |
47 | #include
48 |
49 | __BEGIN_DECLS
50 | void vwarnc(int code, const char *format, va_list ap)
51 | __printflike(2, 0);
52 | void warnc(int code, const char *format, ...)
53 | __printflike(2, 3);
54 |
55 | void verrc(int status, int code, const char *format, va_list ap)
56 | __printflike(3, 0) __dead2;
57 | void errc(int status, int code, const char *format, ...)
58 | __printflike(3, 4) __dead2;
59 |
60 | #ifdef LIBBSD_NEED_ERR_H_FUNCS
61 | void vwarn(const char *format, va_list ap)
62 | __printflike(1, 0);
63 | void vwarnx(const char *format, va_list ap)
64 | __printflike(1, 0);
65 | void warn(const char *format, ...)
66 | __printflike(1, 2);
67 | void warnx(const char *format, ...)
68 | __printflike(1, 2);
69 |
70 | void verr(int status, const char *format, va_list ap)
71 | __printflike(2, 0) __dead2;
72 | void verrx(int status, const char *format, va_list ap)
73 | __printflike(2, 0) __dead2;
74 | void err(int status, const char *format, ...)
75 | __printflike(2, 3) __dead2;
76 | void errx(int status, const char *format, ...)
77 | __printflike(2, 3) __dead2;
78 | #endif
79 | __END_DECLS
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/include/bsd/getopt.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2011 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include
29 | #if __has_include_next()
30 | #include_next
31 | #endif
32 | #include
33 | #else
34 | #include
35 | #if __has_include()
36 | #include
37 | #endif
38 | #include
39 | #endif
40 |
--------------------------------------------------------------------------------
/include/bsd/grp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2021 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include
29 | #if __has_include_next()
30 | #include_next
31 | #endif
32 | #else
33 | #include
34 | #if __has_include()
35 | #include
36 | #endif
37 | #endif
38 |
39 | #ifndef LIBBSD_GRP_H
40 | #define LIBBSD_GRP_H
41 |
42 | #define _GR_BUF_LEN (1024 + 200 * sizeof(char *))
43 |
44 | __BEGIN_DECLS
45 | int
46 | gid_from_group(const char *, gid_t *);
47 | #ifndef __APPLE__
48 | const char *
49 | group_from_gid(gid_t, int);
50 | #endif
51 | __END_DECLS
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/bsd/inttypes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2018 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include_next
29 | #else
30 | #include
31 | #endif
32 |
33 | #ifndef LIBBSD_INTTYPES_H
34 | #define LIBBSD_INTTYPES_H
35 |
36 | #ifdef LIBBSD_OVERLAY
37 | #include
38 | #else
39 | #include
40 | #endif
41 |
42 | __BEGIN_DECLS
43 | intmax_t strtoi(const char *__restrict nptr, char **__restrict endptr,
44 | int base, intmax_t lo, intmax_t hi, int *rstatus);
45 | uintmax_t strtou(const char *__restrict nptr, char **__restrict endptr,
46 | int base, uintmax_t lo, uintmax_t hi, int *rstatus);
47 | __END_DECLS
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/include/bsd/md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2021 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef _AIX
28 | #ifdef LIBBSD_OVERLAY
29 | #include_next
30 | #else
31 | #include
32 | #endif
33 | #endif
34 |
--------------------------------------------------------------------------------
/include/bsd/pwd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2021 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include
29 | #if __has_include_next()
30 | #include_next
31 | #endif
32 | #else
33 | #include
34 | #if __has_include()
35 | #include
36 | #endif
37 | #endif
38 |
39 | #ifndef LIBBSD_PWD_H
40 | #define LIBBSD_PWD_H
41 |
42 | #define _PW_BUF_LEN 1024 /* length of getpw*_r buffer */
43 |
44 | __BEGIN_DECLS
45 | int
46 | uid_from_user(const char *, uid_t *);
47 | #ifndef __APPLE__
48 | const char *
49 | user_from_uid(uid_t, int);
50 | #endif
51 | __END_DECLS
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/bsd/readpassphrase.h:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: readpassphrase.h,v 1.4 2003/06/03 01:52:39 millert Exp $ */
2 |
3 | /*
4 | * Copyright (c) 2000, 2002 Todd C. Miller
5 | *
6 | * Permission to use, copy, modify, and distribute this software for any
7 | * purpose with or without fee is hereby granted, provided that the above
8 | * copyright notice and this permission notice appear in all copies.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 | *
18 | * Sponsored in part by the Defense Advanced Research Projects
19 | * Agency (DARPA) and Air Force Research Laboratory, Air Force
20 | * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21 | */
22 |
23 | #ifndef LIBBSD_READPASSPHRASE_H
24 | #define LIBBSD_READPASSPHRASE_H
25 |
26 | #define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
27 | #define RPP_ECHO_ON 0x01 /* Leave echo on. */
28 | #define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
29 | #define RPP_FORCELOWER 0x04 /* Force input to lower case. */
30 | #define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
31 | #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
32 | #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
33 |
34 | #ifdef LIBBSD_OVERLAY
35 | #include
36 | #else
37 | #include
38 | #endif
39 | #include
40 |
41 | __BEGIN_DECLS
42 | char * readpassphrase(const char *, char *, size_t, int);
43 | __END_DECLS
44 |
45 | #endif /* !LIBBSD_READPASSPHRASE_H */
46 |
--------------------------------------------------------------------------------
/include/bsd/string.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2004, 2005, 2009, 2011 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include_next
29 | #else
30 | #include
31 | #endif
32 |
33 | #ifndef LIBBSD_STRING_H
34 | #define LIBBSD_STRING_H
35 |
36 | #ifdef LIBBSD_OVERLAY
37 | #include
38 | #else
39 | #include
40 | #endif
41 | #include
42 |
43 | __BEGIN_DECLS
44 | #if !defined(__APPLE__) && \
45 | (!defined(__GLIBC__) || !__GLIBC_PREREQ(2, 38) || !defined(_DEFAULT_SOURCE))
46 | size_t strlcpy(char *dst, const char *src, size_t siz);
47 | size_t strlcat(char *dst, const char *src, size_t siz);
48 | #endif
49 | char *strnstr(const char *str, const char *find, size_t str_len);
50 | #ifndef __APPLE__
51 | void strmode(mode_t mode, char *str);
52 | #endif
53 |
54 | #if !defined(__GLIBC__) || \
55 | !__GLIBC_PREREQ(2, 25) || \
56 | !defined(_DEFAULT_SOURCE)
57 | void explicit_bzero(void *buf, size_t len);
58 | #endif
59 | __END_DECLS
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/include/bsd/stringlist.h:
--------------------------------------------------------------------------------
1 | /* $NetBSD: stringlist.h,v 1.6 2006/07/27 15:37:19 christos Exp $ */
2 |
3 | /*-
4 | * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 | * All rights reserved.
6 | *
7 | * This code is derived from software contributed to The NetBSD Foundation
8 | * by Christos Zoulas.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | * POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | #ifndef LIBBSD_STRINGLIST_H
33 | #define LIBBSD_STRINGLIST_H
34 |
35 | #ifdef LIBBSD_OVERLAY
36 | #include
37 | #else
38 | #include
39 | #endif
40 | #include
41 |
42 | /*
43 | * Simple string list
44 | */
45 | typedef struct _stringlist {
46 | char **sl_str;
47 | size_t sl_max;
48 | size_t sl_cur;
49 | } StringList;
50 |
51 | __BEGIN_DECLS
52 | StringList *sl_init(void);
53 | int sl_add(StringList *, char *);
54 | void sl_free(StringList *, int);
55 | char *sl_find(StringList *, const char *);
56 | int sl_delete(StringList *, const char *, int);
57 | __END_DECLS
58 |
59 | #endif /* LIBBSD_STRINGLIST_H */
60 |
--------------------------------------------------------------------------------
/include/bsd/sys/param.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2018 Facebook, Inc.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include
29 | #if __has_include_next()
30 | #include_next
31 | #endif
32 | #else
33 | #include
34 | #if __has_include()
35 | #include
36 | #endif
37 | #endif
38 |
39 | #ifndef LIBBSD_SYS_PARAM_H
40 | #define LIBBSD_SYS_PARAM_H
41 |
42 | #ifndef MIN
43 | #define MIN(x, y) (((x) < (y)) ? (x) : (y))
44 | #endif
45 | #ifndef MAX
46 | #define MAX(x, y) (((x) > (y)) ? (x) : (y))
47 | #endif
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/include/bsd/sys/poll.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2011 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifdef LIBBSD_OVERLAY
28 | #include_next
29 | #else
30 | #include
31 | #endif
32 |
33 | #ifndef LIBBSD_SYS_POLL_H
34 | #define LIBBSD_SYS_POLL_H
35 |
36 | #ifndef INFTIM
37 | #define INFTIM (-1)
38 | #endif
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/include/bsd/unistd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2006 Robert Millan
3 | * Copyright © 2008-2011 Guillem Jover
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #ifdef LIBBSD_OVERLAY
29 | #include
30 | #if __has_include_next()
31 | #include_next
32 | #endif
33 | #else
34 | #include
35 | #if __has_include()
36 | #include
37 | #endif
38 | #endif
39 |
40 | #ifndef LIBBSD_UNISTD_H
41 | #define LIBBSD_UNISTD_H
42 |
43 | #include
44 |
45 | #if !defined(S_ISTXT) && defined(S_ISVTX)
46 | #define S_ISTXT S_ISVTX
47 | #endif
48 |
49 | __BEGIN_DECLS
50 | #if !defined(__APPLE__)
51 | extern int optreset;
52 |
53 | #ifdef LIBBSD_OVERLAY
54 | #undef getopt
55 | #define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr)
56 | #endif
57 |
58 | int bsd_getopt(int argc, char * const argv[], const char *shortopts);
59 | #endif
60 |
61 | mode_t getmode(const void *set, mode_t mode);
62 | void *setmode(const char *mode_str);
63 |
64 | #if !defined(__GLIBC__) || \
65 | !__GLIBC_PREREQ(2, 34) || \
66 | !defined(_DEFAULT_SOURCE)
67 | void closefrom(int lowfd);
68 | #endif
69 |
70 | /* Compatibility with sendmail implementations. */
71 | #define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))
72 |
73 | void setproctitle_init(int argc, char *argv[], char *envp[]);
74 | void setproctitle(const char *fmt, ...)
75 | __printflike(1, 2);
76 |
77 | int getpeereid(int s, uid_t *euid, gid_t *egid);
78 | __END_DECLS
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/include/bsd/wchar.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012-2013 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #if defined(__need_wchar_t) || defined(__need_wint_t) || \
28 | defined(__need_mbstate_t)
29 | #define LIBBSD_WCHAR_H_SKIP
30 | #endif
31 |
32 | #ifdef LIBBSD_OVERLAY
33 | #include_next
34 | #else
35 | #include
36 | #endif
37 |
38 | #ifndef LIBBSD_WCHAR_H_SKIP
39 | #ifndef LIBBSD_WCHAR_H
40 | #define LIBBSD_WCHAR_H
41 |
42 | #include
43 | #ifdef LIBBSD_OVERLAY
44 | #include
45 | #else
46 | #include
47 | #endif
48 | #include
49 |
50 | __BEGIN_DECLS
51 | wchar_t *fgetwln(FILE *stream, size_t *len);
52 |
53 | #if !defined(__APPLE__)
54 | size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
55 | size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
56 | #endif
57 | __END_DECLS
58 |
59 | #endif
60 | #endif
61 | #undef LIBBSD_WCHAR_H_SKIP
62 |
--------------------------------------------------------------------------------
/m4/.gitignore:
--------------------------------------------------------------------------------
1 | *.m4
2 | !libbsd*.m4
3 |
--------------------------------------------------------------------------------
/m4/libbsd-funcs.m4:
--------------------------------------------------------------------------------
1 | # Copyright © 2011-2024 Guillem Jover
2 |
3 | # LIBBSD_CHECK_PROGNAME
4 | # ---------------------
5 | AC_DEFUN([LIBBSD_CHECK_PROGNAME], [
6 | AC_MSG_CHECKING([for program_invocation_short_name])
7 | AC_LINK_IFELSE([
8 | AC_LANG_PROGRAM([[
9 | #include
10 | ]], [[
11 | const char *p = program_invocation_short_name;
12 | ]])
13 | ], [
14 | AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
15 | [Define to 1 if you have program_invocation_short_name])
16 | AC_MSG_RESULT([yes])
17 | ], [
18 | AC_MSG_RESULT([no])
19 | ])
20 |
21 | AC_MSG_CHECKING([for __progname])
22 | AC_LINK_IFELSE([
23 | AC_LANG_PROGRAM([[
24 | #include
25 | extern char *__progname;
26 | ]], [[
27 | printf("%s", __progname);
28 | ]])
29 | ], [
30 | AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
31 | AC_MSG_RESULT([yes])
32 | ], [
33 | AC_MSG_RESULT([no])
34 | ])
35 | ])
36 |
37 | # LIBBSD_CHECK_REGISTER_ATFORK
38 | # ----------------------------
39 | AC_DEFUN([LIBBSD_CHECK_REGISTER_ATFORK], [
40 | AC_MSG_CHECKING([for __register_atfork])
41 | AC_LINK_IFELSE([
42 | AC_LANG_PROGRAM([[
43 | #include
44 | extern void *__dso_handle;
45 | extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
46 | ]], [[
47 | __register_atfork(NULL, NULL, NULL, __dso_handle);
48 | ]])
49 | ], [
50 | AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
51 | [Define to 1 if you have __register_atfork])
52 | AC_MSG_RESULT([yes])
53 | ], [
54 | LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
55 | AC_MSG_RESULT([no])
56 | ])
57 | ])
58 |
--------------------------------------------------------------------------------
/m4/libbsd-large.m4:
--------------------------------------------------------------------------------
1 | # Copyright © 2024 Guillem Jover
2 |
3 | # LIBBSD_SYS_TIME64
4 | # -----------------
5 | # Check for availability of time64 support.
6 | AC_DEFUN([LIBBSD_SYS_TIME64], [
7 | # Check the default time_t size.
8 | AC_CHECK_SIZEOF([time_t], [], [[
9 | #undef _TIME_BITS
10 | #include
11 | ]])
12 | AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
13 | libbsd_sys_time_bits=64
14 | ], [
15 | libbsd_sys_time_bits=32
16 | ])
17 | AC_DEFINE_UNQUOTED([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits],
18 | [The number of bits for the default system time_t ABI])
19 | AC_SUBST([LIBBSD_SYS_TIME_BITS], [$libbsd_sys_time_bits])
20 | AS_UNSET([ac_cv_sizeof_time_t])
21 | AM_CONDITIONAL([LIBBSD_SYS_IS_TIME32], [test "$libbsd_sys_time_bits" -eq 32])
22 |
23 | # Check the whether the system supports 64-bit time_t.
24 | AC_CHECK_SIZEOF([time_t], [], [[
25 | #define _FILE_OFFSET_BITS 64
26 | #define _TIME_BITS 64
27 | #include
28 | ]])
29 | AS_IF([test $ac_cv_sizeof_time_t -eq 8], [
30 | libbsd_sys_has_time64=1
31 | ], [
32 | libbsd_sys_has_time64=0
33 | ])
34 | AC_DEFINE_UNQUOTED([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64],
35 | [Enable if the system supports 64-bit time_t])
36 | AC_SUBST([LIBBSD_SYS_HAS_TIME64], [$libbsd_sys_has_time64])
37 | AM_CONDITIONAL([LIBBSD_SYS_HAS_TIME64], [test "$libbsd_sys_has_time64" -eq 1])
38 | AS_IF([test "$libbsd_sys_time_bits" -eq 32 && \
39 | test "$libbsd_sys_has_time64" -eq 1], [
40 | abi_time64=yes
41 | ], [
42 | abi_time64=no
43 | ])
44 | LIBBSD_SELECT_ABI([time64], [explicit time64 time_t support])
45 |
46 | AC_CHECK_SIZEOF([off_t], [], [[
47 | #define _FILE_OFFSET_BITS 64
48 | #include
49 | ]])
50 | AS_IF([test $ac_cv_sizeof_off_t = 8], [
51 | libbsd_sys_has_lfs=1
52 | ], [
53 | libbsd_sys_has_lfs=0
54 | ])
55 |
56 | AS_IF([test $libbsd_sys_has_lfs -eq 1 && \
57 | test $libbsd_sys_time_bits -eq 32 && \
58 | test $ac_cv_sizeof_time_t -eq 8], [
59 | AC_DEFINE([_TIME_BITS], [64], [Enable 64-bit time_t support])
60 | ])
61 | ])
62 |
--------------------------------------------------------------------------------
/m4/libbsd-linker.m4:
--------------------------------------------------------------------------------
1 | # Copyright © 2019, 2022 Guillem Jover
2 |
3 | # LIBBSD_LINKER_VERSION_SCRIPT
4 | # ----------------------------
5 | AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
6 | AC_CACHE_CHECK([if ld supports --version-script flag],
7 | [libbsd_cv_version_script], [
8 | echo "{ global: symbol; local: *; };" >conftest.map
9 | save_LDFLAGS=$LDFLAGS
10 | LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
11 | AC_LINK_IFELSE([
12 | AC_LANG_PROGRAM([[
13 | extern int symbol(void);
14 | int symbol(void) { return 0; }
15 | ]], [[
16 | ]])
17 | ], [
18 | libbsd_cv_version_script=yes
19 | ], [
20 | libbsd_cv_version_script=no
21 | ])
22 | LDFLAGS="$save_LDFLAGS"
23 | rm -f conftest.map
24 | ])
25 | AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
26 | [test "x$libbsd_cv_version_script" = "xyes"])
27 | ])
28 |
--------------------------------------------------------------------------------
/man/.gitignore:
--------------------------------------------------------------------------------
1 | md5.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_CLASS_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_CLASS_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_FIRST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_FOREACH_FROM.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_FOREACH_FROM_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_FOREACH_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_HEAD_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_INSERT_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_INSERT_BEFORE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_INSERT_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_PREV.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/LIST_SWAP.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_FIND.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_FOREACH_REVERSE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_GENERATE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_GENERATE_STATIC.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_INSERT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_LEFT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_MAX.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_MIN.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_NFIND.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_PARENT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_PREV.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_PROTOTYPE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_PROTOTYPE_STATIC.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_RIGHT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/RB_ROOT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_CLASS_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_CLASS_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_FIRST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_FOREACH_FROM.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_FOREACH_FROM_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_FOREACH_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_HEAD_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_INSERT_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_INSERT_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_REMOVE_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_REMOVE_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_REMOVE_PREVPTR.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SLIST_SWAP.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_FIND.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_GENERATE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_INSERT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_LEFT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_MAX.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_MIN.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_PROTOTYPE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_RIGHT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/SPLAY_ROOT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/tree.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_CLASS_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_CLASS_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_CONCAT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_FIRST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_FOREACH_FROM.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_FOREACH_FROM_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_FOREACH_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_HEAD_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_INSERT_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_INSERT_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_INSERT_TAIL.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_LAST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_REMOVE_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_REMOVE_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/STAILQ_SWAP.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_CLASS_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_CLASS_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_CONCAT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_EMPTY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_ENTRY.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FIRST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_FROM.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_FROM_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_REVERSE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_REVERSE_FROM.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_REVERSE_FROM_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_REVERSE_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_FOREACH_SAFE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_HEAD_INITIALIZER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_INIT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_INSERT_AFTER.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_INSERT_BEFORE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_INSERT_HEAD.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_INSERT_TAIL.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_LAST.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_NEXT.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_PREV.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_REMOVE.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TAILQ_SWAP.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/queue.3bsd
2 |
--------------------------------------------------------------------------------
/man/TIMEVAL_TO_TIMESPEC.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/TIMESPEC_TO_TIMEVAL.3bsd
2 |
--------------------------------------------------------------------------------
/man/arc4random_addrandom.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/arc4random.3bsd
2 |
--------------------------------------------------------------------------------
/man/arc4random_buf.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/arc4random.3bsd
2 |
--------------------------------------------------------------------------------
/man/arc4random_stir.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/arc4random.3bsd
2 |
--------------------------------------------------------------------------------
/man/arc4random_uniform.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/arc4random.3bsd
2 |
--------------------------------------------------------------------------------
/man/be16dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/be16enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/be32dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/be32enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/be64dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/be64enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_alloc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_clear.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_decl.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_ffc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_ffs.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_nclear.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_nset.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_set.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bit_test.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/bitstr_size.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/bitstring.3bsd
2 |
--------------------------------------------------------------------------------
/man/byteorder.3bsd:
--------------------------------------------------------------------------------
1 | .\" Copyright (c) 2002 Mike Barcroft
2 | .\" All rights reserved.
3 | .\"
4 | .\" Redistribution and use in source and binary forms, with or without
5 | .\" modification, are permitted provided that the following conditions
6 | .\" are met:
7 | .\" 1. Redistributions of source code must retain the above copyright
8 | .\" notice, this list of conditions and the following disclaimer.
9 | .\" 2. Redistributions in binary form must reproduce the above copyright
10 | .\" notice, this list of conditions and the following disclaimer in the
11 | .\" documentation and/or other materials provided with the distribution.
12 | .\"
13 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 | .\" SUCH DAMAGE.
24 | .\"
25 | .\" $FreeBSD$
26 | .\"
27 | .Dd April 29, 2002
28 | .Dt byteorder 3bsd
29 | .Os
30 | .Sh NAME
31 | .Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
32 | .Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec
33 | .Nd byte order operations
34 | .Sh LIBRARY
35 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
36 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
37 | .Lb libbsd
38 | .Sh SYNOPSIS
39 | .In sys/endian.h
40 | (See
41 | .Xr libbsd 7
42 | for include usage.)
43 | .Ft uint16_t
44 | .Fn be16dec "const void *"
45 | .Ft uint32_t
46 | .Fn be32dec "const void *"
47 | .Ft uint64_t
48 | .Fn be64dec "const void *"
49 | .Ft uint16_t
50 | .Fn le16dec "const void *"
51 | .Ft uint32_t
52 | .Fn le32dec "const void *"
53 | .Ft uint64_t
54 | .Fn le64dec "const void *"
55 | .Ft void
56 | .Fn be16enc "void *" uint16_t
57 | .Ft void
58 | .Fn be32enc "void *" uint32_t
59 | .Ft void
60 | .Fn be64enc "void *" uint64_t
61 | .Ft void
62 | .Fn le16enc "void *" uint16_t
63 | .Ft void
64 | .Fn le32enc "void *" uint32_t
65 | .Ft void
66 | .Fn le64enc "void *" uint64_t
67 | .Sh DESCRIPTION
68 | .Pp
69 | The
70 | .Fn be16enc ,
71 | .Fn be16dec ,
72 | .Fn be32enc ,
73 | .Fn be32dec ,
74 | .Fn be64enc ,
75 | .Fn be64dec ,
76 | .Fn le16enc ,
77 | .Fn le16dec ,
78 | .Fn le32enc ,
79 | .Fn le32dec ,
80 | .Fn le64enc ,
81 | and
82 | .Fn le64dec
83 | functions encode and decode integers to/from byte strings on any alignment
84 | in big/little endian format.
85 | .Sh SEE ALSO
86 | .Xr byteorder 3
87 | .Sh HISTORY
88 | .Pp
89 | The encode/decode functions first appeared in
90 | .Fx 5.1 .
91 |
--------------------------------------------------------------------------------
/man/closefrom.3bsd:
--------------------------------------------------------------------------------
1 | .\" Copyright (c) 2009 Advanced Computing Technologies LLC
2 | .\" Written by: John H. Baldwin
3 | .\" All rights reserved.
4 | .\"
5 | .\" Redistribution and use in source and binary forms, with or without
6 | .\" modification, are permitted provided that the following conditions
7 | .\" are met:
8 | .\" 1. Redistributions of source code must retain the above copyright
9 | .\" notice, this list of conditions and the following disclaimer.
10 | .\" 2. Redistributions in binary form must reproduce the above copyright
11 | .\" notice, this list of conditions and the following disclaimer in the
12 | .\" documentation and/or other materials provided with the distribution.
13 | .\"
14 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 | .\" SUCH DAMAGE.
25 | .\"
26 | .\" $FreeBSD$
27 | .\"
28 | .Dd June 12, 2009
29 | .Dt closefrom 3bsd
30 | .Os
31 | .Sh NAME
32 | .Nm closefrom
33 | .Nd delete open file descriptors
34 | .Sh LIBRARY
35 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
36 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
37 | .Lb libbsd
38 | .Sh SYNOPSIS
39 | .In unistd.h
40 | (See
41 | .Xr libbsd 7
42 | for include usage.)
43 | .Ft void
44 | .Fn closefrom "int lowfd"
45 | .Sh DESCRIPTION
46 | The
47 | .Fn closefrom
48 | system call deletes all open file descriptors greater than or equal to
49 | .Fa lowfd
50 | from the per-process object reference table.
51 | Any errors encountered while closing file descriptors are ignored.
52 | .Sh SEE ALSO
53 | .Xr close 2
54 | .Sh STANDARDS
55 | .Fn closefrom
56 | is a
57 | .Bx
58 | and Solaris extension.
59 | .Sh HISTORY
60 | The
61 | .Fn closefrom
62 | function first appeared in Solaris 9,
63 | .Ox 3.5 ,
64 | .Dx 1.2 ,
65 | .Nx 3.0 ,
66 | .Fx 8.0
67 | and glibc 2.34.
68 |
--------------------------------------------------------------------------------
/man/dehumanize_number.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/humanize_number.3bsd
2 |
--------------------------------------------------------------------------------
/man/explicit_bzero.3bsd:
--------------------------------------------------------------------------------
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 | .\" All rights reserved.
3 | .\"
4 | .\" This code is derived from software contributed to Berkeley by
5 | .\" Chris Torek.
6 | .\" Redistribution and use in source and binary forms, with or without
7 | .\" modification, are permitted provided that the following conditions
8 | .\" are met:
9 | .\" 1. Redistributions of source code must retain the above copyright
10 | .\" notice, this list of conditions and the following disclaimer.
11 | .\" 2. Redistributions in binary form must reproduce the above copyright
12 | .\" notice, this list of conditions and the following disclaimer in the
13 | .\" documentation and/or other materials provided with the distribution.
14 | .\" 3. Neither the name of the University nor the names of its contributors
15 | .\" may be used to endorse or promote products derived from this software
16 | .\" without specific prior written permission.
17 | .\"
18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 | .\" SUCH DAMAGE.
29 | .\"
30 | .\" $OpenBSD: bzero.3,v 1.10 2014/01/22 21:06:45 tedu Exp $
31 | .\"
32 | .Dd $Mdocdate: January 22 2014 $
33 | .Dt explicit_bzero 3bsd
34 | .Os
35 | .Sh NAME
36 | .Nm explicit_bzero
37 | .Nd write zeroes to a byte string
38 | .Sh LIBRARY
39 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
40 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
41 | .Lb libbsd
42 | .Sh SYNOPSIS
43 | .In string.h
44 | (See
45 | .Xr libbsd 7
46 | for include usage.)
47 | .Ft void
48 | .Fn explicit_bzero "void *buf" "size_t len"
49 | .Sh DESCRIPTION
50 | The
51 | .Fn explicit_bzero
52 | function writes
53 | .Fa len
54 | zero bytes to the string
55 | .Fa buf .
56 | If
57 | .Fa len
58 | is zero,
59 | .Fn explicit_bzero
60 | does nothing.
61 | .Pp
62 | The
63 | .Fn explicit_bzero
64 | variant behaves the same as the
65 | .Fn bzero
66 | function, but will not be removed by a compiler's dead store optimization
67 | pass, making it useful for clearing sensitive memory such as a password.
68 | .Sh SEE ALSO
69 | .Xr bzero 3 ,
70 | .Xr memset 3 ,
71 | .Xr swab 3
72 | .Sh HISTORY
73 | The
74 | .Fn explicit_bzero
75 | function first appeared in
76 | .Ox 5.5 ,
77 | glibc 2.25.
78 |
--------------------------------------------------------------------------------
/man/fpurge.3bsd:
--------------------------------------------------------------------------------
1 | .\" $OpenBSD: fflush.3,v 1.12 2015/11/04 21:30:13 tedu Exp $
2 | .\"
3 | .\" Copyright (c) 1990, 1991, 1993
4 | .\" The Regents of the University of California. All rights reserved.
5 | .\"
6 | .\" This code is derived from software contributed to Berkeley by
7 | .\" Chris Torek and the American National Standards Committee X3,
8 | .\" on Information Processing Systems.
9 | .\"
10 | .\" Redistribution and use in source and binary forms, with or without
11 | .\" modification, are permitted provided that the following conditions
12 | .\" are met:
13 | .\" 1. Redistributions of source code must retain the above copyright
14 | .\" notice, this list of conditions and the following disclaimer.
15 | .\" 2. Redistributions in binary form must reproduce the above copyright
16 | .\" notice, this list of conditions and the following disclaimer in the
17 | .\" documentation and/or other materials provided with the distribution.
18 | .\" 3. Neither the name of the University nor the names of its contributors
19 | .\" may be used to endorse or promote products derived from this software
20 | .\" without specific prior written permission.
21 | .\"
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | .\" SUCH DAMAGE.
33 | .\"
34 | .Dd $Mdocdate: November 4 2015 $
35 | .Dt fpurge 3bsd
36 | .Os
37 | .Sh NAME
38 | .Nm fpurge
39 | .Nd flush a stream
40 | .Sh LIBRARY
41 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
42 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
43 | .Lb libbsd
44 | .Sh SYNOPSIS
45 | .In stdio.h
46 | (See
47 | .Xr libbsd 7
48 | for include usage.)
49 | .Ft int
50 | .Fn fpurge "FILE *stream"
51 | .Sh DESCRIPTION
52 | The function
53 | .Fn fpurge
54 | erases any input or output buffered in the given
55 | .Fa stream .
56 | For output streams this discards any unwritten output.
57 | For input streams this discards any input read from the underlying object
58 | but not yet obtained via
59 | .Xr getc 3 ;
60 | this includes any text pushed back via
61 | .Xr ungetc 3 .
62 | .Sh RETURN VALUES
63 | Upon successful completion 0 is returned.
64 | Otherwise,
65 | .Dv EOF
66 | is returned and the global variable
67 | .Va errno
68 | is set to indicate the error.
69 | .Sh ERRORS
70 | .Bl -tag -width Er
71 | .It Bq Er EBADF
72 | .Fa stream
73 | is not an open stream.
74 | .El
75 | .Sh SEE ALSO
76 | .Xr fclose 3 ,
77 | .Xr fopen 3 ,
78 | .Xr setvbuf 3
79 | .Sh HISTORY
80 | The
81 | .Fn fpurge
82 | function first appeared in
83 | .Bx 4.4 Lite .
84 |
--------------------------------------------------------------------------------
/man/freezero.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/reallocarray.3bsd
2 |
--------------------------------------------------------------------------------
/man/getmode.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/setmode.3bsd
2 |
--------------------------------------------------------------------------------
/man/getprogname.3bsd:
--------------------------------------------------------------------------------
1 | .\" Copyright (c) 2022 Guillem Jover
2 | .\"
3 | .\" Redistribution and use in source and binary forms, with or without
4 | .\" modification, are permitted provided that the following conditions
5 | .\" are met:
6 | .\" 1. Redistributions of source code must retain the above copyright
7 | .\" notice, this list of conditions and the following disclaimer.
8 | .\" 2. Redistributions in binary form must reproduce the above copyright
9 | .\" notice, this list of conditions and the following disclaimer in the
10 | .\" documentation and/or other materials provided with the distribution.
11 | .\" 3. The name of the author may not be used to endorse or promote products
12 | .\" derived from this software without specific prior written permission.
13 | .\" .
14 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
16 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
17 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | .\"
25 | .Dd August 03, 2022
26 | .Dt getprogname 3bsd
27 | .Os
28 | .Sh NAME
29 | .Nm getprogname ,
30 | .Nm setprogname
31 | .Nd get and set program name
32 | .Sh LIBRARY
33 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
34 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
35 | .Lb libbsd
36 | .Sh SYNOPSIS
37 | .In stdlib.h
38 | (See
39 | .Xr libbsd 7
40 | for include usage.)
41 | .Ft const char *
42 | .Fn getprogname "void"
43 | .Ft void
44 | .Fn setprogname "const char *progname"
45 | .Sh DESCRIPTION
46 | The
47 | .Fn getprogname
48 | returns a string with the current program name,
49 | excluding any directory component.
50 | The function will return
51 | .Dv NULL
52 | if it was unable to get the program name from any known source.
53 | .Pp
54 | The
55 | .Fn setprogname
56 | function sets the current program name,
57 | stripping any directory component prefix.
58 | The function will keep a reference to the passed string pointer,
59 | so it must not be freed or modified while these functions might
60 | be called.
61 | .Pp
62 | The implementations on most BSDs will try to initialize the program name
63 | at program startup time, and
64 | .Nm libbsd
65 | will try to infer it from various known sources depending on the
66 | target system.
67 | But it is not a portable assumption that the program name will be set
68 | without calling
69 | .Fn setprogname ,
70 | so portable programs should always call it after starting up.
71 | .Sh SEE ALSO
72 | .Xr setproctitle 3bsd .
73 | .Sh HISTORY
74 | The
75 | .Fn setprogname
76 | and
77 | .Fn getprogname
78 | functions first appeared in
79 | .Nx 1.6 ,
80 | .Fx 4.4 ,
81 | .Dx 2.1
82 | and
83 | .Ox 5.4 .
84 |
--------------------------------------------------------------------------------
/man/gid_from_group.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pwcache.3bsd
2 |
--------------------------------------------------------------------------------
/man/group_from_gid.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pwcache.3bsd
2 |
--------------------------------------------------------------------------------
/man/le16dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/le16enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/le32dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/le32enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/le64dec.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/le64enc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/byteorder.3bsd
2 |
--------------------------------------------------------------------------------
/man/mergesort.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/heapsort.3bsd
2 |
--------------------------------------------------------------------------------
/man/nlist.3bsd:
--------------------------------------------------------------------------------
1 | .\" Copyright (c) 1980, 1991, 1993
2 | .\" The Regents of the University of California. All rights reserved.
3 | .\"
4 | .\" Redistribution and use in source and binary forms, with or without
5 | .\" modification, are permitted provided that the following conditions
6 | .\" are met:
7 | .\" 1. Redistributions of source code must retain the above copyright
8 | .\" notice, this list of conditions and the following disclaimer.
9 | .\" 2. Redistributions in binary form must reproduce the above copyright
10 | .\" notice, this list of conditions and the following disclaimer in the
11 | .\" documentation and/or other materials provided with the distribution.
12 | .\" 4. Neither the name of the University nor the names of its contributors
13 | .\" may be used to endorse or promote products derived from this software
14 | .\" without specific prior written permission.
15 | .\"
16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 | .\" SUCH DAMAGE.
27 | .\"
28 | .\" @(#)nlist.3 8.3 (Berkeley) 4/19/94
29 | .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
30 | .\"
31 | .Dd April 19, 1994
32 | .Dt nlist 3bsd
33 | .Os
34 | .Sh NAME
35 | .Nm nlist
36 | .Nd retrieve symbol table name list from an executable file
37 | .Sh LIBRARY
38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
39 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
40 | .Lb libbsd
41 | .Sh SYNOPSIS
42 | .In nlist.h
43 | (See
44 | .Xr libbsd 7
45 | for include usage.)
46 | .Ft int
47 | .Fn nlist "const char *filename" "struct nlist *nl"
48 | .Sh DESCRIPTION
49 | The
50 | .Fn nlist
51 | function
52 | retrieves name list entries from the symbol table of an
53 | executable file (see
54 | .Xr elf 5 ) .
55 | The argument
56 | .Fa \&nl
57 | is set to reference the
58 | beginning of the list.
59 | The list is preened of binary and invalid data;
60 | if an entry in the
61 | name list is valid, the
62 | .Fa n_type
63 | and
64 | .Fa n_value
65 | for the entry are copied into the list
66 | referenced by
67 | .Fa \&nl .
68 | No other data is copied.
69 | The last entry in the list is always
70 | .Dv NULL .
71 | .Sh RETURN VALUES
72 | The number of invalid entries is returned if successful; otherwise,
73 | if the file
74 | .Fa filename
75 | does not exist or is not executable,
76 | or the nl pointer is
77 | .Dv NULL ,
78 | the returned value is \-1.
79 | .Sh SEE ALSO
80 | .Xr elf 5
81 | .Sh HISTORY
82 | A
83 | .Fn nlist
84 | function appeared in
85 | .At v6 .
86 |
--------------------------------------------------------------------------------
/man/pidfile_close.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pidfile.3bsd
2 |
--------------------------------------------------------------------------------
/man/pidfile_open.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pidfile.3bsd
2 |
--------------------------------------------------------------------------------
/man/pidfile_remove.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pidfile.3bsd
2 |
--------------------------------------------------------------------------------
/man/pidfile_write.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pidfile.3bsd
2 |
--------------------------------------------------------------------------------
/man/recallocarray.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/reallocarray.3bsd
2 |
--------------------------------------------------------------------------------
/man/setproctitle_init.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/setproctitle.3bsd
2 |
--------------------------------------------------------------------------------
/man/setprogname.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/getprogname.3bsd
2 |
--------------------------------------------------------------------------------
/man/sl_add.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/stringlist.3bsd
2 |
--------------------------------------------------------------------------------
/man/sl_delete.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/stringlist.3bsd
2 |
--------------------------------------------------------------------------------
/man/sl_find.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/stringlist.3bsd
2 |
--------------------------------------------------------------------------------
/man/sl_free.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/stringlist.3bsd
2 |
--------------------------------------------------------------------------------
/man/sl_init.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/stringlist.3bsd
2 |
--------------------------------------------------------------------------------
/man/sradixsort.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/radixsort.3bsd
2 |
--------------------------------------------------------------------------------
/man/strlcat.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/strlcpy.3bsd
2 |
--------------------------------------------------------------------------------
/man/strnunvis.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/unvis.3bsd
2 |
--------------------------------------------------------------------------------
/man/strnvis.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/vis.3bsd
2 |
--------------------------------------------------------------------------------
/man/strunvis.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/unvis.3bsd
2 |
--------------------------------------------------------------------------------
/man/strvis.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/vis.3bsd
2 |
--------------------------------------------------------------------------------
/man/strvisx.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/vis.3bsd
2 |
--------------------------------------------------------------------------------
/man/timerclear.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timercmp.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timerisset.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timersub.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timespecadd.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timespecclear.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timespeccmp.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timespecisset.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/timespecsub.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/timeradd.3bsd
2 |
--------------------------------------------------------------------------------
/man/uid_from_user.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pwcache.3bsd
2 |
--------------------------------------------------------------------------------
/man/user_from_uid.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/pwcache.3bsd
2 |
--------------------------------------------------------------------------------
/man/verrc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/errc.3bsd
2 |
--------------------------------------------------------------------------------
/man/vwarnc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/errc.3bsd
2 |
--------------------------------------------------------------------------------
/man/warnc.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/errc.3bsd
2 |
--------------------------------------------------------------------------------
/man/wcslcat.3bsd:
--------------------------------------------------------------------------------
1 | .so man3/wcslcpy.3bsd
2 |
--------------------------------------------------------------------------------
/man/wcslcpy.3bsd:
--------------------------------------------------------------------------------
1 | .\" $NetBSD: wmemchr.3,v 1.4 2001/01/02 11:26:23 itojun Exp $
2 | .\"
3 | .\" Copyright (c) 1990, 1991, 1993
4 | .\" The Regents of the University of California. All rights reserved.
5 | .\"
6 | .\" This code is derived from software contributed to Berkeley by
7 | .\" Chris Torek and the American National Standards Committee X3,
8 | .\" on Information Processing Systems.
9 | .\"
10 | .\" Redistribution and use in source and binary forms, with or without
11 | .\" modification, are permitted provided that the following conditions
12 | .\" are met:
13 | .\" 1. Redistributions of source code must retain the above copyright
14 | .\" notice, this list of conditions and the following disclaimer.
15 | .\" 2. Redistributions in binary form must reproduce the above copyright
16 | .\" notice, this list of conditions and the following disclaimer in the
17 | .\" documentation and/or other materials provided with the distribution.
18 | .\" 3. Neither the name of the University nor the names of its contributors
19 | .\" may be used to endorse or promote products derived from this software
20 | .\" without specific prior written permission.
21 | .\"
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | .\" SUCH DAMAGE.
33 | .\"
34 | .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93
35 | .\"
36 | .\" $FreeBSD$
37 | .\"
38 | .Dd March 4, 2009
39 | .Dt wcslcpy 3bsd
40 | .Os
41 | .Sh NAME
42 | .Nm wcslcat ,
43 | .Nm wcslcpy ,
44 | .Nd wide character string manipulation operations
45 | .Sh LIBRARY
46 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
47 | .ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
48 | .Lb libbsd
49 | .Sh SYNOPSIS
50 | .In wchar.h
51 | (See
52 | .Xr libbsd 7
53 | for include usage.)
54 | .Ft size_t
55 | .Fn wcslcat "wchar_t *s1" "const wchar_t *s2" "size_t n"
56 | .Ft size_t
57 | .Fn wcslcpy "wchar_t *s1" "const wchar_t *s2" "size_t n"
58 | .Sh DESCRIPTION
59 | The functions implement string manipulation operations over wide character
60 | strings.
61 | For a detailed description, refer to documents for the respective single-byte
62 | counterpart, such as
63 | .Xr strlcpy 3bsd .
64 | .Sh SEE ALSO
65 | .Xr strlcat 3bsd ,
66 | .Xr strlcpy 3bsd .
67 | .Sh STANDARDS
68 | .Fn wcslcat
69 | and
70 | .Fn wcslcpy ,
71 | which are BSD extensions.
72 | .Sh HISTORY
73 | The
74 | .Fn wcslcpy
75 | and
76 | .Fn wcslcat
77 | functions first appeared in
78 | .Ox 3.8 ,
79 | .Nx 1.6 ,
80 | .Fx 5.0
81 | and
82 | .Dx 2.1 .
83 |
--------------------------------------------------------------------------------
/src/arc4random.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef LIBBSD_ARC4RANDOM_H
28 | #define LIBBSD_ARC4RANDOM_H
29 |
30 | #include
31 |
32 | int
33 | getentropy(void *buf, size_t len);
34 |
35 | #if defined(__linux__)
36 | #include "arc4random_linux.h"
37 | #elif defined(_WIN32)
38 | #include "arc4random_win.h"
39 | #else
40 | #include "arc4random_unix.h"
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/arc4random_linux.h:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: arc4random_linux.h,v 1.11 2016/06/30 12:19:51 bcook Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1996, David Mazieres
5 | * Copyright (c) 2008, Damien Miller
6 | * Copyright (c) 2013, Markus Friedl
7 | * Copyright (c) 2014, Theo de Raadt
8 | *
9 | * Permission to use, copy, modify, and distribute this software for any
10 | * purpose with or without fee is hereby granted, provided that the above
11 | * copyright notice and this permission notice appear in all copies.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 | */
21 |
22 | /*
23 | * Stub functions for portability.
24 | */
25 |
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
32 | #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
33 | #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
34 |
35 | #ifdef HAVE___REGISTER_ATFORK
36 | extern void *__dso_handle;
37 | extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
38 | #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
39 | #else
40 | #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
41 | #endif
42 |
43 | static inline void
44 | _getentropy_fail(void)
45 | {
46 | raise(SIGKILL);
47 | }
48 |
49 | static volatile sig_atomic_t _rs_forked;
50 |
51 | static inline void
52 | _rs_forkhandler(void)
53 | {
54 | _rs_forked = 1;
55 | }
56 |
57 | static inline void
58 | _rs_forkdetect(void)
59 | {
60 | static pid_t _rs_pid = 0;
61 | pid_t pid = getpid();
62 |
63 | /* XXX unusual calls to clone() can bypass checks */
64 | if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) {
65 | _rs_pid = pid;
66 | _rs_forked = 0;
67 | if (rs)
68 | memset(rs, 0, sizeof(*rs));
69 | }
70 | }
71 |
72 | static inline int
73 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
74 | {
75 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
76 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
77 | return (-1);
78 |
79 | if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
80 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
81 | munmap(*rsp, sizeof(**rsp));
82 | *rsp = NULL;
83 | return (-1);
84 | }
85 |
86 | _ARC4_ATFORK(_rs_forkhandler);
87 | return (0);
88 | }
89 |
--------------------------------------------------------------------------------
/src/arc4random_uniform.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: arc4random_uniform.c,v 1.1 2014/07/12 13:24:54 deraadt Exp $ */
2 |
3 | /*
4 | * Copyright (c) 2008, Damien Miller
5 | *
6 | * Permission to use, copy, modify, and distribute this software for any
7 | * purpose with or without fee is hereby granted, provided that the above
8 | * copyright notice and this permission notice appear in all copies.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 | */
18 |
19 | #include
20 | #include
21 |
22 | /*
23 | * Calculate a uniformly distributed random number less than upper_bound
24 | * avoiding "modulo bias".
25 | *
26 | * Uniformity is achieved by generating new random numbers until the one
27 | * returned is outside the range [0, 2**32 % upper_bound). This
28 | * guarantees the selected random number will be inside
29 | * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
30 | * after reduction modulo upper_bound.
31 | */
32 | uint32_t
33 | arc4random_uniform(uint32_t upper_bound)
34 | {
35 | uint32_t r, min;
36 |
37 | if (upper_bound < 2)
38 | return 0;
39 |
40 | /* 2**32 % x == (2**32 - x) % x */
41 | min = -upper_bound % upper_bound;
42 |
43 | /*
44 | * This could theoretically loop forever but each retry has
45 | * p > 0.5 (worst case, usually far better) of selecting a
46 | * number inside the range we need, so it should rarely need
47 | * to re-roll.
48 | */
49 | for (;;) {
50 | r = arc4random();
51 | if (r >= min)
52 | break;
53 | }
54 |
55 | return r % upper_bound;
56 | }
57 | //DEF_WEAK(arc4random_uniform);
58 |
--------------------------------------------------------------------------------
/src/arc4random_unix.h:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: arc4random_freebsd.h,v 1.4 2016/06/30 12:19:51 bcook Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1996, David Mazieres
5 | * Copyright (c) 2008, Damien Miller
6 | * Copyright (c) 2013, Markus Friedl
7 | * Copyright (c) 2014, Theo de Raadt
8 | *
9 | * Permission to use, copy, modify, and distribute this software for any
10 | * purpose with or without fee is hereby granted, provided that the above
11 | * copyright notice and this permission notice appear in all copies.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 | */
21 |
22 | /*
23 | * Stub functions for portability.
24 | */
25 |
26 | #include
27 |
28 | #include
29 | #include
30 |
31 | static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
32 | #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
33 | #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
34 |
35 | #ifdef HAVE___REGISTER_ATFORK
36 | extern void *__dso_handle;
37 | extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
38 | #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
39 | #else
40 | /*
41 | * Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10) if
42 | * a program does not link to -lthr. Callbacks registered with pthread_atfork()
43 | * appear to fail silently. So, it is not always possible to detect a PID
44 | * wraparound.
45 | */
46 | #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
47 | #endif
48 |
49 | static inline void
50 | _getentropy_fail(void)
51 | {
52 | raise(SIGKILL);
53 | }
54 |
55 | static volatile sig_atomic_t _rs_forked;
56 |
57 | static inline void
58 | _rs_forkhandler(void)
59 | {
60 | _rs_forked = 1;
61 | }
62 |
63 | static inline void
64 | _rs_forkdetect(void)
65 | {
66 | static pid_t _rs_pid = 0;
67 | pid_t pid = getpid();
68 |
69 | if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
70 | _rs_pid = pid;
71 | _rs_forked = 0;
72 | if (rs)
73 | memset(rs, 0, sizeof(*rs));
74 | }
75 | }
76 |
77 | static inline int
78 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
79 | {
80 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
81 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
82 | return (-1);
83 |
84 | if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
85 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
86 | munmap(*rsp, sizeof(**rsp));
87 | *rsp = NULL;
88 | return (-1);
89 | }
90 |
91 | _ARC4_ATFORK(_rs_forkhandler);
92 | return (0);
93 | }
94 |
--------------------------------------------------------------------------------
/src/arc4random_win.h:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: arc4random_win.h,v 1.6 2016/06/30 12:17:29 bcook Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1996, David Mazieres
5 | * Copyright (c) 2008, Damien Miller
6 | * Copyright (c) 2013, Markus Friedl
7 | * Copyright (c) 2014, Theo de Raadt
8 | *
9 | * Permission to use, copy, modify, and distribute this software for any
10 | * purpose with or without fee is hereby granted, provided that the above
11 | * copyright notice and this permission notice appear in all copies.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 | */
21 |
22 | /*
23 | * Stub functions for portability.
24 | */
25 |
26 | #include
27 |
28 | static volatile HANDLE arc4random_mtx = NULL;
29 |
30 | /*
31 | * Initialize the mutex on the first lock attempt. On collision, each thread
32 | * will attempt to allocate a mutex and compare-and-swap it into place as the
33 | * global mutex. On failure to swap in the global mutex, the mutex is closed.
34 | */
35 | #define _ARC4_LOCK() { \
36 | if (!arc4random_mtx) { \
37 | HANDLE p = CreateMutex(NULL, FALSE, NULL); \
38 | if (InterlockedCompareExchangePointer((void **)&arc4random_mtx, (void *)p, NULL)) \
39 | CloseHandle(p); \
40 | } \
41 | WaitForSingleObject(arc4random_mtx, INFINITE); \
42 | } \
43 |
44 | #define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
45 |
46 | static inline void
47 | _getentropy_fail(void)
48 | {
49 | TerminateProcess(GetCurrentProcess(), 0);
50 | }
51 |
52 | static inline int
53 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
54 | {
55 | *rsp = VirtualAlloc(NULL, sizeof(**rsp),
56 | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
57 | if (*rsp == NULL)
58 | return (-1);
59 |
60 | *rsxp = VirtualAlloc(NULL, sizeof(**rsxp),
61 | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
62 | if (*rsxp == NULL) {
63 | VirtualFree(*rsp, 0, MEM_RELEASE);
64 | *rsp = NULL;
65 | return (-1);
66 | }
67 | return (0);
68 | }
69 |
70 | static inline void
71 | _rs_forkhandler(void)
72 | {
73 | }
74 |
75 | static inline void
76 | _rs_forkdetect(void)
77 | {
78 | }
79 |
--------------------------------------------------------------------------------
/src/asprintf.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2010-2024 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | #include
30 | #include
31 |
32 | int
33 | asprintf(char **strp, char const *fmt, ...)
34 | {
35 | va_list args;
36 | int n;
37 |
38 | va_start(args, fmt);
39 | n = vasprintf(strp, fmt, args);
40 | va_end(args);
41 |
42 | return n;
43 | }
44 |
--------------------------------------------------------------------------------
/src/bsd_getopt.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2006 Robert Millan
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | int optreset = 0;
30 |
31 | int
32 | bsd_getopt(int argc, char * const argv[], const char *shortopts)
33 | {
34 | if (optreset == 1) {
35 | optreset = 0;
36 | optind = 0;
37 | }
38 |
39 | /*
40 | * Make sure we are using the system getopt() and not a possible
41 | * overlay macro.
42 | */
43 | return (getopt)(argc, argv, shortopts);
44 | }
45 |
--------------------------------------------------------------------------------
/src/dehumanize_number.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012-2013 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | int
36 | dehumanize_number(const char *buf, int64_t *num)
37 | {
38 | uint64_t rval, rmax;
39 | int sign = +1;
40 | int rc;
41 |
42 | /* The current expand_number() implementation uses bit shifts, so
43 | * we cannot pass negative numbers, preserve the sign and apply it
44 | * later. */
45 | while (isspace(*buf))
46 | buf++;
47 | if (*buf == '-') {
48 | sign = -1;
49 | buf++;
50 | }
51 |
52 | rc = expand_number(buf, &rval);
53 | if (rc < 0)
54 | return rc;
55 |
56 | /* The sign has been stripped, so rval has the absolute value.
57 | * Error out, regardless of the sign, if rval is greater than
58 | * abs(INT64_MIN) (== INT64_MAX + 1), or if the sign is positive
59 | * and the value has overflown by one (INT64_MAX + 1). */
60 | rmax = INT64_MAX + 1ULL;
61 | if (rval > rmax || (rval == rmax && sign == +1)) {
62 | errno = ERANGE;
63 | return -1;
64 | }
65 | *num = rval * sign;
66 |
67 | return 0;
68 | }
69 |
--------------------------------------------------------------------------------
/src/err.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2019 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | void
35 | vwarn(const char *format, va_list ap)
36 | {
37 | vwarnc(errno, format, ap);
38 | }
39 |
40 | void
41 | warn(const char *format, ...)
42 | {
43 | va_list ap;
44 |
45 | va_start(ap, format);
46 | vwarnc(errno, format, ap);
47 | va_end(ap);
48 | }
49 |
50 | void
51 | vwarnx(const char *format, va_list ap)
52 | {
53 | fprintf(stderr, "%s: ", getprogname());
54 | if (format)
55 | vfprintf(stderr, format, ap);
56 | fprintf(stderr, "\n");
57 | }
58 |
59 | void
60 | warnx(const char *format, ...)
61 | {
62 | va_list ap;
63 |
64 | va_start(ap, format);
65 | vwarnx(format, ap);
66 | va_end(ap);
67 | }
68 |
69 | void
70 | verr(int status, const char *format, va_list ap)
71 | {
72 | verrc(status, errno, format, ap);
73 | }
74 |
75 | void
76 | err(int status, const char *format, ...)
77 | {
78 | va_list ap;
79 |
80 | va_start(ap, format);
81 | verrc(status, errno, format, ap);
82 | va_end(ap);
83 | }
84 |
85 | void
86 | verrx(int eval, const char *format, va_list ap)
87 | {
88 | fprintf(stderr, "%s: ", getprogname());
89 | if (format)
90 | vfprintf(stderr, format, ap);
91 | fprintf(stderr, "\n");
92 | exit(eval);
93 | }
94 |
95 | void
96 | errx(int eval, const char *format, ...)
97 | {
98 | va_list ap;
99 |
100 | va_start(ap, format);
101 | verrx(eval, format, ap);
102 | va_end(ap);
103 | }
104 |
--------------------------------------------------------------------------------
/src/errc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2006 Robert Millan
3 | * Copyright © 2011, 2019 Guillem Jover
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | void
35 | vwarnc(int code, const char *format, va_list ap)
36 | {
37 | fprintf(stderr, "%s: ", getprogname());
38 | if (format) {
39 | vfprintf(stderr, format, ap);
40 | fprintf(stderr, ": ");
41 | }
42 | fprintf(stderr, "%s\n", strerror(code));
43 | }
44 |
45 | void
46 | warnc(int code, const char *format, ...)
47 | {
48 | va_list ap;
49 |
50 | va_start(ap, format);
51 | vwarnc(code, format, ap);
52 | va_end(ap);
53 | }
54 |
55 | void
56 | verrc(int status, int code, const char *format, va_list ap)
57 | {
58 | fprintf(stderr, "%s: ", getprogname());
59 | if (format) {
60 | vfprintf(stderr, format, ap);
61 | fprintf(stderr, ": ");
62 | }
63 | fprintf(stderr, "%s\n", strerror(code));
64 | exit(status);
65 | }
66 |
67 | void
68 | errc(int status, int code, const char *format, ...)
69 | {
70 | va_list ap;
71 |
72 | va_start(ap, format);
73 | verrc(status, code, format, ap);
74 | va_end(ap);
75 | }
76 |
--------------------------------------------------------------------------------
/src/explicit_bzero.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
2 | /*
3 | * Public domain.
4 | * Written by Matthew Dempsky.
5 | */
6 |
7 | #include
8 |
9 | __attribute__((__weak__)) void
10 | __explicit_bzero_hook(void *, size_t);
11 |
12 | __attribute__((__weak__)) void
13 | __explicit_bzero_hook(void *buf, size_t len)
14 | {
15 | }
16 |
17 | void
18 | explicit_bzero(void *buf, size_t len)
19 | {
20 | memset(buf, 0, len);
21 | __explicit_bzero_hook(buf, len);
22 | }
23 |
--------------------------------------------------------------------------------
/src/fgetln.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2005 Hector Garcia Alvarez
3 | * Copyright © 2005, 2008-2012 Guillem Jover
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #include
29 | #include
30 |
31 | #include
32 | #include
33 |
34 | #include "local-link.h"
35 |
36 | #ifdef HAVE_GETLINE
37 | struct filebuf {
38 | FILE *fp;
39 | char *buf;
40 | size_t len;
41 | };
42 |
43 | #define FILEBUF_POOL_ITEMS 32
44 |
45 | static struct filebuf fb_pool[FILEBUF_POOL_ITEMS];
46 | static int fb_pool_cur;
47 |
48 | char *
49 | fgetln(FILE *stream, size_t *len)
50 | {
51 | struct filebuf *fb;
52 | ssize_t nread;
53 |
54 | flockfile(stream);
55 |
56 | /* Try to diminish the possibility of several fgetln() calls being
57 | * used on different streams, by using a pool of buffers per file. */
58 | fb = &fb_pool[fb_pool_cur];
59 | if (fb->fp != stream && fb->fp != NULL) {
60 | fb_pool_cur++;
61 | fb_pool_cur %= FILEBUF_POOL_ITEMS;
62 | fb = &fb_pool[fb_pool_cur];
63 | }
64 | fb->fp = stream;
65 |
66 | nread = getline(&fb->buf, &fb->len, stream);
67 |
68 | funlockfile(stream);
69 |
70 | /* Note: the getdelim/getline API ensures nread != 0. */
71 | if (nread == -1) {
72 | *len = 0;
73 | return NULL;
74 | } else {
75 | *len = (size_t)nread;
76 | return fb->buf;
77 | }
78 | }
79 | libbsd_link_warning(fgetln,
80 | "The fgetln() function cannot be safely ported, use getline(3) "
81 | "instead, as it is supported by GNU and POSIX.1-2008.");
82 | #else
83 | #error "Function fgetln() needs to be ported."
84 | #endif
85 |
--------------------------------------------------------------------------------
/src/fpurge.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2011 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #if HAVE_STDIO_EXT_H
30 | #include
31 | #endif
32 |
33 | #ifdef HAVE___FPURGE
34 | int
35 | fpurge(FILE *fp)
36 | {
37 | if (fp == NULL) {
38 | errno = EBADF;
39 | return EOF;
40 | }
41 |
42 | __fpurge(fp);
43 |
44 | return 0;
45 | }
46 | #else
47 | #error "Function fpurge() needs to be ported."
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/freezero.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: malloc.c,v 1.267 2020/11/23 15:42:11 otto Exp $ */
2 | /*
3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek
4 | *
5 | * Permission to use, copy, modify, and distribute this software for any
6 | * purpose with or without fee is hereby granted, provided that the above
7 | * copyright notice and this permission notice appear in all copies.
8 | *
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 | */
17 |
18 | #include
19 | #include
20 |
21 | void
22 | freezero(void *ptr, size_t sz)
23 | {
24 | /* This is legal. */
25 | if (ptr == NULL)
26 | return;
27 |
28 | explicit_bzero(ptr, sz);
29 | free(ptr);
30 | }
31 |
--------------------------------------------------------------------------------
/src/getentropy.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #if defined(__linux__)
28 | #include "getentropy_linux.c"
29 | #elif defined(__GNU__)
30 | #include "getentropy_hurd.c"
31 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
32 | #include "getentropy_bsd.c"
33 | #elif defined(__NetBSD__)
34 | #include "getentropy_bsd.c"
35 | #elif defined(__sun)
36 | #include "getentropy_solaris.c"
37 | #elif defined(__APPLE__)
38 | #include "getentropy_osx.c"
39 | #elif defined(_AIX)
40 | #include "getentropy_aix.c"
41 | #elif defined(__hpux)
42 | #include "getentropy_hpux.c"
43 | #elif defined(_WIN32)
44 | #include "getentropy_win.c"
45 | #else
46 | #error "No getentropy hooks defined for this platform."
47 | #endif
48 |
--------------------------------------------------------------------------------
/src/getentropy_bsd.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: getentropy_freebsd.c,v 1.3 2016/08/07 03:27:21 tb Exp $ */
2 |
3 | /*
4 | * Copyright (c) 2014 Pawel Jakub Dawidek
5 | * Copyright (c) 2014 Brent Cook
6 | *
7 | * Permission to use, copy, modify, and distribute this software for any
8 | * purpose with or without fee is hereby granted, provided that the above
9 | * copyright notice and this permission notice appear in all copies.
10 | *
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 | *
19 | * Emulation of getentropy(2) as documented at:
20 | * http://man.openbsd.org/getentropy.2
21 | */
22 |
23 | #include
24 | #include
25 |
26 | #include
27 | #include
28 |
29 | int getentropy(void *buf, size_t len);
30 |
31 | /*
32 | * Derived from lib/libc/gen/arc4random.c from FreeBSD.
33 | */
34 | static size_t
35 | getentropy_sysctl(unsigned char *buf, size_t size)
36 | {
37 | int mib[2];
38 | size_t len, done;
39 |
40 | mib[0] = CTL_KERN;
41 | mib[1] = KERN_ARND;
42 | done = 0;
43 |
44 | do {
45 | len = size;
46 | if (sysctl(mib, 2, buf, &len, NULL, 0) == -1)
47 | return (done);
48 | done += len;
49 | buf += len;
50 | size -= len;
51 | } while (size > 0);
52 |
53 | return (done);
54 | }
55 |
56 | int
57 | getentropy(void *buf, size_t len)
58 | {
59 | if (len <= 256 && getentropy_sysctl(buf, len) == len)
60 | return (0);
61 |
62 | errno = EIO;
63 | return (-1);
64 | }
65 |
--------------------------------------------------------------------------------
/src/getentropy_win.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: getentropy_win.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */
2 |
3 | /*
4 | * Copyright (c) 2014, Theo de Raadt
5 | * Copyright (c) 2014, Bob Beck
6 | *
7 | * Permission to use, copy, modify, and distribute this software for any
8 | * purpose with or without fee is hereby granted, provided that the above
9 | * copyright notice and this permission notice appear in all copies.
10 | *
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 | *
19 | * Emulation of getentropy(2) as documented at:
20 | * http://man.openbsd.org/getentropy.2
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | int getentropy(void *buf, size_t len);
31 |
32 | /*
33 | * On Windows, CryptGenRandom is supposed to be a well-seeded
34 | * cryptographically strong random number generator.
35 | */
36 | int
37 | getentropy(void *buf, size_t len)
38 | {
39 | HCRYPTPROV provider;
40 |
41 | if (len > 256) {
42 | errno = EIO;
43 | return (-1);
44 | }
45 |
46 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
47 | CRYPT_VERIFYCONTEXT) == 0)
48 | goto fail;
49 | if (CryptGenRandom(provider, len, buf) == 0) {
50 | CryptReleaseContext(provider, 0);
51 | goto fail;
52 | }
53 | CryptReleaseContext(provider, 0);
54 | return (0);
55 |
56 | fail:
57 | errno = EIO;
58 | return (-1);
59 | }
60 |
--------------------------------------------------------------------------------
/src/libbsd-ctor.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libbsd-ctor
7 | Description: Automatic constructor functions for libbsd
8 | Version: @VERSION@
9 | URL: https://libbsd.freedesktop.org/
10 | Cflags: -I${includedir}
11 | Libs: -L${libdir} -Wl,-z,nodlopen -Wl,-u,libbsd_init_func -lbsd-ctor
12 | Requires: libbsd
13 |
--------------------------------------------------------------------------------
/src/libbsd-overlay.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libbsd
7 | Description: Utility functions from BSD systems (overlay)
8 | Version: @VERSION@
9 | URL: https://libbsd.freedesktop.org/
10 | Libs: -L${libdir} -lbsd
11 | Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@
12 | # We use -isystem instead of -I due the overlay via #include_next usage.
13 | Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY
14 |
--------------------------------------------------------------------------------
/src/libbsd.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libbsd
7 | Description: Utility functions from BSD systems
8 | Version: @VERSION@
9 | URL: https://libbsd.freedesktop.org/
10 | Libs: -L${libdir} -lbsd
11 | Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@
12 | Cflags: -I${includedir}
13 |
--------------------------------------------------------------------------------
/src/reallocarray.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
2 | /*
3 | * Copyright (c) 2008 Otto Moerbeek
4 | *
5 | * Permission to use, copy, modify, and distribute this software for any
6 | * purpose with or without fee is hereby granted, provided that the above
7 | * copyright notice and this permission notice appear in all copies.
8 | *
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | /*
24 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
25 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
26 | */
27 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
28 |
29 | void *
30 | reallocarray(void *optr, size_t nmemb, size_t size)
31 | {
32 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
33 | nmemb > 0 && SIZE_MAX / nmemb < size) {
34 | errno = ENOMEM;
35 | return NULL;
36 | }
37 | return realloc(optr, size * nmemb);
38 | }
39 |
--------------------------------------------------------------------------------
/src/reallocf.c:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright (c) 1998, M. Warner Losh
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 | * SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | #include
30 |
31 | void *
32 | reallocf(void *ptr, size_t size)
33 | {
34 | void *nptr;
35 |
36 | nptr = realloc(ptr, size);
37 |
38 | /*
39 | * When the System V compatibility option (malloc "V" flag) is
40 | * in effect, realloc(ptr, 0) frees the memory and returns NULL.
41 | * So, to avoid double free, call free() only when size != 0.
42 | * realloc(ptr, 0) can't fail when ptr != NULL.
43 | */
44 | if (!nptr && ptr && size != 0)
45 | free(ptr);
46 | return (nptr);
47 | }
48 |
--------------------------------------------------------------------------------
/src/recallocarray.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */
2 | /*
3 | * Copyright (c) 2008, 2017 Otto Moerbeek
4 | *
5 | * Permission to use, copy, modify, and distribute this software for any
6 | * purpose with or without fee is hereby granted, provided that the above
7 | * copyright notice and this permission notice appear in all copies.
8 | *
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | /*
25 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
26 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
27 | */
28 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
29 |
30 | void *
31 | recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size)
32 | {
33 | size_t oldsize, newsize;
34 | void *newptr;
35 |
36 | if (ptr == NULL)
37 | return calloc(newnmemb, size);
38 |
39 | if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
40 | newnmemb > 0 && SIZE_MAX / newnmemb < size) {
41 | errno = ENOMEM;
42 | return NULL;
43 | }
44 | newsize = newnmemb * size;
45 |
46 | if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
47 | oldnmemb > 0 && SIZE_MAX / oldnmemb < size) {
48 | errno = EINVAL;
49 | return NULL;
50 | }
51 | oldsize = oldnmemb * size;
52 |
53 | /*
54 | * Don't bother too much if we're shrinking just a bit,
55 | * we do not shrink for series of small steps, oh well.
56 | */
57 | if (newsize <= oldsize) {
58 | size_t d = oldsize - newsize;
59 |
60 | if (d < oldsize / 2 && d < (size_t)getpagesize()) {
61 | memset((char *)ptr + newsize, 0, d);
62 | return ptr;
63 | }
64 | }
65 |
66 | newptr = malloc(newsize);
67 | if (newptr == NULL)
68 | return NULL;
69 |
70 | if (newsize > oldsize) {
71 | memcpy(newptr, ptr, oldsize);
72 | memset((char *)newptr + oldsize, 0, newsize - oldsize);
73 | } else
74 | memcpy(newptr, ptr, newsize);
75 |
76 | explicit_bzero(ptr, oldsize);
77 | free(ptr);
78 |
79 | return newptr;
80 | }
81 |
--------------------------------------------------------------------------------
/src/setproctitle_ctor.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2013 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | /*
30 | * The automatic initialization cannot be part of the main shared library,
31 | * because there is no thread-safe way to change the environ global
32 | * variable. This is not a problem if the initializaion happens just at
33 | * program load time, but becomes one if the shared library is directly or
34 | * indirectly dlopen()ed during the execution of the program, which could
35 | * have either kept references to the old environ or could change it in
36 | * some other thread. This has been observed for example on systems using
37 | * Samba NSS modules.
38 | *
39 | * To avoid any other possible fallout, the constructor is split into a
40 | * new static library that needs to be linked explicitly into programs
41 | * using setproctitle(). As an additional safety measure the pkgconf(1)
42 | * linker flags will mark the program as not allowing to be dlopen()ed
43 | * so that we make sure to avoid the problem described above.
44 | */
45 |
46 | /*
47 | * Force setproctitle_init() function into the .init_array section instead of
48 | * expecting either the compiler to place constructors there or the linker to
49 | * move them from .ctors to .init_array.
50 | */
51 | void (*libbsd_init_func)(int argc, char *argv[], char *envp[])
52 | __attribute__((__section__(".init_array"), __used__)) = setproctitle_init;
53 |
--------------------------------------------------------------------------------
/src/strlcat.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1998, 2015 Todd C. Miller
5 | *
6 | * Permission to use, copy, modify, and distribute this software for any
7 | * purpose with or without fee is hereby granted, provided that the above
8 | * copyright notice and this permission notice appear in all copies.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 | */
18 |
19 | #include
20 | #include
21 |
22 | /*
23 | * Appends src to string dst of size dsize (unlike strncat, dsize is the
24 | * full size of dst, not space left). At most dsize-1 characters
25 | * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
26 | * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
27 | * If retval >= dsize, truncation occurred.
28 | */
29 | size_t
30 | strlcat(char *dst, const char *src, size_t dsize)
31 | {
32 | const char *odst = dst;
33 | const char *osrc = src;
34 | size_t n = dsize;
35 | size_t dlen;
36 |
37 | /* Find the end of dst and adjust bytes left but don't go past end. */
38 | while (n-- != 0 && *dst != '\0')
39 | dst++;
40 | dlen = dst - odst;
41 | n = dsize - dlen;
42 |
43 | if (n-- == 0)
44 | return(dlen + strlen(src));
45 | while (*src != '\0') {
46 | if (n != 0) {
47 | *dst++ = *src;
48 | n--;
49 | }
50 | src++;
51 | }
52 | *dst = '\0';
53 |
54 | return(dlen + (src - osrc)); /* count does not include NUL */
55 | }
56 |
--------------------------------------------------------------------------------
/src/strlcpy.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1998, 2015 Todd C. Miller
5 | *
6 | * Permission to use, copy, modify, and distribute this software for any
7 | * purpose with or without fee is hereby granted, provided that the above
8 | * copyright notice and this permission notice appear in all copies.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 | */
18 |
19 | #include
20 | #include
21 |
22 | /*
23 | * Copy string src to buffer dst of size dsize. At most dsize-1
24 | * chars will be copied. Always NUL terminates (unless dsize == 0).
25 | * Returns strlen(src); if retval >= dsize, truncation occurred.
26 | */
27 | size_t
28 | strlcpy(char *dst, const char *src, size_t dsize)
29 | {
30 | const char *osrc = src;
31 | size_t nleft = dsize;
32 |
33 | /* Copy as many bytes as will fit. */
34 | if (nleft != 0) {
35 | while (--nleft != 0) {
36 | if ((*dst++ = *src++) == '\0')
37 | break;
38 | }
39 | }
40 |
41 | /* Not enough room in dst, add NUL and traverse rest of src. */
42 | if (nleft == 0) {
43 | if (dsize != 0)
44 | *dst = '\0'; /* NUL-terminate dst */
45 | while (*src++)
46 | ;
47 | }
48 |
49 | return(src - osrc - 1); /* count does not include NUL */
50 | }
51 |
--------------------------------------------------------------------------------
/src/strnstr.c:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright (c) 2001 Mike Barcroft
3 | * Copyright (c) 1990, 1993
4 | * The Regents of the University of California. All rights reserved.
5 | *
6 | * This code is derived from software contributed to Berkeley by
7 | * Chris Torek.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions
11 | * are met:
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright
15 | * notice, this list of conditions and the following disclaimer in the
16 | * documentation and/or other materials provided with the distribution.
17 | * 3. Neither the name of the University nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | */
33 |
34 | #include
35 |
36 | #include
37 |
38 | /*
39 | * Find the first occurrence of find in s, where the search is limited to the
40 | * first slen characters of s.
41 | */
42 | char *
43 | strnstr(const char *s, const char *find, size_t slen)
44 | {
45 | char c, sc;
46 | size_t len;
47 |
48 | if ((c = *find++) != '\0') {
49 | len = strlen(find);
50 | do {
51 | do {
52 | if (slen-- < 1 || (sc = *s++) == '\0')
53 | return (NULL);
54 | } while (sc != c);
55 | if (len > slen)
56 | return (NULL);
57 | } while (strncmp(s, find, len) != 0);
58 | s--;
59 | }
60 | return ((char *)s);
61 | }
62 |
--------------------------------------------------------------------------------
/src/strtonum.c:
--------------------------------------------------------------------------------
1 | /* $NetBSD: strtonum.c,v 1.7 2024/01/20 16:13:39 christos Exp $ */
2 | /*-
3 | * Copyright (c) 2014 The NetBSD Foundation, Inc.
4 | * All rights reserved.
5 | *
6 | * This code is derived from software contributed to The NetBSD Foundation
7 | * by Christos Zoulas.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions
11 | * are met:
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright
15 | * notice, this list of conditions and the following disclaimer in the
16 | * documentation and/or other materials provided with the distribution.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | * POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include
32 |
33 | #include
34 | #include
35 | #include
36 | #include
37 |
38 | long long
39 | strtonum(const char *nptr, long long minval, long long maxval,
40 | const char **errstr)
41 | {
42 | int e;
43 | long long rv;
44 | const char *resp;
45 | char *eptr;
46 |
47 | if (errstr == NULL)
48 | errstr = &resp;
49 |
50 | if (minval > maxval)
51 | goto out;
52 |
53 | rv = (long long)strtoi(nptr, &eptr, 10, minval, maxval, &e);
54 |
55 | switch (e) {
56 | case 0:
57 | *errstr = NULL;
58 | return rv;
59 | case ECANCELED:
60 | case ENOTSUP:
61 | case EINVAL:
62 | goto out;
63 | case ERANGE:
64 | if (*eptr)
65 | goto out;
66 | *errstr = rv == maxval ? "too large" : "too small";
67 | return 0;
68 | default:
69 | abort();
70 | }
71 |
72 | out:
73 | *errstr = "invalid";
74 | return 0;
75 | }
76 |
--------------------------------------------------------------------------------
/src/vasprintf.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2010-2024 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | #include
30 | #include
31 | #include
32 |
33 | int
34 | vasprintf(char **strp, char const *fmt, va_list args)
35 | {
36 | va_list args_copy;
37 | int needed, n;
38 | char *str;
39 |
40 | va_copy(args_copy, args);
41 | needed = vsnprintf(NULL, 0, fmt, args_copy);
42 | va_end(args_copy);
43 |
44 | if (needed < 0) {
45 | *strp = NULL;
46 | return -1;
47 | }
48 |
49 | str = malloc(needed + 1);
50 | if (str == NULL) {
51 | *strp = NULL;
52 | return -1;
53 | }
54 |
55 | n = vsnprintf(str, needed + 1, fmt, args);
56 | if (n < 0) {
57 | free(str);
58 | str = NULL;
59 | }
60 |
61 | *strp = str;
62 |
63 | return n;
64 | }
65 |
--------------------------------------------------------------------------------
/src/wcslcat.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1998 Todd C. Miller
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | *
27 | * from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp
28 | * from NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp
29 | */
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | /*
36 | * Appends src to string dst of size siz (unlike wcsncat, siz is the
37 | * full size of dst, not space left). At most siz-1 characters
38 | * will be copied. Always NUL terminates (unless siz == 0).
39 | * Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
40 | * truncation occurred.
41 | */
42 | size_t
43 | wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
44 | {
45 | wchar_t *d = dst;
46 | const wchar_t *s = src;
47 | size_t n = siz;
48 | size_t dlen;
49 |
50 | /* Find the end of dst and adjust bytes left but don't go past end */
51 | while (*d != '\0' && n-- != 0)
52 | d++;
53 | dlen = d - dst;
54 | n = siz - dlen;
55 |
56 | if (n == 0)
57 | return(dlen + wcslen(s));
58 | while (*s != '\0') {
59 | if (n != 1) {
60 | *d++ = *s;
61 | n--;
62 | }
63 | s++;
64 | }
65 | *d = '\0';
66 |
67 | return(dlen + (s - src)); /* count does not include NUL */
68 | }
69 |
--------------------------------------------------------------------------------
/src/wcslcpy.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1998 Todd C. Miller
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | *
27 | * from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
28 | * from NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp
29 | */
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | /*
36 | * Copy src to string dst of size siz. At most siz-1 characters
37 | * will be copied. Always NUL terminates (unless siz == 0).
38 | * Returns wcslen(src); if retval >= siz, truncation occurred.
39 | */
40 | size_t
41 | wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
42 | {
43 | wchar_t *d = dst;
44 | const wchar_t *s = src;
45 | size_t n = siz;
46 |
47 | /* Copy as many bytes as will fit */
48 | if (n != 0 && --n != 0) {
49 | do {
50 | if ((*d++ = *s++) == 0)
51 | break;
52 | } while (--n != 0);
53 | }
54 |
55 | /* Not enough room in dst, add NUL and traverse rest of src */
56 | if (n == 0) {
57 | if (siz != 0)
58 | *d = '\0'; /* NUL-terminate dst */
59 | while (*s++)
60 | ;
61 | }
62 |
63 | return(s - src - 1); /* count does not include NUL */
64 | }
65 |
--------------------------------------------------------------------------------
/test/.gitignore:
--------------------------------------------------------------------------------
1 | arc4random
2 | bzero
3 | closefrom
4 | endian
5 | explicit_bzero
6 | fgetln
7 | fparseln
8 | fpurge
9 | funopen
10 | headers-overlay-gen.c
11 | headers-system-gen.c
12 | humanize
13 | md5
14 | nlist
15 | overlay
16 | proctitle
17 | proctitle-init
18 | progname
19 | pwcache
20 | setmode
21 | strl
22 | strmode
23 | strnstr
24 | strtonum
25 | timeconv32
26 | timeconv64
27 | vis
28 | vis-openbsd
29 |
--------------------------------------------------------------------------------
/test/bzero.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | int
31 | main(int argc, char *argv[])
32 | {
33 | unsigned char array[40];
34 | size_t i;
35 |
36 | memset(array, 0x3e, sizeof(array));
37 |
38 | explicit_bzero(array, 0);
39 | for (i = 0; i < sizeof(array); i++)
40 | assert(array[i] == 0x3e);
41 |
42 | explicit_bzero(array, sizeof(array));
43 | for (i = 0; i < sizeof(array); i++)
44 | assert(array[i] == 0);
45 |
46 | return 0;
47 | }
48 |
--------------------------------------------------------------------------------
/test/closefrom.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | int
34 | main(int argc, char *argv[])
35 | {
36 | int i;
37 | int fd;
38 | int fd_max;
39 |
40 | fd = open("/dev/null", O_RDONLY);
41 |
42 | fd_max = 1024;
43 |
44 | /* First make sure we have a clean fd list. */
45 | for (i = 4; i < fd_max; i++)
46 | close(i);
47 |
48 | /* Then initialize each even fd. */
49 | for (i = 4; i < fd_max; i *= 2) {
50 | int fd_new = dup2(fd, i);
51 |
52 | if (fd_new < 0 && (errno == EMFILE || errno == EBADF)) {
53 | fd_max = i - 1;
54 | break;
55 | }
56 | assert(fd_new == i);
57 | }
58 |
59 | if (fd < 4)
60 | close(fd);
61 | closefrom(4);
62 |
63 | for (i = 4; i < fd_max; i++) {
64 | int rc;
65 |
66 | errno = 0;
67 | rc = fcntl(i, F_GETFD);
68 | #ifdef __APPLE__
69 | /* On macOS we only set close-on-exec. */
70 | if ((i & (i - 1)) == 0)
71 | assert(rc == FD_CLOEXEC);
72 | else
73 | assert(rc == -1 && errno == EBADF);
74 | #else
75 | assert(rc == -1 && errno == EBADF);
76 | #endif
77 | }
78 | assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF);
79 |
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/test/endian.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 |
29 | #include
30 | #include
31 |
32 | int
33 | main(int argc, char *argv[])
34 | {
35 | unsigned char decstream[] = {
36 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
37 | };
38 | unsigned char encstream[sizeof(decstream)];
39 |
40 | assert(be16dec(decstream) == 0x0011);
41 | assert(le16dec(decstream) == 0x1100);
42 |
43 | assert(be32dec(decstream) == 0x00112233);
44 | assert(le32dec(decstream) == 0x33221100);
45 |
46 | assert(be64dec(decstream) == 0x0011223344556677);
47 | assert(le64dec(decstream) == 0x7766554433221100);
48 |
49 | memset(encstream, 0, sizeof(encstream));
50 | be16enc(encstream, 0x1100);
51 | assert(memcmp(encstream, decstream, sizeof(uint16_t)));
52 | le16enc(encstream, 0x0011);
53 | assert(memcmp(encstream, decstream, sizeof(uint16_t)));
54 |
55 | memset(encstream, 0, sizeof(encstream));
56 | be32enc(encstream, 0x33221100);
57 | assert(memcmp(encstream, decstream, sizeof(uint32_t)));
58 | le32enc(encstream, 0x00112233);
59 | assert(memcmp(encstream, decstream, sizeof(uint32_t)));
60 |
61 | memset(encstream, 0, sizeof(encstream));
62 | be64enc(encstream, 0x7766554433221100);
63 | assert(memcmp(encstream, decstream, sizeof(uint64_t)));
64 | le64enc(encstream, 0x0011223344556677);
65 | assert(memcmp(encstream, decstream, sizeof(uint64_t)));
66 |
67 | return 0;
68 | }
69 |
--------------------------------------------------------------------------------
/test/fparseln.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | #include "test-stream.h"
33 |
34 | #define TEST_LINES 9
35 | static const char *data_test[] = {
36 | "# This is a test\n",
37 | "line 1\n",
38 | "line 2 \\\n",
39 | "line 3 # Comment\n",
40 | "line 4 \\# Not comment \\\\\\\\\n",
41 | "\n",
42 | "# And a comment \\\n",
43 | "line 5 \\\\\\\n",
44 | "line 6 w/ escape sequences \\b, \\t, \\\\t",
45 | };
46 |
47 | #define EXPECT_LINES 5
48 | static size_t lineno_expect[] = { 2, 4, 5, 6, 9 };
49 |
50 | static const char *data_parse[] = {
51 | "line 1",
52 | "line 2 line 3 ",
53 | "line 4 \\# Not comment \\\\\\\\",
54 | "",
55 | "line 5 \\\\line 6 w/ escape sequences \\b, \\t, \\\\t",
56 | };
57 | static const char *data_escape[] = {
58 | "line 1",
59 | "line 2 line 3 ",
60 | "line 4 # Not comment \\\\",
61 | "",
62 | "line 5 \\line 6 w/ escape sequences b, t, \\t",
63 | };
64 |
65 | static void
66 | test_fparseln(const char **data_expect, int flags)
67 | {
68 | FILE *fp;
69 | size_t i, len, lineno = 0;
70 |
71 | fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_test, TEST_LINES);
72 | for (i = 0; i < EXPECT_LINES; i++) {
73 | char *str = fparseln(fp, &len, &lineno, NULL, flags);
74 |
75 | assert(str);
76 | assert(lineno == lineno_expect[i]);
77 | assert(strcmp(str, data_expect[i]) == 0);
78 |
79 | free(str);
80 | }
81 | assert(fparseln(fp, &len, NULL, NULL, 0) == NULL);
82 | pipe_close(fp);
83 | }
84 |
85 | int
86 | main(int argc, char **argv)
87 | {
88 | test_fparseln(data_parse, 0);
89 | test_fparseln(data_escape, FPARSELN_UNESCALL);
90 |
91 | return 0;
92 | }
93 |
--------------------------------------------------------------------------------
/test/fpurge.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2011 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | static int
32 | test_memstream(void)
33 | {
34 | int rc = 0;
35 | #if HAVE_OPEN_MEMSTREAM
36 | FILE *fp;
37 | char *buf = NULL;
38 | size_t bufsz = 0;
39 |
40 | fp = open_memstream(&buf, &bufsz);
41 | if (fp == NULL)
42 | return 1;
43 |
44 | fputs("World", fp);
45 | if (fpurge(fp) < 0)
46 | rc = 1;
47 | fflush(fp);
48 | if (bufsz != 0)
49 | rc = 1;
50 |
51 | fclose(fp);
52 | free(buf);
53 | #endif
54 |
55 | return rc;
56 | }
57 |
58 | int
59 | main(int argc, char *argv[])
60 | {
61 | FILE *fp;
62 | int rc;
63 |
64 | if (fpurge(NULL) == 0)
65 | return 1;
66 |
67 | fp = fopen("/dev/zero", "r");
68 | if (fpurge(fp) < 0)
69 | return 1;
70 | fclose(fp);
71 |
72 | rc = test_memstream();
73 |
74 | return rc;
75 | }
76 |
--------------------------------------------------------------------------------
/test/headers-overlay.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | run()
6 | {
7 | echo "$@"
8 | "$@"
9 | }
10 |
11 | incdir="${top_srcdir}/include/bsd"
12 | CPPFLAGS="$CPPFLAGS -DLIBBSD_OVERLAY"
13 |
14 | for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do
15 | cat >headers-overlay-gen.c <
17 | int main() { return 0; }
18 | SOURCE
19 |
20 | echo "testing header $inc"
21 | run $CC -isystem "$incdir" $CPPFLAGS headers-overlay-gen.c -o headers-overlay
22 | echo
23 |
24 | rm -f headers-overlay
25 | rm -f headers-overlay-gen*
26 | done
27 |
--------------------------------------------------------------------------------
/test/headers-system.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | run()
6 | {
7 | echo "$@"
8 | "$@"
9 | }
10 |
11 | incdir="${top_srcdir}/include"
12 |
13 | for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do
14 | cat >headers-system-gen.c <
16 | int main() { return 0; }
17 | SOURCE
18 |
19 | echo "testing header $inc"
20 | run $CC -isystem "$incdir" $CPPFLAGS headers-system-gen.c -o headers-system
21 | echo
22 |
23 | rm -f headers-system
24 | rm -f headers-system-gen.*
25 | done
26 |
--------------------------------------------------------------------------------
/test/humanize.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2013 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | int
32 | main(int argc, char **argv)
33 | {
34 | uint64_t uval;
35 | int64_t val;
36 |
37 | assert(expand_number("512", &uval) == 0);
38 | assert(uval == 512);
39 |
40 | assert(expand_number("512b", &uval) == 0);
41 | assert(uval == 512);
42 |
43 | assert(expand_number("10k", &uval) == 0);
44 | assert(uval == 10240);
45 |
46 | assert(expand_number("20M", &uval) == 0);
47 | assert(uval == 20971520);
48 |
49 | assert(dehumanize_number("512", &val) == 0);
50 | assert(val == 512);
51 |
52 | assert(dehumanize_number("512b", &val) == 0);
53 | assert(val == 512);
54 |
55 | assert(dehumanize_number("10k", &val) == 0);
56 | assert(val == 10240);
57 |
58 | assert(dehumanize_number("20M", &val) == 0);
59 | assert(val == 20971520);
60 |
61 | assert(dehumanize_number("-3G", &val) == 0);
62 | assert(val == -3221225472LL);
63 |
64 | assert(dehumanize_number("9223372036854775807", &val) == 0);
65 | assert(val == INT64_MAX);
66 |
67 | assert(dehumanize_number("9223372036854775808", &val) == -1);
68 | assert(errno == ERANGE);
69 |
70 | assert(dehumanize_number("-9223372036854775808", &val) == 0);
71 | assert(val == INT64_MIN);
72 |
73 | assert(dehumanize_number("-9223372036854775809", &val) == -1);
74 | assert(errno == ERANGE);
75 |
76 | return 0;
77 | }
78 |
--------------------------------------------------------------------------------
/test/md5.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2016 Guillem Jover
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include