mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-20 22:31:34 +02:00
Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
918a4dba4a | ||
![]() |
444bd1fbb8 | ||
![]() |
1d69ae1cd5 | ||
![]() |
14524b545d | ||
![]() |
c21d788fea | ||
![]() |
fdcae57707 | ||
![]() |
e9e4a60d7e | ||
![]() |
309c82a016 | ||
![]() |
cd67cb1417 | ||
![]() |
1b5b1cd52a | ||
![]() |
ddefaae330 | ||
![]() |
e7f3976088 | ||
![]() |
e59ac2c96c | ||
![]() |
7cfa7e4304 | ||
![]() |
7620fef70b | ||
![]() |
08139dd50e | ||
![]() |
d90ce079f7 | ||
![]() |
c1d086c224 | ||
![]() |
e37293a18a | ||
![]() |
34bf1068a2 | ||
![]() |
4eab0cc351 | ||
![]() |
752997462a | ||
![]() |
d5d9186937 | ||
![]() |
f8e8063079 | ||
![]() |
786d143920 | ||
![]() |
866f73af91 | ||
![]() |
f71d8e0501 | ||
![]() |
0b96e1a218 | ||
![]() |
109cafb393 | ||
![]() |
6434858314 | ||
![]() |
943939d0e5 | ||
![]() |
3d614131b5 | ||
![]() |
8723226040 | ||
![]() |
b5cc17d664 | ||
![]() |
abf14c3940 | ||
![]() |
23973e2221 | ||
![]() |
980f04f77b | ||
![]() |
8d2f12d7f0 | ||
![]() |
88004b30ff | ||
![]() |
dcaa93d984 | ||
![]() |
0aa777f47e | ||
![]() |
540ab03b18 | ||
![]() |
93321224f6 | ||
![]() |
2fb7200d45 | ||
![]() |
0acd86f6eb | ||
![]() |
901ed630fc | ||
![]() |
059f89ca95 | ||
![]() |
4a6303ba3b |
13
.gitignore
vendored
13
.gitignore
vendored
@@ -1,6 +1,19 @@
|
|||||||
ChangeLog
|
ChangeLog
|
||||||
*.pc
|
*.pc
|
||||||
|
*.la
|
||||||
*.lo
|
*.lo
|
||||||
*.o
|
*.o
|
||||||
*.so*
|
*.so*
|
||||||
*.a
|
*.a
|
||||||
|
.deps/
|
||||||
|
.libs/
|
||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
aclocal.m4
|
||||||
|
autom4te.cache/
|
||||||
|
build-aux/
|
||||||
|
configure
|
||||||
|
config.*
|
||||||
|
libtool
|
||||||
|
m4/
|
||||||
|
stamp-h1
|
||||||
|
144
COPYING
144
COPYING
@@ -1,3 +1,7 @@
|
|||||||
|
The following 4-clause BSD licenses are only for man pages, specifically
|
||||||
|
for man/arc4random.3, man/tree.3 and man/getprogname.3.
|
||||||
|
|
||||||
|
|
||||||
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -28,7 +32,41 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright © 2004-2006, 2008-2011 Guillem Jover
|
Copyright © 2001 Christopher G. Demetriou
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this software
|
||||||
|
must display the following acknowledgement:
|
||||||
|
This product includes software developed for the
|
||||||
|
NetBSD Project. See http://www.netbsd.org/ for
|
||||||
|
information about NetBSD.
|
||||||
|
4. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
The rest of the licenses apply to code and/or man pages.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright © 2004-2006, 2008-2011 Guillem Jover <guillem@hadrons.org>
|
||||||
Copyright © 2005 Hector Garcia Alvarez
|
Copyright © 2005 Hector Garcia Alvarez
|
||||||
Copyright © 2005 Aurelien Jarno
|
Copyright © 2005 Aurelien Jarno
|
||||||
Copyright © 2006 Robert Millan
|
Copyright © 2006 Robert Millan
|
||||||
@@ -138,6 +176,27 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
Copyright © 1995 Peter Wemm <peter@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, is permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice immediately at the beginning of the file, without modification,
|
||||||
|
this list of conditions, and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. This work was done expressly for inclusion into FreeBSD. Other use
|
||||||
|
is permitted provided this notation is included.
|
||||||
|
4. Absolutely no warranty of function or purpose is made by the author
|
||||||
|
Peter Wemm.
|
||||||
|
5. Modifications may be freely made to this file providing the above
|
||||||
|
conditions are met.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
Copyright © 1997-2000, 2002, 2005, 2006, 2008 The NetBSD Foundation, Inc.
|
Copyright © 1997-2000, 2002, 2005, 2006, 2008 The NetBSD Foundation, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -174,6 +233,33 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
Copyright (c) 2009 Advanced Computing Technologies LLC
|
||||||
|
Written by: John H. Baldwin <jhb@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
Copyright © 1998, M. Warner Losh <imp@freebsd.org>
|
Copyright © 1998, M. Warner Losh <imp@freebsd.org>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -251,6 +337,32 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
Copyright © 2002 Thomas Moestl <tmm@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
Copyright © 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
Copyright © 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -277,6 +389,33 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
Copyright © 2007 Eric Anderson <anderson@FreeBSD.org>
|
||||||
|
Copyright © 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -349,7 +488,8 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright © 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
|
Copyright © 2000-2002, 2004-2005, 2007, 2010
|
||||||
|
Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
237
Makefile
237
Makefile
@@ -1,237 +0,0 @@
|
|||||||
VERSION := $(shell ./get-version)
|
|
||||||
|
|
||||||
LIB_NAME := libbsd
|
|
||||||
LIB_VERSION_MAJOR := 0
|
|
||||||
LIB_VERSION_MINOR := 3
|
|
||||||
LIB_VERSION_MICRO := 0
|
|
||||||
LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
|
|
||||||
|
|
||||||
LIB_PKGCONFIG := $(LIB_NAME).pc
|
|
||||||
LIB_PKGCONFIG_OVERLAY := $(LIB_NAME)-overlay.pc
|
|
||||||
LIB_STATIC := $(LIB_NAME).a
|
|
||||||
LIB_SHARED_SO := $(LIB_NAME).so
|
|
||||||
LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR)
|
|
||||||
LIB_SHARED := $(LIB_SONAME).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
|
|
||||||
|
|
||||||
TAR_NAME := $(LIB_NAME)-$(VERSION)
|
|
||||||
TAR_FILE := $(TAR_NAME).tar.gz
|
|
||||||
|
|
||||||
LIB_DIST := \
|
|
||||||
ChangeLog
|
|
||||||
|
|
||||||
LIB_SRCS_GEN := \
|
|
||||||
hash/md5hl.c
|
|
||||||
LIB_SRCS := \
|
|
||||||
arc4random.c \
|
|
||||||
bsd_getopt.c \
|
|
||||||
err.c \
|
|
||||||
fgetln.c \
|
|
||||||
flopen.c \
|
|
||||||
fpurge.c \
|
|
||||||
getpeereid.c \
|
|
||||||
heapsort.c \
|
|
||||||
merge.c \
|
|
||||||
humanize_number.c \
|
|
||||||
dehumanize_number.c \
|
|
||||||
inet_net_pton.c \
|
|
||||||
hash/md5.c \
|
|
||||||
pidfile.c \
|
|
||||||
readpassphrase.c \
|
|
||||||
reallocf.c \
|
|
||||||
setmode.c \
|
|
||||||
setproctitle.c \
|
|
||||||
strmode.c \
|
|
||||||
strtonum.c \
|
|
||||||
strlcat.c strlcpy.c \
|
|
||||||
fmtcheck.c \
|
|
||||||
nlist.c \
|
|
||||||
progname.c \
|
|
||||||
radixsort.c \
|
|
||||||
vis.c unvis.c \
|
|
||||||
$(LIB_SRCS_GEN)
|
|
||||||
LIB_SRCS_GEN := $(patsubst %,src/%,$(LIB_SRCS_GEN))
|
|
||||||
LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS))
|
|
||||||
|
|
||||||
LIB_INCLUDES := \
|
|
||||||
bsd/cdefs.h \
|
|
||||||
bsd/queue.h \
|
|
||||||
bsd/ip_icmp.h \
|
|
||||||
bsd/sys/cdefs.h \
|
|
||||||
bsd/sys/bitstring.h \
|
|
||||||
bsd/sys/endian.h \
|
|
||||||
bsd/sys/poll.h \
|
|
||||||
bsd/sys/queue.h \
|
|
||||||
bsd/sys/tree.h \
|
|
||||||
bsd/netinet/ip_icmp.h \
|
|
||||||
bsd/err.h \
|
|
||||||
bsd/getopt.h \
|
|
||||||
bsd/inet.h \
|
|
||||||
bsd/random.h \
|
|
||||||
bsd/md5.h \
|
|
||||||
bsd/string.h \
|
|
||||||
bsd/bsd.h \
|
|
||||||
bsd/stdio.h \
|
|
||||||
bsd/stdlib.h \
|
|
||||||
bsd/readpassphrase.h \
|
|
||||||
bsd/unistd.h \
|
|
||||||
bsd/nlist.h \
|
|
||||||
bsd/vis.h \
|
|
||||||
bsd/libutil.h \
|
|
||||||
nlist.h \
|
|
||||||
vis.h \
|
|
||||||
libutil.h
|
|
||||||
|
|
||||||
LIB_MANS_GEN := \
|
|
||||||
md5.3bsd
|
|
||||||
LIB_MANS := \
|
|
||||||
arc4random.3 \
|
|
||||||
arc4random_addrandom.3 \
|
|
||||||
arc4random_buf.3 \
|
|
||||||
arc4random_stir.3 \
|
|
||||||
arc4random_uniform.3 \
|
|
||||||
dehumanize_number.3 \
|
|
||||||
strtonum.3 \
|
|
||||||
strlcpy.3 \
|
|
||||||
strlcat.3 \
|
|
||||||
fgetln.3 \
|
|
||||||
flopen.3 \
|
|
||||||
getpeereid.3 \
|
|
||||||
readpassphrase.3 \
|
|
||||||
reallocf.3 \
|
|
||||||
heapsort.3 \
|
|
||||||
humanize_number.3 \
|
|
||||||
fmtcheck.3 \
|
|
||||||
mergesort.3 \
|
|
||||||
radixsort.3 \
|
|
||||||
sradixsort.3 \
|
|
||||||
nlist.3 \
|
|
||||||
pidfile.3 \
|
|
||||||
setmode.3 \
|
|
||||||
getmode.3 \
|
|
||||||
strmode.3 \
|
|
||||||
unvis.3 \
|
|
||||||
vis.3 \
|
|
||||||
$(LIB_MANS_GEN)
|
|
||||||
LIB_MANS_GEN := $(patsubst %,src/%,$(LIB_MANS_GEN))
|
|
||||||
LIB_MANS := $(patsubst %,src/%,$(LIB_MANS))
|
|
||||||
|
|
||||||
LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
|
|
||||||
LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo)
|
|
||||||
|
|
||||||
AR = ar
|
|
||||||
CC = gcc
|
|
||||||
CCLD = $(CC)
|
|
||||||
|
|
||||||
# Set default values for user variables
|
|
||||||
CPPFLAGS ?=
|
|
||||||
CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable
|
|
||||||
LDFLAGS ?=
|
|
||||||
|
|
||||||
# Internal makefile variables
|
|
||||||
MK_CPPFLAGS := -Iinclude/bsd/ -Iinclude/ \
|
|
||||||
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
|
||||||
-D_GNU_SOURCE -D__REENTRANT
|
|
||||||
MK_CFLAGS :=
|
|
||||||
MK_LDFLAGS :=
|
|
||||||
|
|
||||||
COMPILE = $(CC) $(MK_CPPFLAGS) $(CPPFLAGS) $(MK_CFLAGS) $(CFLAGS)
|
|
||||||
LINK = $(CCLD) $(MK_CFLAGS) $(CFLAGS) $(MK_LDFLAGS) $(LDFLAGS)
|
|
||||||
|
|
||||||
prefix = /usr
|
|
||||||
exec_prefix =
|
|
||||||
libdir = ${exec_prefix}/lib
|
|
||||||
usrlibdir = ${prefix}/lib
|
|
||||||
includedir = ${prefix}/include
|
|
||||||
pkgconfigdir = ${usrlibdir}/pkgconfig
|
|
||||||
mandir = ${prefix}/share/man
|
|
||||||
|
|
||||||
.PHONY: libs
|
|
||||||
libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG) $(LIB_PKGCONFIG_OVERLAY)
|
|
||||||
|
|
||||||
.PHONY: man
|
|
||||||
man: $(LIB_MANS)
|
|
||||||
|
|
||||||
%.lo: %.c
|
|
||||||
$(COMPILE) -o $@ -DPIC -fPIC -c $<
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(COMPILE) -o $@ -c $<
|
|
||||||
|
|
||||||
src/md5.3bsd: src/mdX.3
|
|
||||||
sed -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' $< > $@
|
|
||||||
|
|
||||||
src/hash/md5hl.c: src/hash/helper.c
|
|
||||||
sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
|
|
||||||
|
|
||||||
%.pc: %.pc.in
|
|
||||||
sed -e 's:@VERSION@:$(VERSION):' \
|
|
||||||
-e 's:@prefix@:$(value prefix):' \
|
|
||||||
-e 's:@exec_prefix@:$(value exec_prefix):' \
|
|
||||||
-e 's:@libdir@:$(value usrlibdir):' \
|
|
||||||
-e 's:@includedir@:$(value includedir):' \
|
|
||||||
$< > $@
|
|
||||||
|
|
||||||
$(LIB_STATIC): $(LIB_STATIC_OBJS)
|
|
||||||
$(AR) rcs $@ $^
|
|
||||||
|
|
||||||
$(LIB_SHARED_SO): $(LIB_SONAME)
|
|
||||||
ln -fs $^ $@
|
|
||||||
|
|
||||||
$(LIB_SONAME): $(LIB_SHARED)
|
|
||||||
ln -fs $^ $@
|
|
||||||
|
|
||||||
$(LIB_SHARED): $(LIB_SHARED_OBJS)
|
|
||||||
$(LINK) \
|
|
||||||
-shared \
|
|
||||||
-Wl,-soname -Wl,$(LIB_SONAME) \
|
|
||||||
-Wl,--version-script=Versions \
|
|
||||||
-o $@ $^
|
|
||||||
|
|
||||||
.PHONY: ChangeLog
|
|
||||||
ChangeLog:
|
|
||||||
-git log --stat -C >$@
|
|
||||||
|
|
||||||
.PHONY: dist
|
|
||||||
dist: $(LIB_DIST)
|
|
||||||
mkdir $(TAR_NAME)
|
|
||||||
echo $(VERSION) >$(TAR_NAME)/.dist-version
|
|
||||||
cp -a --parents $(LIB_DIST) `git ls-files` $(TAR_NAME)
|
|
||||||
tar czf $(TAR_FILE) --exclude=.gitignore $(TAR_NAME)
|
|
||||||
rm -rf $(TAR_NAME)
|
|
||||||
gpg -a -b $(TAR_FILE)
|
|
||||||
|
|
||||||
.PHONY: install
|
|
||||||
install: libs man
|
|
||||||
mkdir -p $(DESTDIR)$(libdir)
|
|
||||||
mkdir -p $(DESTDIR)$(usrlibdir)
|
|
||||||
mkdir -p $(DESTDIR)$(includedir)/bsd/
|
|
||||||
mkdir -p $(DESTDIR)$(includedir)/bsd/sys/
|
|
||||||
mkdir -p $(DESTDIR)$(includedir)/bsd/netinet/
|
|
||||||
mkdir -p $(DESTDIR)$(mandir)/man3
|
|
||||||
mkdir -p $(DESTDIR)$(pkgconfigdir)
|
|
||||||
install -m644 $(LIB_STATIC) $(DESTDIR)$(usrlibdir)
|
|
||||||
install -m755 $(LIB_SHARED) $(DESTDIR)$(libdir)
|
|
||||||
for i in $(LIB_INCLUDES); do \
|
|
||||||
install -m644 include/$$i $(DESTDIR)$(includedir)/$$i; \
|
|
||||||
done
|
|
||||||
install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3
|
|
||||||
install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir)
|
|
||||||
install -m644 $(LIB_PKGCONFIG_OVERLAY) $(DESTDIR)$(pkgconfigdir)
|
|
||||||
ifeq ($(libdir),$(usrlibdir))
|
|
||||||
# If both dirs are the same, do a relative symlink.
|
|
||||||
ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
|
|
||||||
else
|
|
||||||
# Otherwise, do an absolute one.
|
|
||||||
ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
|
|
||||||
endif
|
|
||||||
ln -sf $(LIB_SHARED) $(DESTDIR)$(libdir)/$(LIB_SONAME)
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
rm -f $(LIB_PKGCONFIG)
|
|
||||||
rm -f $(LIB_PKGCONFIG_OVERLAY)
|
|
||||||
rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN)
|
|
||||||
rm -f $(LIB_STATIC_OBJS)
|
|
||||||
rm -f $(LIB_STATIC)
|
|
||||||
rm -f $(LIB_SHARED_OBJS)
|
|
||||||
rm -f $(LIB_SHARED) $(LIB_SONAME) $(LIB_SHARED_SO)
|
|
19
Makefile.am
Normal file
19
Makefile.am
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
SUBDIRS = include man src test
|
||||||
|
|
||||||
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
autogen \
|
||||||
|
get-version \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
DISTCLEANFILES = ChangeLog
|
||||||
|
.PHONY: ChangeLog
|
||||||
|
|
||||||
|
ChangeLog:
|
||||||
|
git log --stat -C >$@
|
||||||
|
|
||||||
|
dist-hook:
|
||||||
|
echo $(VERSION) >$(distdir)/.dist-version
|
5
autogen
Executable file
5
autogen
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p m4
|
||||||
|
autoreconf -f -i
|
||||||
|
rm -rf autom4te.cache
|
86
configure.ac
Normal file
86
configure.ac
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
|
AC_PREREQ([2.67])
|
||||||
|
AC_INIT([libbsd], m4_esyscmd([./get-version]), [libbsd@lists.freedesktop.org])
|
||||||
|
AC_CONFIG_SRCDIR([src/fgetln.c])
|
||||||
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
|
AM_INIT_AUTOMAKE([1.8 foreign nostdinc])
|
||||||
|
|
||||||
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||||
|
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||||
|
|
||||||
|
# Check and store if we got user supplied variables
|
||||||
|
user_CFLAGS=${CFLAGS-unset}
|
||||||
|
|
||||||
|
# Checks for operating system services and capabilities.
|
||||||
|
AC_USE_SYSTEM_EXTENSIONS
|
||||||
|
AC_SYS_LARGEFILE
|
||||||
|
|
||||||
|
LT_INIT
|
||||||
|
|
||||||
|
# Checks for programs.
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
AC_PROG_LN_S
|
||||||
|
|
||||||
|
# Set default compiler variables
|
||||||
|
if test "$user_CFLAGS" = unset && test "$GCC" = yes; then
|
||||||
|
CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Checks for libraries.
|
||||||
|
|
||||||
|
# Checks for header files.
|
||||||
|
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h dir.h dirent.h])
|
||||||
|
|
||||||
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
|
AC_TYPE_UID_T
|
||||||
|
AC_C_INLINE
|
||||||
|
AC_TYPE_INT64_T
|
||||||
|
AC_TYPE_MODE_T
|
||||||
|
AC_TYPE_OFF_T
|
||||||
|
AC_TYPE_PID_T
|
||||||
|
AC_TYPE_SIZE_T
|
||||||
|
AC_TYPE_SSIZE_T
|
||||||
|
|
||||||
|
AC_CHECK_DECL([F_CLOSEM],
|
||||||
|
[AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
||||||
|
[Define to 1 if you have fcntl(F_CLOSEM)])],
|
||||||
|
[],
|
||||||
|
[#include <limits.h>
|
||||||
|
#include <fcntl.h>])
|
||||||
|
|
||||||
|
# Checks for library functions.
|
||||||
|
AC_MSG_CHECKING([for program_invocation_short_name])
|
||||||
|
AC_LINK_IFELSE(
|
||||||
|
[AC_LANG_PROGRAM([[#include <errno.h>]],
|
||||||
|
[[const char *p = program_invocation_short_name;]])],
|
||||||
|
[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
||||||
|
[Define to 1 if you have program_invocation_short_name])
|
||||||
|
AC_MSG_RESULT([yes])],
|
||||||
|
[AC_MSG_RESULT([no])])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for __progname])
|
||||||
|
AC_LINK_IFELSE(
|
||||||
|
[AC_LANG_PROGRAM([[]],
|
||||||
|
[[extern char *__progname;
|
||||||
|
const char *p = __progname;]])],
|
||||||
|
[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
||||||
|
AC_MSG_RESULT([yes])],
|
||||||
|
[AC_MSG_RESULT([no])])
|
||||||
|
|
||||||
|
AC_CHECK_FUNCS([dirfd __fpurge getexecname getline sysconf])
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([
|
||||||
|
Makefile
|
||||||
|
include/Makefile
|
||||||
|
man/Makefile
|
||||||
|
src/Makefile
|
||||||
|
src/libbsd.pc
|
||||||
|
src/libbsd-overlay.pc
|
||||||
|
test/Makefile
|
||||||
|
])
|
||||||
|
AC_CONFIG_HEADERS([config.h])
|
||||||
|
AC_OUTPUT
|
@@ -44,4 +44,5 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$version"
|
# Use printf to avoid the trailing new line that m4_esyscmd would not handle.
|
||||||
|
printf "$version"
|
||||||
|
24
include/Makefile.am
Normal file
24
include/Makefile.am
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
nobase_include_HEADERS = \
|
||||||
|
bsd/sys/bitstring.h \
|
||||||
|
bsd/sys/cdefs.h \
|
||||||
|
bsd/sys/endian.h \
|
||||||
|
bsd/sys/poll.h \
|
||||||
|
bsd/sys/queue.h \
|
||||||
|
bsd/sys/tree.h \
|
||||||
|
bsd/netinet/ip_icmp.h \
|
||||||
|
bsd/bitstring.h \
|
||||||
|
bsd/bsd.h \
|
||||||
|
bsd/err.h \
|
||||||
|
bsd/getopt.h \
|
||||||
|
bsd/libutil.h \
|
||||||
|
bsd/md5.h \
|
||||||
|
bsd/nlist.h \
|
||||||
|
bsd/readpassphrase.h \
|
||||||
|
bsd/stdio.h \
|
||||||
|
bsd/stdlib.h \
|
||||||
|
bsd/string.h \
|
||||||
|
bsd/unistd.h \
|
||||||
|
bsd/vis.h \
|
||||||
|
$(nil)
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2008, 2009 Guillem Jover
|
* Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,15 +24,9 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_INET_H
|
/* For compatibility with NetBSD and OpenBSD. */
|
||||||
#define LIBBSD_INET_H
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <sys/bitstring.h>
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <arpa/inet.h> instead."
|
|
||||||
#else
|
#else
|
||||||
#warning "Deprecated header, use <arpa/inet.h> instead."
|
#include <bsd/sys/bitstring.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2006 Guillem Jover
|
* Copyright © 2004, 2005, 2006 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -41,9 +41,4 @@
|
|||||||
#include <bsd/getopt.h>
|
#include <bsd/getopt.h>
|
||||||
#include <bsd/md5.h>
|
#include <bsd/md5.h>
|
||||||
|
|
||||||
/* FIXME: Will be removed in the future. */
|
|
||||||
#ifndef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2009 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_CDEFS_H
|
|
||||||
#define LIBBSD_BSD_CDEFS_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/sys/cdefs.h> or libbsd-overlay.pc instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/sys/cdefs.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#else
|
|
||||||
#include <bsd/sys/cdefs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2009, 2011 Guillem Jover
|
* Copyright © 2009, 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -25,6 +25,12 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <err.h>
|
||||||
|
#else
|
||||||
|
#include <err.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_ERR_H
|
#ifndef LIBBSD_ERR_H
|
||||||
#define LIBBSD_ERR_H
|
#define LIBBSD_ERR_H
|
||||||
|
|
||||||
@@ -32,12 +38,6 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include_next <err.h>
|
|
||||||
#else
|
|
||||||
#include <err.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
extern void warnc (int code, const char *format, ...);
|
extern void warnc (int code, const char *format, ...);
|
||||||
extern void vwarnc (int code, const char *format, va_list ap);
|
extern void vwarnc (int code, const char *format, va_list ap);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2011 Guillem Jover
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,16 +24,10 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_GETOPT_H
|
|
||||||
#define LIBBSD_GETOPT_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <getopt.h>
|
#include_next <getopt.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#warning "Deprecated header, use <bsd/unistd.h> or <unistd.h> with libbsd-overlay.pc instead."
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <bsd/unistd.h>
|
#include <bsd/unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <features.h>
|
#include <features.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/* for pidfile.c */
|
/* for pidfile.c */
|
||||||
struct pidfh {
|
struct pidfh {
|
||||||
@@ -53,6 +54,7 @@ struct pidfh {
|
|||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
int humanize_number(char *buf, size_t len, int64_t bytes,
|
int humanize_number(char *buf, size_t len, int64_t bytes,
|
||||||
const char *suffix, int scale, int flags);
|
const char *suffix, int scale, int flags);
|
||||||
|
int expand_number(const char *_buf, uint64_t *_num);
|
||||||
|
|
||||||
int flopen(const char *_path, int _flags, ...);
|
int flopen(const char *_path, int _flags, ...);
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover
|
* Copyright © 2009 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2009 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_QUEUE_H
|
|
||||||
#define LIBBSD_BSD_QUEUE_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/sys/queue.h> or libbsd-overlay.pc instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/sys/queue.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <sys/queue.h>
|
|
||||||
#else
|
|
||||||
#include <bsd/sys/queue.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2004, 2005, 2009 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_RANDOM_H
|
|
||||||
#define LIBBSD_RANDOM_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/stdlib.h> instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/stdlib.h> instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <stdlib.h>
|
|
||||||
#else
|
|
||||||
#include <bsd/stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2009, 2011 Guillem Jover
|
* Copyright © 2004, 2005, 2009, 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,18 +24,18 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_STDIO_H
|
|
||||||
#define LIBBSD_STDIO_H
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <stdio.h>
|
#include_next <stdio.h>
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_STDIO_H
|
||||||
|
#define LIBBSD_STDIO_H
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
const char *fmtcheck(const char *, const char *);
|
const char *fmtcheck(const char *, const char *);
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005 Aurelien Jarno
|
* Copyright © 2005 Aurelien Jarno
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2008-2011 Guillem Jover
|
* Copyright © 2008-2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -26,13 +26,6 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_STDLIB_H
|
|
||||||
#define LIBBSD_STDLIB_H
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <stdlib.h>
|
#include_next <stdlib.h>
|
||||||
#else
|
#else
|
||||||
@@ -46,16 +39,12 @@
|
|||||||
#include <bsd/libutil.h>
|
#include <bsd/libutil.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */
|
#ifndef LIBBSD_STDLIB_H
|
||||||
#ifndef LIBBSD_DISABLE_DEPRECATED
|
#define LIBBSD_STDLIB_H
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <stdio.h>
|
#include <sys/cdefs.h>
|
||||||
#include <unistd.h>
|
#include <sys/stat.h>
|
||||||
#else
|
#include <stdint.h>
|
||||||
#include <bsd/stdio.h>
|
|
||||||
#include <bsd/unistd.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
u_int32_t arc4random();
|
u_int32_t arc4random();
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2009, 2011 Guillem Jover
|
* Copyright © 2004, 2005, 2009, 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,26 +24,17 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_STRING_H
|
|
||||||
#define LIBBSD_STRING_H
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <string.h>
|
#include_next <string.h>
|
||||||
#else
|
#else
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_DISABLE_DEPRECATED
|
#ifndef LIBBSD_STRING_H
|
||||||
/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
|
#define LIBBSD_STRING_H
|
||||||
#ifdef LIBBSD_OVERLAY
|
|
||||||
#include <stdio.h>
|
#include <sys/cdefs.h>
|
||||||
#else
|
#include <sys/types.h>
|
||||||
#include <bsd/stdio.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004-2006, 2009-2011 Guillem Jover
|
* Copyright © 2004-2006, 2009-2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,15 +24,15 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_SYS_CDEFS_H
|
|
||||||
#define LIBBSD_SYS_CDEFS_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <sys/cdefs.h>
|
#include_next <sys/cdefs.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_CDEFS_H
|
||||||
|
#define LIBBSD_SYS_CDEFS_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some kFreeBSD headers expect those macros to be set for sanity checks.
|
* Some kFreeBSD headers expect those macros to be set for sanity checks.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2011 Guillem Jover
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,15 +24,15 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_SYS_ENDIAN_H
|
|
||||||
#define LIBBSD_SYS_ENDIAN_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <endian.h>
|
#include_next <endian.h>
|
||||||
#else
|
#else
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_ENDIAN_H
|
||||||
|
#define LIBBSD_SYS_ENDIAN_H
|
||||||
|
|
||||||
#ifndef _BYTE_ORDER
|
#ifndef _BYTE_ORDER
|
||||||
#define _BYTE_ORDER __BYTE_ORDER
|
#define _BYTE_ORDER __BYTE_ORDER
|
||||||
#endif
|
#endif
|
||||||
@@ -49,4 +49,140 @@
|
|||||||
#define _PDP_ENDIAN __PDP_ENDIAN
|
#define _PDP_ENDIAN __PDP_ENDIAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright © 2002 Thomas Moestl <tmm@FreeBSD.org>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
|
||||||
|
|
||||||
|
static __inline uint16_t
|
||||||
|
be16dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return ((p[0] << 8) | p[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline uint32_t
|
||||||
|
be32dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline uint64_t
|
||||||
|
be64dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline uint16_t
|
||||||
|
le16dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return ((p[1] << 8) | p[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline uint32_t
|
||||||
|
le32dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline uint64_t
|
||||||
|
le64dec(const void *pp)
|
||||||
|
{
|
||||||
|
uint8_t const *p = (uint8_t const *)pp;
|
||||||
|
|
||||||
|
return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
be16enc(void *pp, uint16_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
p[0] = (u >> 8) & 0xff;
|
||||||
|
p[1] = u & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
be32enc(void *pp, uint32_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
p[0] = (u >> 24) & 0xff;
|
||||||
|
p[1] = (u >> 16) & 0xff;
|
||||||
|
p[2] = (u >> 8) & 0xff;
|
||||||
|
p[3] = u & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
be64enc(void *pp, uint64_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
be32enc(p, (uint32_t)(u >> 32));
|
||||||
|
be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
le16enc(void *pp, uint16_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
p[0] = u & 0xff;
|
||||||
|
p[1] = (u >> 8) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
le32enc(void *pp, uint32_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
p[0] = u & 0xff;
|
||||||
|
p[1] = (u >> 8) & 0xff;
|
||||||
|
p[2] = (u >> 16) & 0xff;
|
||||||
|
p[3] = (u >> 24) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void
|
||||||
|
le64enc(void *pp, uint64_t u)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)pp;
|
||||||
|
|
||||||
|
le32enc(p, (uint32_t)(u & 0xffffffffU));
|
||||||
|
le32enc(p + 4, (uint32_t)(u >> 32));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2011 Guillem Jover
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,15 +24,15 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_SYS_POLL_H
|
|
||||||
#define LIBBSD_SYS_POLL_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <sys/poll.h>
|
#include_next <sys/poll.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_POLL_H
|
||||||
|
#define LIBBSD_SYS_POLL_H
|
||||||
|
|
||||||
#ifndef INFTIM
|
#ifndef INFTIM
|
||||||
#define INFTIM (-1)
|
#define INFTIM (-1)
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2008-2011 Guillem Jover
|
* Copyright © 2008-2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -25,18 +25,18 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_UNISTD_H
|
|
||||||
#define LIBBSD_UNISTD_H
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
#ifdef LIBBSD_OVERLAY
|
||||||
#include_next <unistd.h>
|
#include_next <unistd.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_UNISTD_H
|
||||||
|
#define LIBBSD_UNISTD_H
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifndef S_ISTXT
|
#ifndef S_ISTXT
|
||||||
#define S_ISTXT S_ISVTX
|
#define S_ISTXT S_ISVTX
|
||||||
#endif
|
#endif
|
||||||
@@ -49,11 +49,13 @@ extern int optreset;
|
|||||||
#define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr)
|
#define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int bsd_getopt(int, char **, char *);
|
int bsd_getopt(int argc, char * const argv[], const char *shortopts);
|
||||||
|
|
||||||
mode_t getmode(const void *set, mode_t mode);
|
mode_t getmode(const void *set, mode_t mode);
|
||||||
void *setmode(const char *mode_str);
|
void *setmode(const char *mode_str);
|
||||||
|
|
||||||
|
void closefrom(int lowfd);
|
||||||
|
|
||||||
void setproctitle(const char *fmt, ...);
|
void setproctitle(const char *fmt, ...);
|
||||||
|
|
||||||
int getpeereid(int s, uid_t *euid, gid_t *egid);
|
int getpeereid(int s, uid_t *euid, gid_t *egid);
|
||||||
|
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2011 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_LIBUTIL_H
|
|
||||||
#define LIBBSD_LIBUTIL_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/libutil.h> or libbsd-overlay.pc instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/libutil.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <bsd/libutil.h>
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2011 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_DEPRECATED_NLIST_H
|
|
||||||
#define LIBBSD_DEPRECATED_NLIST_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/nlist.h> or libbsd-overlay.pc instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/nlist.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <bsd/nlist.h>
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2011 Guillem Jover
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBBSD_VIS_H
|
|
||||||
#define LIBBSD_VIS_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
|
||||||
#error "Deprecated header, use <bsd/vis.h> or libbsd-overlay.pc instead."
|
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/vis.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <bsd/vis.h>
|
|
||||||
|
|
||||||
#endif
|
|
0
src/.gitignore → man/.gitignore
vendored
0
src/.gitignore → man/.gitignore
vendored
53
man/Makefile.am
Normal file
53
man/Makefile.am
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
mdX.3bsd \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
CLEANFILES = \
|
||||||
|
md5.3bsd \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
|
||||||
|
|
||||||
|
md5.3bsd: $(srcdir)/mdX.3bsd
|
||||||
|
$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
|
||||||
|
|
||||||
|
dist_man_MANS = \
|
||||||
|
arc4random.3 \
|
||||||
|
arc4random_addrandom.3 \
|
||||||
|
arc4random_buf.3 \
|
||||||
|
arc4random_stir.3 \
|
||||||
|
arc4random_uniform.3 \
|
||||||
|
bitstring.3 \
|
||||||
|
closefrom.3 \
|
||||||
|
dehumanize_number.3 \
|
||||||
|
expand_number.3 \
|
||||||
|
fgetln.3 \
|
||||||
|
flopen.3 \
|
||||||
|
fmtcheck.3 \
|
||||||
|
getmode.3 \
|
||||||
|
getpeereid.3 \
|
||||||
|
getprogname.3 \
|
||||||
|
heapsort.3 \
|
||||||
|
humanize_number.3 \
|
||||||
|
md5.3bsd \
|
||||||
|
mergesort.3 \
|
||||||
|
nlist.3 \
|
||||||
|
pidfile.3 \
|
||||||
|
queue.3bsd \
|
||||||
|
radixsort.3 \
|
||||||
|
readpassphrase.3 \
|
||||||
|
reallocf.3 \
|
||||||
|
setmode.3 \
|
||||||
|
setproctitle.3 \
|
||||||
|
setprogname.3 \
|
||||||
|
sradixsort.3 \
|
||||||
|
strlcat.3 \
|
||||||
|
strlcpy.3 \
|
||||||
|
strmode.3 \
|
||||||
|
strtonum.3 \
|
||||||
|
tree.3 \
|
||||||
|
unvis.3 \
|
||||||
|
vis.3 \
|
||||||
|
$(nil)
|
186
man/bitstring.3
Normal file
186
man/bitstring.3
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
.\" Copyright (c) 1989, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Paul Vixie.
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 4. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" @(#)bitstring.3 8.1 (Berkeley) 7/19/93
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd July 19, 1993
|
||||||
|
.Dt BITSTRING 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm bit_alloc ,
|
||||||
|
.Nm bit_clear ,
|
||||||
|
.Nm bit_decl ,
|
||||||
|
.Nm bit_ffs ,
|
||||||
|
.Nm bit_nclear ,
|
||||||
|
.Nm bit_nset ,
|
||||||
|
.Nm bit_set ,
|
||||||
|
.Nm bitstr_size ,
|
||||||
|
.Nm bit_test
|
||||||
|
.Nd bit-string manipulation macros
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/bitstring.h
|
||||||
|
.Ft bitstr_t *
|
||||||
|
.Fn bit_alloc "int nbits"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_decl "bitstr_t *name" "int nbits"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_clear "bitstr_t *name" "int bit"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_ffc "bitstr_t *name" "int nbits" "int *value"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_ffs "bitstr_t *name" "int nbits" "int *value"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_nclear "bitstr_t *name" "int start" "int stop"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_nset "bitstr_t *name" "int start" "int stop"
|
||||||
|
.Ft void
|
||||||
|
.Fn bit_set "bitstr_t *name" "int bit"
|
||||||
|
.Ft int
|
||||||
|
.Fn bitstr_size "int nbits"
|
||||||
|
.Ft int
|
||||||
|
.Fn bit_test "bitstr_t *name" "int bit"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
These macros operate on strings of bits.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
|
.Fn bit_alloc
|
||||||
|
returns a pointer of type
|
||||||
|
.Dq Fa "bitstr_t *"
|
||||||
|
to sufficient space to store
|
||||||
|
.Fa nbits
|
||||||
|
bits, or
|
||||||
|
.Dv NULL
|
||||||
|
if no space is available.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
|
.Fn bit_decl
|
||||||
|
allocates sufficient space to store
|
||||||
|
.Fa nbits
|
||||||
|
bits on the stack.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
|
.Fn bitstr_size
|
||||||
|
returns the number of elements of type
|
||||||
|
.Fa bitstr_t
|
||||||
|
necessary to store
|
||||||
|
.Fa nbits
|
||||||
|
bits.
|
||||||
|
This is useful for copying bit strings.
|
||||||
|
.Pp
|
||||||
|
The macros
|
||||||
|
.Fn bit_clear
|
||||||
|
and
|
||||||
|
.Fn bit_set
|
||||||
|
clear or set the zero-based numbered bit
|
||||||
|
.Fa bit ,
|
||||||
|
in the bit string
|
||||||
|
.Ar name .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn bit_nset
|
||||||
|
and
|
||||||
|
.Fn bit_nclear
|
||||||
|
macros
|
||||||
|
set or clear the zero-based numbered bits from
|
||||||
|
.Fa start
|
||||||
|
through
|
||||||
|
.Fa stop
|
||||||
|
in the bit string
|
||||||
|
.Ar name .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn bit_test
|
||||||
|
macro
|
||||||
|
evaluates to non-zero if the zero-based numbered bit
|
||||||
|
.Fa bit
|
||||||
|
of bit string
|
||||||
|
.Fa name
|
||||||
|
is set, and zero otherwise.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn bit_ffs
|
||||||
|
macro
|
||||||
|
stores in the location referenced by
|
||||||
|
.Fa value
|
||||||
|
the zero-based number of the first bit set in the array of
|
||||||
|
.Fa nbits
|
||||||
|
bits referenced by
|
||||||
|
.Fa name .
|
||||||
|
If no bits are set, the location referenced by
|
||||||
|
.Fa value
|
||||||
|
is set to \-1.
|
||||||
|
.Pp
|
||||||
|
The macro
|
||||||
|
.Fn bit_ffc
|
||||||
|
stores in the location referenced by
|
||||||
|
.Fa value
|
||||||
|
the zero-based number of the first bit not set in the array of
|
||||||
|
.Fa nbits
|
||||||
|
bits referenced by
|
||||||
|
.Fa name .
|
||||||
|
If all bits are set, the location referenced by
|
||||||
|
.Fa value
|
||||||
|
is set to \-1.
|
||||||
|
.Pp
|
||||||
|
The arguments to these macros are evaluated only once and may safely
|
||||||
|
have side effects.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
#include <limits.h>
|
||||||
|
#include <bsd/bitstring.h>
|
||||||
|
|
||||||
|
\&...
|
||||||
|
#define LPR_BUSY_BIT 0
|
||||||
|
#define LPR_FORMAT_BIT 1
|
||||||
|
#define LPR_DOWNLOAD_BIT 2
|
||||||
|
\&...
|
||||||
|
#define LPR_AVAILABLE_BIT 9
|
||||||
|
#define LPR_MAX_BITS 10
|
||||||
|
|
||||||
|
make_lpr_available()
|
||||||
|
{
|
||||||
|
bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
|
||||||
|
...
|
||||||
|
bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
|
||||||
|
...
|
||||||
|
if (!bit_test(bitlist, LPR_BUSY_BIT)) {
|
||||||
|
bit_clear(bitlist, LPR_FORMAT_BIT);
|
||||||
|
bit_clear(bitlist, LPR_DOWNLOAD_BIT);
|
||||||
|
bit_set(bitlist, LPR_AVAILABLE_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.Ed
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr malloc 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Nm bitstring
|
||||||
|
functions first appeared in
|
||||||
|
.Bx 4.4 .
|
54
man/closefrom.3
Normal file
54
man/closefrom.3
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
.\" Copyright (c) 2009 Advanced Computing Technologies LLC
|
||||||
|
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd June 12, 2009
|
||||||
|
.Dt CLOSEFROM 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm closefrom
|
||||||
|
.Nd delete open file descriptors
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/unistd.h
|
||||||
|
.Ft void
|
||||||
|
.Fn closefrom "int lowfd"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn closefrom
|
||||||
|
system call deletes all open file descriptors greater than or equal to
|
||||||
|
.Fa lowfd
|
||||||
|
from the per-process object reference table.
|
||||||
|
Any errors encountered while closing file descriptors are ignored.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr close 2
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn closefrom
|
||||||
|
function first appeared in
|
||||||
|
.Fx 8.0 .
|
87
man/expand_number.3
Normal file
87
man/expand_number.3
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
.\" Copyright (c) 2007 Eric Anderson <anderson@FreeBSD.org>
|
||||||
|
.\" Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd August 15, 2010
|
||||||
|
.Dt EXPAND_NUMBER 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm expand_number
|
||||||
|
.Nd format a number from human readable form
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/libutil.h
|
||||||
|
.Ft int
|
||||||
|
.Fo expand_number
|
||||||
|
.Fa "const char *buf" "uint64_t *num"
|
||||||
|
.Fc
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn expand_number
|
||||||
|
function unformats the
|
||||||
|
.Fa buf
|
||||||
|
string and stores a unsigned 64-bit quantity at address pointed out by the
|
||||||
|
.Fa num
|
||||||
|
argument.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn expand_number
|
||||||
|
function
|
||||||
|
follows the SI power of two convention.
|
||||||
|
.Pp
|
||||||
|
The prefixes are:
|
||||||
|
.Bl -column "Prefix" "Description" "1000000000000000000" -offset indent
|
||||||
|
.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
|
||||||
|
.It Li k Ta No kilo Ta 1024
|
||||||
|
.It Li M Ta No mega Ta 1048576
|
||||||
|
.It Li G Ta No giga Ta 1073741824
|
||||||
|
.It Li T Ta No tera Ta 1099511627776
|
||||||
|
.It Li P Ta No peta Ta 1125899906842624
|
||||||
|
.It Li E Ta No exa Ta 1152921504606846976
|
||||||
|
.El
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
.Rv -std
|
||||||
|
.Sh ERRORS
|
||||||
|
The
|
||||||
|
.Fn expand_number
|
||||||
|
function will fail if:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The given string contains no digits.
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
An unrecognized prefix was given.
|
||||||
|
.It Bq Er ERANGE
|
||||||
|
Result doesn't fit into 64 bits.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr humanize_number 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn expand_number
|
||||||
|
function first appeared in
|
||||||
|
.Fx 6.3 .
|
@@ -1,5 +1,5 @@
|
|||||||
.\"-
|
.\"-
|
||||||
.\" Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
|
.\" Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm flopen
|
.Nm flopen
|
||||||
.Nd "Reliably open and lock a file"
|
.Nd reliably open and lock a file
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
@@ -84,7 +84,7 @@ includes
|
|||||||
If successful,
|
If successful,
|
||||||
.Fn flopen
|
.Fn flopen
|
||||||
returns a valid file descriptor.
|
returns a valid file descriptor.
|
||||||
Otherwise, it returns -1, and sets
|
Otherwise, it returns \-1, and sets
|
||||||
.Va errno
|
.Va errno
|
||||||
as described in
|
as described in
|
||||||
.Xr flock 2
|
.Xr flock 2
|
95
man/getprogname.3
Normal file
95
man/getprogname.3
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
.\"
|
||||||
|
.\" Copyright (c) 2001 Christopher G. Demetriou
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||||||
|
.\" must display the following acknowledgement:
|
||||||
|
.\" This product includes software developed for the
|
||||||
|
.\" NetBSD Project. See http://www.netbsd.org/ for
|
||||||
|
.\" information about NetBSD.
|
||||||
|
.\" 4. The name of the author may not be used to endorse or promote products
|
||||||
|
.\" derived from this software without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd May 1, 2001
|
||||||
|
.Dt GETPROGNAME 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm getprogname ,
|
||||||
|
.Nm setprogname
|
||||||
|
.Nd get or set the program name
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdlib.h
|
||||||
|
.Ft const char *
|
||||||
|
.Fn getprogname "void"
|
||||||
|
.Ft void
|
||||||
|
.Fn setprogname "const char *progname"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn getprogname
|
||||||
|
and
|
||||||
|
.Fn setprogname
|
||||||
|
functions manipulate the name of the current program.
|
||||||
|
They are used by error-reporting routines to produce
|
||||||
|
consistent output.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn getprogname
|
||||||
|
function returns the name of the program.
|
||||||
|
If the name has not been set yet, it will return
|
||||||
|
.Dv NULL .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn setprogname
|
||||||
|
function sets the name of the program to be the last component of the
|
||||||
|
.Fa progname
|
||||||
|
argument.
|
||||||
|
Since a pointer to the given string is kept as the program name,
|
||||||
|
it should not be modified for the rest of the program's lifetime.
|
||||||
|
.Pp
|
||||||
|
In
|
||||||
|
.Fx ,
|
||||||
|
the name of the program is set by the start-up code that is run before
|
||||||
|
.Fn main ;
|
||||||
|
thus,
|
||||||
|
running
|
||||||
|
.Fn setprogname
|
||||||
|
is not necessary.
|
||||||
|
Programs that desire maximum portability should still call it;
|
||||||
|
on another operating system,
|
||||||
|
these functions may be implemented in a portability library.
|
||||||
|
Calling
|
||||||
|
.Fn setprogname
|
||||||
|
allows the aforementioned library to learn the program name without
|
||||||
|
modifications to the start-up code.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr err 3 ,
|
||||||
|
.Xr setproctitle 3
|
||||||
|
.Sh HISTORY
|
||||||
|
These functions first appeared in
|
||||||
|
.Nx 1.6 ,
|
||||||
|
and made their way into
|
||||||
|
.Fx 4.4 .
|
@@ -10,7 +10,7 @@
|
|||||||
.\" $OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
|
.\" $OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 29, 2004
|
.Dd April 29, 2004
|
||||||
.Dt MDX 3
|
.Dt MDX 3bsd
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm MDXInit ,
|
.Nm MDXInit ,
|
@@ -32,7 +32,7 @@
|
|||||||
.Nm pidfile_write ,
|
.Nm pidfile_write ,
|
||||||
.Nm pidfile_close ,
|
.Nm pidfile_close ,
|
||||||
.Nm pidfile_remove
|
.Nm pidfile_remove
|
||||||
.Nd "library for PID files handling"
|
.Nd library for PID files handling
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
@@ -126,7 +126,7 @@ if (pfh == NULL) {
|
|||||||
warn("Cannot open or create pidfile");
|
warn("Cannot open or create pidfile");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (daemon(0, 0) == -1) {
|
if (daemon(0, 0) == \-1) {
|
||||||
warn("Cannot daemonize");
|
warn("Cannot daemonize");
|
||||||
pidfile_remove(pfh);
|
pidfile_remove(pfh);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -138,7 +138,7 @@ for (;;) {
|
|||||||
/* Do work. */
|
/* Do work. */
|
||||||
childpid = fork();
|
childpid = fork();
|
||||||
switch (childpid) {
|
switch (childpid) {
|
||||||
case -1:
|
case \-1:
|
||||||
syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno));
|
syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno));
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
1040
man/queue.3bsd
Normal file
1040
man/queue.3bsd
Normal file
File diff suppressed because it is too large
Load Diff
124
man/setproctitle.3
Normal file
124
man/setproctitle.3
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
.\" Copyright (c) 1995 Peter Wemm <peter@FreeBSD.org>
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, is permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice immediately at the beginning of the file, without modification,
|
||||||
|
.\" this list of conditions, and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. This work was done expressly for inclusion into FreeBSD. Other use
|
||||||
|
.\" is permitted provided this notation is included.
|
||||||
|
.\" 4. Absolutely no warranty of function or purpose is made by the author
|
||||||
|
.\" Peter Wemm.
|
||||||
|
.\" 5. Modifications may be freely made to this file providing the above
|
||||||
|
.\" conditions are met.
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.\" The following requests are required for all man pages.
|
||||||
|
.Dd December 16, 1995
|
||||||
|
.Dt SETPROCTITLE 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm setproctitle
|
||||||
|
.Nd set process title
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In sys/types.h
|
||||||
|
.In bsd/unistd.h
|
||||||
|
.Ft void
|
||||||
|
.Fn setproctitle "const char *fmt" "..."
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn setproctitle
|
||||||
|
library routine sets the process title that appears on the
|
||||||
|
.Xr ps 1
|
||||||
|
command.
|
||||||
|
.Pp
|
||||||
|
The title is set from the executable's name, followed by the
|
||||||
|
result of a
|
||||||
|
.Xr printf 3
|
||||||
|
style expansion of the arguments as specified by the
|
||||||
|
.Va fmt
|
||||||
|
argument.
|
||||||
|
If the
|
||||||
|
.Va fmt
|
||||||
|
argument begins with a
|
||||||
|
.Dq -
|
||||||
|
character, the executable's name is skipped.
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Va fmt
|
||||||
|
is NULL, the process title is restored.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
To set the title on a daemon to indicate its activity:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
setproctitle("talking to %s", inet_ntoa(addr));
|
||||||
|
.Ed
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr ps 1 ,
|
||||||
|
.Xr w 1 ,
|
||||||
|
.Xr kvm 3 ,
|
||||||
|
.Xr kvm_getargv 3 ,
|
||||||
|
.Xr printf 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn setproctitle
|
||||||
|
function
|
||||||
|
is implicitly non-standard.
|
||||||
|
Other methods of causing the
|
||||||
|
.Xr ps 1
|
||||||
|
command line to change, including copying over the argv[0] string are
|
||||||
|
also implicitly non-portable.
|
||||||
|
It is preferable to use an operating system
|
||||||
|
supplied
|
||||||
|
.Fn setproctitle
|
||||||
|
if present.
|
||||||
|
.Pp
|
||||||
|
Unfortunately, it is possible that there are other calling conventions
|
||||||
|
to other versions of
|
||||||
|
.Fn setproctitle ,
|
||||||
|
although none have been found by the author as yet.
|
||||||
|
This is believed to be
|
||||||
|
the predominant convention.
|
||||||
|
.Pp
|
||||||
|
It is thought that the implementation is compatible with other systems,
|
||||||
|
including
|
||||||
|
.Nx
|
||||||
|
and
|
||||||
|
.Bsx .
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn setproctitle
|
||||||
|
function
|
||||||
|
first appeared in
|
||||||
|
.Fx 2.2 .
|
||||||
|
Other operating systems have
|
||||||
|
similar functions.
|
||||||
|
.Sh AUTHORS
|
||||||
|
.An -nosplit
|
||||||
|
.An Peter Wemm Aq peter@FreeBSD.org
|
||||||
|
stole the idea from the
|
||||||
|
.Sy "Sendmail 8.7.3"
|
||||||
|
source code by
|
||||||
|
.An Eric Allman Aq eric@sendmail.org .
|
||||||
|
.Sh BUGS
|
||||||
|
Never pass a string with user-supplied data as a format without using
|
||||||
|
.Ql %s .
|
||||||
|
An attacker can put format specifiers in the string to mangle your stack,
|
||||||
|
leading to a possible security hole.
|
||||||
|
This holds true even if the string was built using a function like
|
||||||
|
.Fn snprintf ,
|
||||||
|
as the resulting string may still contain user-supplied conversion specifiers
|
||||||
|
for later interpolation by
|
||||||
|
.Fn setproctitle .
|
||||||
|
.Pp
|
||||||
|
Always use the proper secure idiom:
|
||||||
|
.Pp
|
||||||
|
.Dl setproctitle("%s", string);
|
1
man/setprogname.3
Normal file
1
man/setprogname.3
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/getprogname.3
|
@@ -20,7 +20,7 @@
|
|||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm strtonum
|
.Nm strtonum
|
||||||
.Nd "reliably convert string value to an integer"
|
.Nd reliably convert string value to an integer
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
504
man/tree.3
Normal file
504
man/tree.3
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
.\" $OpenBSD: tree.3,v 1.7 2002/06/12 01:09:20 provos Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||||||
|
.\" must display the following acknowledgement:
|
||||||
|
.\" This product includes software developed by Niels Provos.
|
||||||
|
.\" 4. The name of the author may not be used to endorse or promote products
|
||||||
|
.\" derived from this software without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd December 27, 2007
|
||||||
|
.Dt TREE 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm SPLAY_PROTOTYPE ,
|
||||||
|
.Nm SPLAY_GENERATE ,
|
||||||
|
.Nm SPLAY_ENTRY ,
|
||||||
|
.Nm SPLAY_HEAD ,
|
||||||
|
.Nm SPLAY_INITIALIZER ,
|
||||||
|
.Nm SPLAY_ROOT ,
|
||||||
|
.Nm SPLAY_EMPTY ,
|
||||||
|
.Nm SPLAY_NEXT ,
|
||||||
|
.Nm SPLAY_MIN ,
|
||||||
|
.Nm SPLAY_MAX ,
|
||||||
|
.Nm SPLAY_FIND ,
|
||||||
|
.Nm SPLAY_LEFT ,
|
||||||
|
.Nm SPLAY_RIGHT ,
|
||||||
|
.Nm SPLAY_FOREACH ,
|
||||||
|
.Nm SPLAY_INIT ,
|
||||||
|
.Nm SPLAY_INSERT ,
|
||||||
|
.Nm SPLAY_REMOVE ,
|
||||||
|
.Nm RB_PROTOTYPE ,
|
||||||
|
.Nm RB_PROTOTYPE_STATIC ,
|
||||||
|
.Nm RB_GENERATE ,
|
||||||
|
.Nm RB_GENERATE_STATIC ,
|
||||||
|
.Nm RB_ENTRY ,
|
||||||
|
.Nm RB_HEAD ,
|
||||||
|
.Nm RB_INITIALIZER ,
|
||||||
|
.Nm RB_ROOT ,
|
||||||
|
.Nm RB_EMPTY ,
|
||||||
|
.Nm RB_NEXT ,
|
||||||
|
.Nm RB_PREV ,
|
||||||
|
.Nm RB_MIN ,
|
||||||
|
.Nm RB_MAX ,
|
||||||
|
.Nm RB_FIND ,
|
||||||
|
.Nm RB_NFIND ,
|
||||||
|
.Nm RB_LEFT ,
|
||||||
|
.Nm RB_RIGHT ,
|
||||||
|
.Nm RB_PARENT ,
|
||||||
|
.Nm RB_FOREACH ,
|
||||||
|
.Nm RB_FOREACH_REVERSE ,
|
||||||
|
.Nm RB_INIT ,
|
||||||
|
.Nm RB_INSERT ,
|
||||||
|
.Nm RB_REMOVE
|
||||||
|
.Nd implementations of splay and red-black trees
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/sys/tree.h
|
||||||
|
.Fn SPLAY_PROTOTYPE NAME TYPE FIELD CMP
|
||||||
|
.Fn SPLAY_GENERATE NAME TYPE FIELD CMP
|
||||||
|
.Fn SPLAY_ENTRY TYPE
|
||||||
|
.Fn SPLAY_HEAD HEADNAME TYPE
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_INITIALIZER "SPLAY_HEAD *head"
|
||||||
|
.Fn SPLAY_ROOT "SPLAY_HEAD *head"
|
||||||
|
.Ft bool
|
||||||
|
.Fn SPLAY_EMPTY "SPLAY_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_NEXT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_MIN NAME "SPLAY_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_MAX NAME "SPLAY_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_FIND NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME"
|
||||||
|
.Fn SPLAY_FOREACH VARNAME NAME "SPLAY_HEAD *head"
|
||||||
|
.Ft void
|
||||||
|
.Fn SPLAY_INIT "SPLAY_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_INSERT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn SPLAY_REMOVE NAME "SPLAY_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Fn RB_PROTOTYPE NAME TYPE FIELD CMP
|
||||||
|
.Fn RB_PROTOTYPE_STATIC NAME TYPE FIELD CMP
|
||||||
|
.Fn RB_GENERATE NAME TYPE FIELD CMP
|
||||||
|
.Fn RB_GENERATE_STATIC NAME TYPE FIELD CMP
|
||||||
|
.Fn RB_ENTRY TYPE
|
||||||
|
.Fn RB_HEAD HEADNAME TYPE
|
||||||
|
.Fn RB_INITIALIZER "RB_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_ROOT "RB_HEAD *head"
|
||||||
|
.Ft "bool"
|
||||||
|
.Fn RB_EMPTY "RB_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_NEXT NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_PREV NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_MIN NAME "RB_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_MAX NAME "RB_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_FIND NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_NFIND NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME"
|
||||||
|
.Fn RB_FOREACH VARNAME NAME "RB_HEAD *head"
|
||||||
|
.Fn RB_FOREACH_REVERSE VARNAME NAME "RB_HEAD *head"
|
||||||
|
.Ft void
|
||||||
|
.Fn RB_INIT "RB_HEAD *head"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_INSERT NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Ft "struct TYPE *"
|
||||||
|
.Fn RB_REMOVE NAME "RB_HEAD *head" "struct TYPE *elm"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
These macros define data structures for different types of trees:
|
||||||
|
splay trees and red-black trees.
|
||||||
|
.Pp
|
||||||
|
In the macro definitions,
|
||||||
|
.Fa TYPE
|
||||||
|
is the name tag of a user defined structure that must contain a field of type
|
||||||
|
.Vt SPLAY_ENTRY ,
|
||||||
|
or
|
||||||
|
.Vt RB_ENTRY ,
|
||||||
|
named
|
||||||
|
.Fa ENTRYNAME .
|
||||||
|
The argument
|
||||||
|
.Fa HEADNAME
|
||||||
|
is the name tag of a user defined structure that must be declared
|
||||||
|
using the macros
|
||||||
|
.Fn SPLAY_HEAD ,
|
||||||
|
or
|
||||||
|
.Fn RB_HEAD .
|
||||||
|
The argument
|
||||||
|
.Fa NAME
|
||||||
|
has to be a unique name prefix for every tree that is defined.
|
||||||
|
.Pp
|
||||||
|
The function prototypes are declared with
|
||||||
|
.Fn SPLAY_PROTOTYPE ,
|
||||||
|
.Fn RB_PROTOTYPE ,
|
||||||
|
or
|
||||||
|
.Fn RB_PROTOTYPE_STATIC .
|
||||||
|
The function bodies are generated with
|
||||||
|
.Fn SPLAY_GENERATE ,
|
||||||
|
.Fn RB_GENERATE ,
|
||||||
|
or
|
||||||
|
.Fn RB_GENERATE_STATIC .
|
||||||
|
See the examples below for further explanation of how these macros are used.
|
||||||
|
.Sh SPLAY TREES
|
||||||
|
A splay tree is a self-organizing data structure.
|
||||||
|
Every operation on the tree causes a splay to happen.
|
||||||
|
The splay moves the requested
|
||||||
|
node to the root of the tree and partly rebalances it.
|
||||||
|
.Pp
|
||||||
|
This has the benefit that request locality causes faster lookups as
|
||||||
|
the requested nodes move to the top of the tree.
|
||||||
|
On the other hand, every lookup causes memory writes.
|
||||||
|
.Pp
|
||||||
|
The Balance Theorem bounds the total access time for
|
||||||
|
.Ar m
|
||||||
|
operations and
|
||||||
|
.Ar n
|
||||||
|
inserts on an initially empty tree as
|
||||||
|
.Fn O "\*[lp]m + n\*[rp]lg n" .
|
||||||
|
The
|
||||||
|
amortized cost for a sequence of
|
||||||
|
.Ar m
|
||||||
|
accesses to a splay tree is
|
||||||
|
.Fn O "lg n" .
|
||||||
|
.Pp
|
||||||
|
A splay tree is headed by a structure defined by the
|
||||||
|
.Fn SPLAY_HEAD
|
||||||
|
macro.
|
||||||
|
A
|
||||||
|
structure is declared as follows:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn SPLAY_HEAD HEADNAME TYPE
|
||||||
|
.Va head ;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
where
|
||||||
|
.Fa HEADNAME
|
||||||
|
is the name of the structure to be defined, and struct
|
||||||
|
.Fa TYPE
|
||||||
|
is the type of the elements to be inserted into the tree.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_ENTRY
|
||||||
|
macro declares a structure that allows elements to be connected in the tree.
|
||||||
|
.Pp
|
||||||
|
In order to use the functions that manipulate the tree structure,
|
||||||
|
their prototypes need to be declared with the
|
||||||
|
.Fn SPLAY_PROTOTYPE
|
||||||
|
macro,
|
||||||
|
where
|
||||||
|
.Fa NAME
|
||||||
|
is a unique identifier for this particular tree.
|
||||||
|
The
|
||||||
|
.Fa TYPE
|
||||||
|
argument is the type of the structure that is being managed
|
||||||
|
by the tree.
|
||||||
|
The
|
||||||
|
.Fa FIELD
|
||||||
|
argument is the name of the element defined by
|
||||||
|
.Fn SPLAY_ENTRY .
|
||||||
|
.Pp
|
||||||
|
The function bodies are generated with the
|
||||||
|
.Fn SPLAY_GENERATE
|
||||||
|
macro.
|
||||||
|
It takes the same arguments as the
|
||||||
|
.Fn SPLAY_PROTOTYPE
|
||||||
|
macro, but should be used only once.
|
||||||
|
.Pp
|
||||||
|
Finally,
|
||||||
|
the
|
||||||
|
.Fa CMP
|
||||||
|
argument is the name of a function used to compare tree nodes
|
||||||
|
with each other.
|
||||||
|
The function takes two arguments of type
|
||||||
|
.Vt "struct TYPE *" .
|
||||||
|
If the first argument is smaller than the second, the function returns a
|
||||||
|
value smaller than zero.
|
||||||
|
If they are equal, the function returns zero.
|
||||||
|
Otherwise, it should return a value greater than zero.
|
||||||
|
The compare
|
||||||
|
function defines the order of the tree elements.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_INIT
|
||||||
|
macro initializes the tree referenced by
|
||||||
|
.Fa head .
|
||||||
|
.Pp
|
||||||
|
The splay tree can also be initialized statically by using the
|
||||||
|
.Fn SPLAY_INITIALIZER
|
||||||
|
macro like this:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn SPLAY_HEAD HEADNAME TYPE
|
||||||
|
.Va head
|
||||||
|
=
|
||||||
|
.Fn SPLAY_INITIALIZER &head ;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_INSERT
|
||||||
|
macro inserts the new element
|
||||||
|
.Fa elm
|
||||||
|
into the tree.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_REMOVE
|
||||||
|
macro removes the element
|
||||||
|
.Fa elm
|
||||||
|
from the tree pointed by
|
||||||
|
.Fa head .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_FIND
|
||||||
|
macro can be used to find a particular element in the tree.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
struct TYPE find, *res;
|
||||||
|
find.key = 30;
|
||||||
|
res = SPLAY_FIND(NAME, head, &find);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_ROOT ,
|
||||||
|
.Fn SPLAY_MIN ,
|
||||||
|
.Fn SPLAY_MAX ,
|
||||||
|
and
|
||||||
|
.Fn SPLAY_NEXT
|
||||||
|
macros can be used to traverse the tree:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
for (np = SPLAY_MIN(NAME, &head); np != NULL; np = SPLAY_NEXT(NAME, &head, np))
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Or, for simplicity, one can use the
|
||||||
|
.Fn SPLAY_FOREACH
|
||||||
|
macro:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn SPLAY_FOREACH np NAME head
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn SPLAY_EMPTY
|
||||||
|
macro should be used to check whether a splay tree is empty.
|
||||||
|
.Sh RED-BLACK TREES
|
||||||
|
A red-black tree is a binary search tree with the node color as an
|
||||||
|
extra attribute.
|
||||||
|
It fulfills a set of conditions:
|
||||||
|
.Bl -enum -offset indent
|
||||||
|
.It
|
||||||
|
Every search path from the root to a leaf consists of the same number of
|
||||||
|
black nodes.
|
||||||
|
.It
|
||||||
|
Each red node (except for the root) has a black parent.
|
||||||
|
.It
|
||||||
|
Each leaf node is black.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
Every operation on a red-black tree is bounded as
|
||||||
|
.Fn O "lg n" .
|
||||||
|
The maximum height of a red-black tree is
|
||||||
|
.Fn 2lg "n + 1" .
|
||||||
|
.Pp
|
||||||
|
A red-black tree is headed by a structure defined by the
|
||||||
|
.Fn RB_HEAD
|
||||||
|
macro.
|
||||||
|
A
|
||||||
|
structure is declared as follows:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn RB_HEAD HEADNAME TYPE
|
||||||
|
.Va head ;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
where
|
||||||
|
.Fa HEADNAME
|
||||||
|
is the name of the structure to be defined, and struct
|
||||||
|
.Fa TYPE
|
||||||
|
is the type of the elements to be inserted into the tree.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_ENTRY
|
||||||
|
macro declares a structure that allows elements to be connected in the tree.
|
||||||
|
.Pp
|
||||||
|
In order to use the functions that manipulate the tree structure,
|
||||||
|
their prototypes need to be declared with the
|
||||||
|
.Fn RB_PROTOTYPE
|
||||||
|
or
|
||||||
|
.Fn RB_PROTOTYPE_STATIC
|
||||||
|
macro,
|
||||||
|
where
|
||||||
|
.Fa NAME
|
||||||
|
is a unique identifier for this particular tree.
|
||||||
|
The
|
||||||
|
.Fa TYPE
|
||||||
|
argument is the type of the structure that is being managed
|
||||||
|
by the tree.
|
||||||
|
The
|
||||||
|
.Fa FIELD
|
||||||
|
argument is the name of the element defined by
|
||||||
|
.Fn RB_ENTRY .
|
||||||
|
.Pp
|
||||||
|
The function bodies are generated with the
|
||||||
|
.Fn RB_GENERATE
|
||||||
|
or
|
||||||
|
.Fn RB_GENERATE_STATIC
|
||||||
|
macro.
|
||||||
|
These macros take the same arguments as the
|
||||||
|
.Fn RB_PROTOTYPE
|
||||||
|
and
|
||||||
|
.Fn RB_PROTOTYPE_STATIC
|
||||||
|
macros, but should be used only once.
|
||||||
|
.Pp
|
||||||
|
Finally,
|
||||||
|
the
|
||||||
|
.Fa CMP
|
||||||
|
argument is the name of a function used to compare tree nodes
|
||||||
|
with each other.
|
||||||
|
The function takes two arguments of type
|
||||||
|
.Vt "struct TYPE *" .
|
||||||
|
If the first argument is smaller than the second, the function returns a
|
||||||
|
value smaller than zero.
|
||||||
|
If they are equal, the function returns zero.
|
||||||
|
Otherwise, it should return a value greater than zero.
|
||||||
|
The compare
|
||||||
|
function defines the order of the tree elements.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_INIT
|
||||||
|
macro initializes the tree referenced by
|
||||||
|
.Fa head .
|
||||||
|
.Pp
|
||||||
|
The red-black tree can also be initialized statically by using the
|
||||||
|
.Fn RB_INITIALIZER
|
||||||
|
macro like this:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn RB_HEAD HEADNAME TYPE
|
||||||
|
.Va head
|
||||||
|
=
|
||||||
|
.Fn RB_INITIALIZER &head ;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_INSERT
|
||||||
|
macro inserts the new element
|
||||||
|
.Fa elm
|
||||||
|
into the tree.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_REMOVE
|
||||||
|
macro removes the element
|
||||||
|
.Fa elm
|
||||||
|
from the tree pointed by
|
||||||
|
.Fa head .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_FIND
|
||||||
|
and
|
||||||
|
.Fn RB_NFIND
|
||||||
|
macros can be used to find a particular element in the tree.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
struct TYPE find, *res;
|
||||||
|
find.key = 30;
|
||||||
|
res = RB_FIND(NAME, head, &find);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_ROOT ,
|
||||||
|
.Fn RB_MIN ,
|
||||||
|
.Fn RB_MAX ,
|
||||||
|
.Fn RB_NEXT ,
|
||||||
|
and
|
||||||
|
.Fn RB_PREV
|
||||||
|
macros can be used to traverse the tree:
|
||||||
|
.Pp
|
||||||
|
.Dl "for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))"
|
||||||
|
.Pp
|
||||||
|
Or, for simplicity, one can use the
|
||||||
|
.Fn RB_FOREACH
|
||||||
|
or
|
||||||
|
.Fn RB_FOREACH_REVERSE
|
||||||
|
macro:
|
||||||
|
.Bd -ragged -offset indent
|
||||||
|
.Fn RB_FOREACH np NAME head
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn RB_EMPTY
|
||||||
|
macro should be used to check whether a red-black tree is empty.
|
||||||
|
.Sh NOTES
|
||||||
|
Trying to free a tree in the following way is a common error:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
SPLAY_FOREACH(var, NAME, head) {
|
||||||
|
SPLAY_REMOVE(NAME, head, var);
|
||||||
|
free(var);
|
||||||
|
}
|
||||||
|
free(head);
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Since
|
||||||
|
.Va var
|
||||||
|
is freed, the
|
||||||
|
.Fn FOREACH
|
||||||
|
macro refers to a pointer that may have been reallocated already.
|
||||||
|
Proper code needs a second variable.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) {
|
||||||
|
nxt = SPLAY_NEXT(NAME, head, var);
|
||||||
|
SPLAY_REMOVE(NAME, head, var);
|
||||||
|
free(var);
|
||||||
|
}
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
Both
|
||||||
|
.Fn RB_INSERT
|
||||||
|
and
|
||||||
|
.Fn SPLAY_INSERT
|
||||||
|
return
|
||||||
|
.Dv NULL
|
||||||
|
if the element was inserted in the tree successfully, otherwise they
|
||||||
|
return a pointer to the element with the colliding key.
|
||||||
|
.Pp
|
||||||
|
Accordingly,
|
||||||
|
.Fn RB_REMOVE
|
||||||
|
and
|
||||||
|
.Fn SPLAY_REMOVE
|
||||||
|
return the pointer to the removed element otherwise they return
|
||||||
|
.Dv NULL
|
||||||
|
to indicate an error.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr queue 3
|
||||||
|
.Sh AUTHORS
|
||||||
|
The author of the tree macros is
|
||||||
|
.An Niels Provos .
|
87
src/Makefile.am
Normal file
87
src/Makefile.am
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
AM_CPPFLAGS = \
|
||||||
|
-I$(top_builddir) \
|
||||||
|
-isystem $(top_srcdir)/include/bsd/ \
|
||||||
|
-include $(top_builddir)/config.h \
|
||||||
|
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
||||||
|
-D__REENTRANT
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
libbsd.map \
|
||||||
|
libbsd.pc.in \
|
||||||
|
libbsd-overlay.pc.in \
|
||||||
|
hash/helper.c \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
CLEANFILES = \
|
||||||
|
hash/md5hl.c \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
|
pkgconfig_DATA = \
|
||||||
|
libbsd.pc \
|
||||||
|
libbsd-overlay.pc \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
lib_LTLIBRARIES = libbsd.la
|
||||||
|
|
||||||
|
hash/md5hl.c: $(srcdir)/hash/helper.c
|
||||||
|
$(MKDIR_P) hash
|
||||||
|
$(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
|
||||||
|
|
||||||
|
libbsd_la_DEPENDENCIES = \
|
||||||
|
libbsd.map
|
||||||
|
libbsd_la_LDFLAGS = \
|
||||||
|
-Wl,--version-script=$(srcdir)/libbsd.map \
|
||||||
|
-version-number 0:4:2
|
||||||
|
libbsd_la_SOURCES = \
|
||||||
|
arc4random.c \
|
||||||
|
bsd_getopt.c \
|
||||||
|
closefrom.c \
|
||||||
|
dehumanize_number.c \
|
||||||
|
err.c \
|
||||||
|
expand_number.c \
|
||||||
|
fgetln.c \
|
||||||
|
flopen.c \
|
||||||
|
fmtcheck.c \
|
||||||
|
fpurge.c \
|
||||||
|
getpeereid.c \
|
||||||
|
hash/md5.c \
|
||||||
|
hash/md5hl.c \
|
||||||
|
heapsort.c \
|
||||||
|
humanize_number.c \
|
||||||
|
inet_net_pton.c \
|
||||||
|
local-elf.h \
|
||||||
|
merge.c \
|
||||||
|
nlist.c \
|
||||||
|
pidfile.c \
|
||||||
|
progname.c \
|
||||||
|
radixsort.c \
|
||||||
|
readpassphrase.c \
|
||||||
|
reallocf.c \
|
||||||
|
setmode.c \
|
||||||
|
setproctitle.c \
|
||||||
|
strlcat.c \
|
||||||
|
strlcpy.c \
|
||||||
|
strmode.c \
|
||||||
|
strtonum.c \
|
||||||
|
unvis.c \
|
||||||
|
vis.c \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
runtimelibdir = $(libdir)
|
||||||
|
|
||||||
|
install-exec-hook:
|
||||||
|
if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
|
||||||
|
$(MKDIR_P) $(DESTDIR)$(runtimelibdir); \
|
||||||
|
mv $(DESTDIR)$(libdir)/libbsd*.so.* \
|
||||||
|
$(DESTDIR)$(runtimelibdir)/; \
|
||||||
|
soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
|
||||||
|
sorelprefix=`echo $(libdir) | sed -r -e 's:(^/)?[^/]+:..:g'`; \
|
||||||
|
ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
|
||||||
|
$(DESTDIR)$(libdir)/libbsd.so; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
uninstall-hook:
|
||||||
|
rm -f $(DESTDIR)$(runtimelibdir)/libbsd*.so*
|
@@ -29,7 +29,7 @@
|
|||||||
int optreset = 0;
|
int optreset = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
bsd_getopt(int argc, char **argv, char *shortopts)
|
bsd_getopt(int argc, char * const argv[], const char *shortopts)
|
||||||
{
|
{
|
||||||
if (optreset == 1) {
|
if (optreset == 1) {
|
||||||
optreset = 0;
|
optreset = 0;
|
||||||
|
122
src/closefrom.c
Normal file
122
src/closefrom.c
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004-2005, 2007, 2010
|
||||||
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <stddef.h>
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_STDLIB_H
|
||||||
|
# include <stdlib.h>
|
||||||
|
# endif
|
||||||
|
#endif /* STDC_HEADERS */
|
||||||
|
#include <fcntl.h>
|
||||||
|
#ifdef HAVE_DIRENT_H
|
||||||
|
# include <dirent.h>
|
||||||
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#else
|
||||||
|
# define dirent direct
|
||||||
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
# ifdef HAVE_SYS_NDIR_H
|
||||||
|
# include <sys/ndir.h>
|
||||||
|
# endif
|
||||||
|
# ifdef HAVE_SYS_DIR_H
|
||||||
|
# include <sys/dir.h>
|
||||||
|
# endif
|
||||||
|
# ifdef HAVE_NDIR_H
|
||||||
|
# include <ndir.h>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OPEN_MAX
|
||||||
|
# define OPEN_MAX 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FCNTL_CLOSEM
|
||||||
|
# ifndef HAVE_DIRFD
|
||||||
|
# define closefrom_fallback closefrom
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close all file descriptors greater than or equal to lowfd.
|
||||||
|
* This is the expensive (ballback) method.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
closefrom_fallback(int lowfd)
|
||||||
|
{
|
||||||
|
long fd, maxfd;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fall back on sysconf() or getdtablesize(). We avoid checking
|
||||||
|
* resource limits since it is possible to open a file descriptor
|
||||||
|
* and then drop the rlimit such that it is below the open fd.
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_SYSCONF
|
||||||
|
maxfd = sysconf(_SC_OPEN_MAX);
|
||||||
|
#else
|
||||||
|
maxfd = getdtablesize();
|
||||||
|
#endif /* HAVE_SYSCONF */
|
||||||
|
if (maxfd < 0)
|
||||||
|
maxfd = OPEN_MAX;
|
||||||
|
|
||||||
|
for (fd = lowfd; fd < maxfd; fd++)
|
||||||
|
(void)close((int)fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close all file descriptors greater than or equal to lowfd.
|
||||||
|
* We try the fast way first, falling back on the slow method.
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_FCNTL_CLOSEM
|
||||||
|
void
|
||||||
|
closefrom(int lowfd)
|
||||||
|
{
|
||||||
|
if (fcntl(lowfd, F_CLOSEM, 0) == -1)
|
||||||
|
closefrom_fallback(lowfd);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_DIRFD
|
||||||
|
void
|
||||||
|
closefrom(int lowfd)
|
||||||
|
{
|
||||||
|
struct dirent *dent;
|
||||||
|
DIR *dirp;
|
||||||
|
char *endp;
|
||||||
|
long fd;
|
||||||
|
|
||||||
|
/* Use /proc/self/fd directory if it exists. */
|
||||||
|
dirp = opendir("/proc/self/fd");
|
||||||
|
if (dirp != NULL) {
|
||||||
|
while ((dent = readdir(dirp)) != NULL) {
|
||||||
|
fd = strtol(dent->d_name, &endp, 10);
|
||||||
|
if (dent->d_name != endp && *endp == '\0' &&
|
||||||
|
fd >= 0 && fd < INT_MAX && fd >= lowfd &&
|
||||||
|
fd != dirfd(dirp))
|
||||||
|
(void)close((int)fd);
|
||||||
|
}
|
||||||
|
(void)closedir(dirp);
|
||||||
|
} else
|
||||||
|
closefrom_fallback(lowfd);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_DIRFD */
|
||||||
|
#endif /* HAVE_FCNTL_CLOSEM */
|
13
src/err.c
13
src/err.c
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -31,15 +32,10 @@
|
|||||||
void
|
void
|
||||||
warnc(int code, const char *format, ...)
|
warnc(int code, const char *format, ...)
|
||||||
{
|
{
|
||||||
int tmp = errno;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
vwarnc(code, format, ap);
|
||||||
errno = code;
|
|
||||||
warn(format, ap);
|
|
||||||
errno = tmp;
|
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,10 +55,7 @@ errc(int status, int code, const char *format, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
verrc(status, code, format, ap);
|
||||||
errno = code;
|
|
||||||
err(status, format, ap);
|
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
101
src/expand_number.c
Normal file
101
src/expand_number.c
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2007 Eric Anderson <anderson@FreeBSD.org>
|
||||||
|
* Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <libutil.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert an expression of the following forms to a uint64_t.
|
||||||
|
* 1) A positive decimal number.
|
||||||
|
* 2) A positive decimal number followed by a 'b' or 'B' (mult by 1).
|
||||||
|
* 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
|
||||||
|
* 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
|
||||||
|
* 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
|
||||||
|
* 6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40).
|
||||||
|
* 7) A positive decimal number followed by a 'p' or 'P' (mult by 1 << 50).
|
||||||
|
* 8) A positive decimal number followed by a 'e' or 'E' (mult by 1 << 60).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
expand_number(const char *buf, uint64_t *num)
|
||||||
|
{
|
||||||
|
uint64_t number;
|
||||||
|
unsigned shift;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
|
number = strtoumax(buf, &endptr, 0);
|
||||||
|
|
||||||
|
if (endptr == buf) {
|
||||||
|
/* No valid digits. */
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tolower((unsigned char)*endptr)) {
|
||||||
|
case 'e':
|
||||||
|
shift = 60;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
shift = 50;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
shift = 40;
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
shift = 30;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
shift = 20;
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
shift = 10;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case '\0': /* No unit. */
|
||||||
|
*num = number;
|
||||||
|
return (0);
|
||||||
|
default:
|
||||||
|
/* Unrecognized unit. */
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((number << shift) >> shift != number) {
|
||||||
|
/* Overflow */
|
||||||
|
errno = ERANGE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
*num = number << shift;
|
||||||
|
return (0);
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005 Hector Garcia Alvarez
|
* Copyright © 2005 Hector Garcia Alvarez
|
||||||
* Copyright © 2005, 2008, 2009, 2011 Guillem Jover
|
* Copyright © 2005, 2008, 2009, 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef HAVE_GETLINE
|
||||||
char *
|
char *
|
||||||
fgetln(FILE *stream, size_t *len)
|
fgetln(FILE *stream, size_t *len)
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2011 Guillem Jover
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,13 +24,11 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE 1
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdio_ext.h>
|
#include <stdio_ext.h>
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef HAVE___FPURGE
|
||||||
int
|
int
|
||||||
fpurge(FILE *fp)
|
fpurge(FILE *fp)
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2010 Guillem Jover
|
* Copyright © 2010 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <bsd/md5.h>
|
#include <md5.h>
|
||||||
|
|
||||||
#define PUT_64BIT_LE(cp, value) do { \
|
#define PUT_64BIT_LE(cp, value) do { \
|
||||||
(cp)[7] = (value) >> 56; \
|
(cp)[7] = (value) >> 56; \
|
||||||
|
@@ -86,7 +86,7 @@
|
|||||||
* Select the top of the heap and 'heapify'. Since by far the most expensive
|
* Select the top of the heap and 'heapify'. Since by far the most expensive
|
||||||
* action is the call to the compar function, a considerable optimization
|
* action is the call to the compar function, a considerable optimization
|
||||||
* in the average case can be achieved due to the fact that k, the displaced
|
* in the average case can be achieved due to the fact that k, the displaced
|
||||||
* elememt, is ususally quite small, so it would be preferable to first
|
* elememt, is usually quite small, so it would be preferable to first
|
||||||
* heapify, always maintaining the invariant that the larger child is copied
|
* heapify, always maintaining the invariant that the larger child is copied
|
||||||
* over its parent's record.
|
* over its parent's record.
|
||||||
*
|
*
|
||||||
|
@@ -89,3 +89,8 @@ LIBBSD_0.3 {
|
|||||||
|
|
||||||
fpurge;
|
fpurge;
|
||||||
} LIBBSD_0.2;
|
} LIBBSD_0.2;
|
||||||
|
|
||||||
|
LIBBSD_0.4 {
|
||||||
|
closefrom;
|
||||||
|
expand_number;
|
||||||
|
} LIBBSD_0.3;
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover
|
* Copyright © 2009 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@@ -138,7 +138,7 @@ __aout_fdnlist(fd, list)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Map the whole a.out file into our address space.
|
* Map the whole a.out file into our address space.
|
||||||
* We then find the string table withing this area.
|
* We then find the string table within this area.
|
||||||
* We do not just mmap the string table, as it probably
|
* We do not just mmap the string table, as it probably
|
||||||
* does not start at a page boundary - we save ourselves a
|
* does not start at a page boundary - we save ourselves a
|
||||||
* lot of nastiness by mmapping the whole file.
|
* lot of nastiness by mmapping the whole file.
|
||||||
@@ -227,14 +227,14 @@ __elf_is_okay__(ehdr)
|
|||||||
* We need to check magic, class size, endianess,
|
* We need to check magic, class size, endianess,
|
||||||
* and version before we look at the rest of the
|
* and version before we look at the rest of the
|
||||||
* Elf_Ehdr structure. These few elements are
|
* Elf_Ehdr structure. These few elements are
|
||||||
* represented in a machine independant fashion.
|
* represented in a machine independent fashion.
|
||||||
*/
|
*/
|
||||||
if (IS_ELF(*ehdr) &&
|
if (IS_ELF(*ehdr) &&
|
||||||
ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
|
ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
|
||||||
ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
|
ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
|
||||||
ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
|
ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
|
||||||
|
|
||||||
/* Now check the machine dependant header */
|
/* Now check the machine dependent header */
|
||||||
if (ehdr->e_machine == ELF_TARG_MACH &&
|
if (ehdr->e_machine == ELF_TARG_MACH &&
|
||||||
ehdr->e_version == ELF_TARG_VER)
|
ehdr->e_version == ELF_TARG_VER)
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
@@ -109,7 +109,7 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the PID file and obtain exclusive lock.
|
* Open the PID file and obtain exclusive lock.
|
||||||
* We truncate PID file here only to remove old PID immediatelly,
|
* We truncate PID file here only to remove old PID immediately,
|
||||||
* PID file will be truncated again in pidfile_write(), so
|
* PID file will be truncated again in pidfile_write(), so
|
||||||
* pidfile_write() can be called multiple times.
|
* pidfile_write() can be called multiple times.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2010-2011 Guillem Jover
|
* Copyright © 2010-2012 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -33,14 +33,22 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef HAVE___PROGNAME
|
||||||
|
extern const char *__progname;
|
||||||
|
#else
|
||||||
static const char *__progname = NULL;
|
static const char *__progname = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
getprogname(void)
|
getprogname(void)
|
||||||
{
|
{
|
||||||
#ifdef __GLIBC__
|
#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
|
||||||
if (__progname == NULL)
|
if (__progname == NULL)
|
||||||
__progname = program_invocation_short_name;
|
__progname = program_invocation_short_name;
|
||||||
|
#elif defined(HAVE_GETEXECNAME)
|
||||||
|
/* getexecname(3) returns an absolute pathname, normalize it. */
|
||||||
|
if (__progname == NULL)
|
||||||
|
setprogname(getexecname());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return __progname;
|
return __progname;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2010 Guillem Jover
|
* Copyright © 2010 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
3
test/.gitignore
vendored
Normal file
3
test/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
endian
|
||||||
|
headers
|
||||||
|
overlay
|
16
test/Makefile.am
Normal file
16
test/Makefile.am
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
AM_CPPFLAGS = \
|
||||||
|
-I$(top_builddir) \
|
||||||
|
-isystem $(top_srcdir)/include/bsd/ \
|
||||||
|
-include $(top_builddir)/config.h \
|
||||||
|
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
||||||
|
-D__REENTRANT
|
||||||
|
|
||||||
|
check_PROGRAMS = \
|
||||||
|
headers \
|
||||||
|
overlay \
|
||||||
|
endian \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
TESTS = $(check_PROGRAMS)
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover
|
* Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,19 +24,45 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_IP_ICMP_H
|
#include <sys/endian.h>
|
||||||
#define LIBBSD_BSD_IP_ICMP_H
|
|
||||||
|
|
||||||
#ifdef LIBBSD_DISABLE_DEPRECATED
|
#include <assert.h>
|
||||||
#error "Deprecated header, use <bsd/netinet/ip_icmp.h> or libbsd-overlay.pc instead."
|
#include <string.h>
|
||||||
#else
|
|
||||||
#warning "Deprecated header, use <bsd/netinet/ip_icmp.h> or libbsd-overlay.pc instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIBBSD_OVERLAY
|
int
|
||||||
#include <netinet/ip_icmp.h>
|
main()
|
||||||
#else
|
{
|
||||||
#include <bsd/netinet/ip_icmp.h>
|
unsigned char decstream[] = {
|
||||||
#endif
|
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||||
|
};
|
||||||
|
unsigned char encstream[sizeof(decstream)];
|
||||||
|
|
||||||
#endif
|
assert(be16dec(decstream) == 0x0011);
|
||||||
|
assert(le16dec(decstream) == 0x1100);
|
||||||
|
|
||||||
|
assert(be32dec(decstream) == 0x00112233);
|
||||||
|
assert(le32dec(decstream) == 0x33221100);
|
||||||
|
|
||||||
|
assert(be64dec(decstream) == 0x0011223344556677);
|
||||||
|
assert(le64dec(decstream) == 0x7766554433221100);
|
||||||
|
|
||||||
|
memset(encstream, 0, sizeof(encstream));
|
||||||
|
be16enc(encstream, 0x1100);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint16_t)));
|
||||||
|
le16enc(encstream, 0x0011);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint16_t)));
|
||||||
|
|
||||||
|
memset(encstream, 0, sizeof(encstream));
|
||||||
|
be32enc(encstream, 0x33221100);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint32_t)));
|
||||||
|
le32enc(encstream, 0x00112233);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint32_t)));
|
||||||
|
|
||||||
|
memset(encstream, 0, sizeof(encstream));
|
||||||
|
be64enc(encstream, 0x7766554433221100);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint64_t)));
|
||||||
|
le64enc(encstream, 0x0011223344556677);
|
||||||
|
assert(memcmp(encstream, decstream, sizeof(uint64_t)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
25
test/headers.c
Normal file
25
test/headers.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* Check that all libbsd overlayed headers preprocess. */
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/endian.h>
|
||||||
|
#include <sys/bitstring.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
|
#include <sys/tree.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <libutil.h>
|
||||||
|
#include <md5.h>
|
||||||
|
#include <nlist.h>
|
||||||
|
#include <readpassphrase.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
23
test/overlay.c
Normal file
23
test/overlay.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* Include system headers that are “known” to pull bits selectively from
|
||||||
|
* other headers through magic macros, to check that the overlay is working
|
||||||
|
* properly. */
|
||||||
|
#include <errno.h>
|
||||||
|
#include <grp.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Include libbsd overlayed headers that might get partially included. */
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
/* Test that we do not get partial definitions. */
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user