mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-20 22:31:34 +02:00
Compare commits
140 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e390651b64 | ||
![]() |
e8d3d04177 | ||
![]() |
faa005cb32 | ||
![]() |
36aca8c06e | ||
![]() |
e8f9300355 | ||
![]() |
a88bb8380d | ||
![]() |
8d16c3df67 | ||
![]() |
f41fdcf186 | ||
![]() |
86cbff385a | ||
![]() |
ee04e8de14 | ||
![]() |
61b2dbb8f5 | ||
![]() |
119417462e | ||
![]() |
948bcf1db8 | ||
![]() |
c5b9590287 | ||
![]() |
3077d2fffc | ||
![]() |
1bf0a55579 | ||
![]() |
ad613d9d09 | ||
![]() |
e084ce3fa7 | ||
![]() |
50e4c55afd | ||
![]() |
6faea4d2a0 | ||
![]() |
367e036537 | ||
![]() |
dc8b09783f | ||
![]() |
4663364783 | ||
![]() |
df5aebd7e1 | ||
![]() |
9587882316 | ||
![]() |
01f146c28e | ||
![]() |
509841b533 | ||
![]() |
06f0585c48 | ||
![]() |
7c4caa679a | ||
![]() |
30349f8922 | ||
![]() |
96a2dae352 | ||
![]() |
a4812cdf24 | ||
![]() |
d3a09e1cf4 | ||
![]() |
330b569fe3 | ||
![]() |
8c26c40ad2 | ||
![]() |
e9933255d4 | ||
![]() |
c984dacd65 | ||
![]() |
35785f8dd1 | ||
![]() |
2a0260d08c | ||
![]() |
f8d52ead5e | ||
![]() |
cf683a275a | ||
![]() |
7196b4dcca | ||
![]() |
a97ce513e0 | ||
![]() |
ee0489eb2b | ||
![]() |
cb7bc0d85e | ||
![]() |
1be0bdb2c9 | ||
![]() |
ff0d700df0 | ||
![]() |
3862764872 | ||
![]() |
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 | ||
![]() |
7446f029b5 | ||
![]() |
e80d338b18 | ||
![]() |
b891772ad6 | ||
![]() |
b0eb19970a | ||
![]() |
0bf3d3913f | ||
![]() |
913cdd91b1 | ||
![]() |
200eeb1265 | ||
![]() |
fbd622971d | ||
![]() |
755d86be01 | ||
![]() |
cd4996cebe | ||
![]() |
a7dd4457f5 | ||
![]() |
8be40010ce | ||
![]() |
e1f2a6f869 | ||
![]() |
87dd203c26 | ||
![]() |
de2062873f | ||
![]() |
71e5db4cde | ||
![]() |
9d04217174 | ||
![]() |
17a9a8472e | ||
![]() |
94fe901eda | ||
![]() |
28585a58bd | ||
![]() |
b36c59c0ed | ||
![]() |
8b6a74775b | ||
![]() |
c594192bac | ||
![]() |
8478e57463 | ||
![]() |
f7caf2b30d | ||
![]() |
520682e596 | ||
![]() |
4c01261f39 | ||
![]() |
8a99226f16 | ||
![]() |
1497d34760 | ||
![]() |
741eb58763 | ||
![]() |
9baf9640b9 | ||
![]() |
4b95e82a32 | ||
![]() |
c766e58acf | ||
![]() |
be6ab54986 | ||
![]() |
5b19adfa82 | ||
![]() |
acb7c42d7c | ||
![]() |
06a60a166a | ||
![]() |
51863b6cf9 | ||
![]() |
08afd5d4c9 | ||
![]() |
1f0b0b23cd | ||
![]() |
32d79b0310 | ||
![]() |
cd730a02c3 | ||
![]() |
11f2c32df2 | ||
![]() |
30c794083f |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,6 +1,22 @@
|
|||||||
ChangeLog
|
ChangeLog
|
||||||
libbsd.pc
|
*.pc
|
||||||
|
*.la
|
||||||
*.lo
|
*.lo
|
||||||
*.o
|
*.o
|
||||||
*.so*
|
*.so*
|
||||||
*.a
|
*.a
|
||||||
|
*.log
|
||||||
|
*.trs
|
||||||
|
.dirstamp
|
||||||
|
.deps/
|
||||||
|
.libs/
|
||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
aclocal.m4
|
||||||
|
autom4te.cache/
|
||||||
|
build-aux/
|
||||||
|
configure
|
||||||
|
config.*
|
||||||
|
libtool
|
||||||
|
m4/
|
||||||
|
stamp-h1
|
||||||
|
494
COPYING
Normal file
494
COPYING
Normal file
@@ -0,0 +1,494 @@
|
|||||||
|
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>
|
||||||
|
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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
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-2013 Guillem Jover <guillem@hadrons.org>
|
||||||
|
Copyright © 2005 Hector Garcia Alvarez
|
||||||
|
Copyright © 2005 Aurelien Jarno
|
||||||
|
Copyright © 2006 Robert Millan
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 1980, 1982, 1986, 1989-1994
|
||||||
|
The Regents of the University of California. All rights reserved.
|
||||||
|
Copyright © 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
the American National Standards Committee X3, on Information
|
||||||
|
Processing Systems.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Peter McIlroy.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Dave Borman at Cray Research, Inc.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Paul Vixie.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Chris Torek.
|
||||||
|
|
||||||
|
© UNIX System Laboratories, Inc.
|
||||||
|
All or some portions of this file are derived from material licensed
|
||||||
|
to the University of California by American Telephone and Telegraph
|
||||||
|
Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||||
|
the permission of UNIX System Laboratories, Inc.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. 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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 1996 Peter Wemm <peter@FreeBSD.org>.
|
||||||
|
All rights reserved.
|
||||||
|
Copyright © 2002 Networks Associates Technology, Inc.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Portions of this software were developed for the FreeBSD Project by
|
||||||
|
ThinkSec AS and NAI Labs, the Security Research Division of Network
|
||||||
|
Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
|
||||||
|
("CBOSS"), as part of the DARPA CHATS research program.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, is permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
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 © 1994, 1997-2000, 2002, 2008 The NetBSD Foundation, Inc.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
||||||
|
|
||||||
|
Some code was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to The NetBSD Foundation
|
||||||
|
by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
||||||
|
NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to The NetBSD Foundation
|
||||||
|
by Julio M. Merino Vidal, developed as part of Google's Summer of Code
|
||||||
|
2005 program.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to The NetBSD Foundation
|
||||||
|
by Christos Zoulas.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 1998, M. Warner Losh <imp@freebsd.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2001 Dima Dorfman.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2001 FreeBSD Inc.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2002 Thomas Moestl <tmm@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2007 Eric Anderson <anderson@FreeBSD.org>
|
||||||
|
Copyright © 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 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 © 1997 Christos Zoulas.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
||||||
|
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
|
||||||
|
in this position and unchanged.
|
||||||
|
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, 2000 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
Copyright © 2004 Ted Unangst
|
||||||
|
|
||||||
|
Copyright © 2004 Ted Unangst and Todd Miller
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2008 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
Sponsored in part by the Defense Advanced Research Projects
|
||||||
|
Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||||
|
Materiel Command, USAF, under agreement number F39502-99-1-0512
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 1996 by Internet Software Consortium.
|
||||||
|
|
||||||
|
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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
CONSORTIUM 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.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 1996, David Mazieres <dm@uun.org>
|
||||||
|
Copyright © 2008, Damien Miller <djm@openbsd.org>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
Modification and redistribution in source and binary forms is
|
||||||
|
permitted provided that due credit is given to the author and the
|
||||||
|
OpenBSD project (for instance by leaving this copyright notice
|
||||||
|
intact).
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
This code is derived from section 17.1 of Applied Cryptography,
|
||||||
|
second edition, which describes a stream cipher allegedly
|
||||||
|
compatible with RSA Labs "RC4" cipher (the actual description of
|
||||||
|
which is a trade secret). The same algorithm is used as a stream
|
||||||
|
cipher called "arcfour" in Tatu Ylonen's ssh package.
|
||||||
|
|
||||||
|
Here the stream cipher has been modified always to include the time
|
||||||
|
when initializing the state. That makes it impossible to
|
||||||
|
regenerate the same random sequence twice, so this can't be used
|
||||||
|
for encryption, but will generate good random numbers.
|
||||||
|
|
||||||
|
RC4 is a registered trademark of RSA Laboratories.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Copyright © 2010 William Ahern
|
||||||
|
Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
persons to whom the Software is furnished to do so, subject to the
|
||||||
|
following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
This code implements the MD5 message-digest algorithm.
|
||||||
|
The algorithm is due to Ron Rivest. This code was
|
||||||
|
written by Colin Plumb in 1993, no copyright is claimed.
|
||||||
|
This code is in the public domain; do with it what you wish.
|
||||||
|
|
||||||
|
Equivalent code is available from RSA Data Security, Inc.
|
||||||
|
This code has been tested against that, and is equivalent,
|
||||||
|
except that you don't need to include two pages of legalese
|
||||||
|
with every copy.
|
||||||
|
|
||||||
|
To compute the message digest of a chunk of bytes, declare an
|
||||||
|
MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||||
|
needed on buffers full of bytes, and then call MD5Final, which
|
||||||
|
will fill a supplied 16-byte array with the digest.
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
"THE BEER-WARE LICENSE" (Revision 42):
|
||||||
|
<phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||||
|
can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
203
Makefile
203
Makefile
@@ -1,203 +0,0 @@
|
|||||||
VERSION := $(shell ./get-version)
|
|
||||||
|
|
||||||
LIB_NAME := libbsd
|
|
||||||
LIB_VERSION_MAJOR := 0
|
|
||||||
LIB_VERSION_MINOR := 2
|
|
||||||
LIB_VERSION_MICRO := 0
|
|
||||||
LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
|
|
||||||
|
|
||||||
LIB_PKGCONFIG := $(LIB_NAME).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 \
|
|
||||||
heapsort.c \
|
|
||||||
humanize_number.c \
|
|
||||||
dehumanize_number.c \
|
|
||||||
inet_net_pton.c \
|
|
||||||
hash/md5.c \
|
|
||||||
pidfile.c \
|
|
||||||
readpassphrase.c \
|
|
||||||
setmode.c \
|
|
||||||
setproctitle.c \
|
|
||||||
strmode.c \
|
|
||||||
strtonum.c \
|
|
||||||
strlcat.c strlcpy.c \
|
|
||||||
fmtcheck.c \
|
|
||||||
nlist.c \
|
|
||||||
progname.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/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 \
|
|
||||||
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 \
|
|
||||||
readpassphrase.3 \
|
|
||||||
humanize_number.3 \
|
|
||||||
fmtcheck.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)
|
|
||||||
|
|
||||||
# Set default value for compilation
|
|
||||||
CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable
|
|
||||||
|
|
||||||
MK_CFLAGS := -Iinclude/ -include bsd/bsd.h -D_GNU_SOURCE -D__REENTRANT
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
.PHONY: man
|
|
||||||
man: $(LIB_MANS)
|
|
||||||
|
|
||||||
%.lo: %.c
|
|
||||||
$(CC) -o $@ $(MK_CFLAGS) $(CFLAGS) -DPIC -fPIC -c $<
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -o $@ $(MK_CFLAGS) $(CFLAGS) -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' $< > $@
|
|
||||||
|
|
||||||
$(LIB_PKGCONFIG): $(LIB_PKGCONFIG).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)
|
|
||||||
gcc -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 -m644 $(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)
|
|
||||||
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_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)
|
|
||||||
|
|
16
Makefile.am
Normal file
16
Makefile.am
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
SUBDIRS = include man src test
|
||||||
|
|
||||||
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
autogen \
|
||||||
|
get-version \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
dist-hook:
|
||||||
|
echo $(VERSION) >$(distdir)/.dist-version
|
||||||
|
if [ -d .git ]; then \
|
||||||
|
git log --stat -C >$(distdir)/ChangeLog; \
|
||||||
|
fi
|
1
README
1
README
@@ -29,4 +29,3 @@ Source Repository
|
|||||||
|
|
||||||
<http://cgit.freedesktop.org/libbsd>
|
<http://cgit.freedesktop.org/libbsd>
|
||||||
<git://anongit.freedesktop.org/git/libbsd>
|
<git://anongit.freedesktop.org/git/libbsd>
|
||||||
|
|
||||||
|
1
TODO
1
TODO
@@ -1,4 +1,3 @@
|
|||||||
* Add more functions used by ported packages (check openssh).
|
* Add more functions used by ported packages (check openssh).
|
||||||
* Fix includes on man pages.
|
|
||||||
* Add missing man pages.
|
* Add missing man pages.
|
||||||
* Add a README.import file.
|
* Add a README.import file.
|
||||||
|
67
Versions
67
Versions
@@ -1,67 +0,0 @@
|
|||||||
LIBBSD_0.0 {
|
|
||||||
global:
|
|
||||||
arc4random;
|
|
||||||
arc4random_stir;
|
|
||||||
arc4random_addrandom;
|
|
||||||
bsd_getopt; optreset;
|
|
||||||
errc; warnc; verrc; vwarnc;
|
|
||||||
fgetln;
|
|
||||||
fmtcheck;
|
|
||||||
heapsort;
|
|
||||||
humanize_number;
|
|
||||||
|
|
||||||
inet_net_pton; /* XXX: Already provided by glibc, remove. */
|
|
||||||
|
|
||||||
getprogname; setprogname;
|
|
||||||
strlcpy;
|
|
||||||
strlcat;
|
|
||||||
|
|
||||||
setmode;
|
|
||||||
getmode;
|
|
||||||
|
|
||||||
vis; strvis; strvisx;
|
|
||||||
unvis; strunvis; strunvisx;
|
|
||||||
MD5Init;
|
|
||||||
MD5Update;
|
|
||||||
MD5Pad;
|
|
||||||
MD5Final;
|
|
||||||
MD5Transform;
|
|
||||||
MD5End;
|
|
||||||
MD5File;
|
|
||||||
MD5FileChunk;
|
|
||||||
MD5Data;
|
|
||||||
|
|
||||||
local:
|
|
||||||
*;
|
|
||||||
};
|
|
||||||
|
|
||||||
LIBBSD_0.1 {
|
|
||||||
strmode;
|
|
||||||
|
|
||||||
__fdnlist; /* Private symbol, but libkvm uses it. */
|
|
||||||
nlist;
|
|
||||||
} LIBBSD_0.0;
|
|
||||||
|
|
||||||
LIBBSD_0.2 {
|
|
||||||
strtonum;
|
|
||||||
|
|
||||||
strnvis;
|
|
||||||
strnunvis;
|
|
||||||
|
|
||||||
dehumanize_number;
|
|
||||||
|
|
||||||
readpassphrase;
|
|
||||||
|
|
||||||
flopen;
|
|
||||||
|
|
||||||
pidfile_open;
|
|
||||||
pidfile_write;
|
|
||||||
pidfile_close;
|
|
||||||
pidfile_remove;
|
|
||||||
|
|
||||||
setproctitle;
|
|
||||||
|
|
||||||
arc4random_buf;
|
|
||||||
arc4random_uniform;
|
|
||||||
} LIBBSD_0.1;
|
|
||||||
|
|
5
autogen
Executable file
5
autogen
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p m4
|
||||||
|
autoreconf -f -i
|
||||||
|
rm -rf autom4te.cache
|
139
configure.ac
Normal file
139
configure.ac
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
# 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.9 foreign nostdinc subdir-objects no-dist-gzip dist-xz])
|
||||||
|
|
||||||
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||||
|
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||||
|
|
||||||
|
LIBBSD_ABI_MAJOR=0
|
||||||
|
LIBBSD_ABI_MINOR=7
|
||||||
|
LIBBSD_ABI_PATCH=0
|
||||||
|
|
||||||
|
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
||||||
|
AC_SUBST([LIBBSD_ABI])
|
||||||
|
|
||||||
|
# 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_C_TYPEOF
|
||||||
|
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>])
|
||||||
|
|
||||||
|
AC_CACHE_CHECK(
|
||||||
|
[for GNU .init_array section support],
|
||||||
|
[libbsd_cv_gnu_init_array_support],
|
||||||
|
[AC_RUN_IFELSE(
|
||||||
|
[AC_LANG_SOURCE(
|
||||||
|
[[
|
||||||
|
static int rc = 1;
|
||||||
|
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||||
|
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
|
||||||
|
int main() { return rc; }
|
||||||
|
]]
|
||||||
|
)],
|
||||||
|
[libbsd_cv_gnu_init_array_support=yes],
|
||||||
|
[libbsd_cv_gnu_init_array_support=no],
|
||||||
|
[AC_PREPROC_IFELSE(
|
||||||
|
[AC_LANG_SOURCE(
|
||||||
|
[[
|
||||||
|
/* Look for a known libc that supports .init_array with the GNU extension
|
||||||
|
* to pass main() arguments to the init functions. */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#if defined __GLIBC_PREREQ
|
||||||
|
# if __GLIBC_PREREQ(2, 4)
|
||||||
|
/* glibc supports GNU .init_array since 2.4. */
|
||||||
|
# else
|
||||||
|
# error glibc does not support GNU .init_array
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
||||||
|
* - Bionic since its inception.
|
||||||
|
* - uClibc since 0.9.29.
|
||||||
|
*/
|
||||||
|
# error unknown whether libc supports GNU .init_array
|
||||||
|
#endif
|
||||||
|
]]
|
||||||
|
)],
|
||||||
|
[libbsd_cv_gnu_init_array_support=yes],
|
||||||
|
[libbsd_cv_gnu_init_array_support=no])
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
)
|
||||||
|
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
|
||||||
|
[test "$libbsd_cv_gnu_init_array_support" = yes])
|
||||||
|
|
||||||
|
# Checks for library functions.
|
||||||
|
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([clearenv dirfd fopencookie __fpurge getexecname getline sysconf])
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([
|
||||||
|
Makefile
|
||||||
|
include/Makefile
|
||||||
|
man/Makefile
|
||||||
|
src/Makefile
|
||||||
|
src/libbsd.pc
|
||||||
|
src/libbsd-ctor.pc
|
||||||
|
src/libbsd-overlay.pc
|
||||||
|
test/Makefile
|
||||||
|
])
|
||||||
|
AC_CONFIG_HEADERS([config.h])
|
||||||
|
AC_OUTPUT
|
@@ -44,5 +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"
|
||||||
|
27
include/Makefile.am
Normal file
27
include/Makefile.am
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
## 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/stringlist.h \
|
||||||
|
bsd/timeconv.h \
|
||||||
|
bsd/unistd.h \
|
||||||
|
bsd/vis.h \
|
||||||
|
bsd/wchar.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,12 +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>
|
||||||
#warning "This header is deprecated, use the one in arpa/inet.h instead."
|
#else
|
||||||
|
#include <bsd/sys/bitstring.h>
|
||||||
#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,7 +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. */
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2009 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,11 +25,17 @@
|
|||||||
* 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
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <err.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
* Copyright © 2009 Guillem Jover
|
|
||||||
*
|
*
|
||||||
* 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,16 +24,10 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_GETOPT_H
|
#ifdef LIBBSD_OVERLAY
|
||||||
#define LIBBSD_GETOPT_H
|
#include_next <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/cdefs.h>
|
#else
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <bsd/unistd.h>
|
||||||
__BEGIN_DECLS
|
|
||||||
extern int optreset;
|
|
||||||
|
|
||||||
int bsd_getopt (int, char **, char *);
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -40,7 +40,10 @@
|
|||||||
#define _LIBUTIL_H_
|
#define _LIBUTIL_H_
|
||||||
|
|
||||||
#include <features.h>
|
#include <features.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/* for pidfile.c */
|
/* for pidfile.c */
|
||||||
struct pidfh {
|
struct pidfh {
|
||||||
@@ -53,6 +56,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, ...);
|
||||||
|
|
||||||
@@ -60,6 +64,8 @@ struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
|
|||||||
int pidfile_write(struct pidfh *pfh);
|
int pidfile_write(struct pidfh *pfh);
|
||||||
int pidfile_close(struct pidfh *pfh);
|
int pidfile_close(struct pidfh *pfh);
|
||||||
int pidfile_remove(struct pidfh *pfh);
|
int pidfile_remove(struct pidfh *pfh);
|
||||||
|
|
||||||
|
char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
/* humanize_number(3) */
|
/* humanize_number(3) */
|
||||||
@@ -71,4 +77,13 @@ __END_DECLS
|
|||||||
#define HN_GETSCALE 0x10
|
#define HN_GETSCALE 0x10
|
||||||
#define HN_AUTOSCALE 0x20
|
#define HN_AUTOSCALE 0x20
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fparseln() specific operation flags.
|
||||||
|
*/
|
||||||
|
#define FPARSELN_UNESCESC 0x01
|
||||||
|
#define FPARSELN_UNESCCONT 0x02
|
||||||
|
#define FPARSELN_UNESCCOMM 0x04
|
||||||
|
#define FPARSELN_UNESCREST 0x08
|
||||||
|
#define FPARSELN_UNESCALL 0x0f
|
||||||
|
|
||||||
#endif /* !_LIBUTIL_H_ */
|
#endif /* !_LIBUTIL_H_ */
|
@@ -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
|
||||||
@@ -35,4 +35,3 @@ extern int nlist(const char *filename, struct nlist *list);
|
|||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@@ -1,35 +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
|
|
||||||
|
|
||||||
#warning "This header is deprecated, use the one in bsd/stdlib.h instead."
|
|
||||||
|
|
||||||
#include <bsd/stdlib.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2009 Guillem Jover
|
* Copyright © 2004-2005, 2009, 2011-2013 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,17 +24,48 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(__need_FILE) || defined(__need___FILE)
|
||||||
|
#define LIBBSD_STDIO_H_SKIP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_STDIO_H_SKIP
|
||||||
#ifndef LIBBSD_STDIO_H
|
#ifndef LIBBSD_STDIO_H
|
||||||
#define LIBBSD_STDIO_H
|
#define LIBBSD_STDIO_H
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
const char *fmtcheck(const char *, const char *);
|
const char *fmtcheck(const char *, const char *);
|
||||||
|
|
||||||
char *fgetln(FILE *fp, size_t *lenp);
|
char *fgetln(FILE *fp, size_t *lenp);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
|
||||||
|
* because seekfn() there wrongly uses fpos_t, assuming it's an integral
|
||||||
|
* type, and any code using that on a system where fpos_t is a struct
|
||||||
|
* (such as GNU-based systems or NetBSD) will fail to build. In which case,
|
||||||
|
* as the code has to be modified anyway, we might just as well use the
|
||||||
|
* correct declaration here.
|
||||||
|
*/
|
||||||
|
FILE *funopen(const void *cookie,
|
||||||
|
int (*readfn)(void *cookie, char *buf, int size),
|
||||||
|
int (*writefn)(void *cookie, const char *buf, int size),
|
||||||
|
off_t (*seekfn)(void *cookie, off_t offset, int whence),
|
||||||
|
int (*closefn)(void *cookie));
|
||||||
|
|
||||||
|
#define fropen(cookie, fn) funopen(cookie, fn, NULL, NULL, NULL)
|
||||||
|
#define fwopen(cookie, fn) funopen(cookie, NULL, fn, NULL, NULL)
|
||||||
|
|
||||||
|
int fpurge(FILE *fp);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
#undef LIBBSD_STDIO_H_SKIP
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005 Aurelien Jarno
|
* Copyright © 2005 Aurelien Jarno
|
||||||
* Copyright © 2006 Robert Millan
|
* Copyright © 2006 Robert Millan
|
||||||
* Copyright © 2008, 2009 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,35 +26,53 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <stdlib.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* For compatibility with NetBSD, which defines humanize_number here. */
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include <libutil.h>
|
||||||
|
#else
|
||||||
|
#include <bsd/libutil.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_STDLIB_H
|
#ifndef LIBBSD_STDLIB_H
|
||||||
#define LIBBSD_STDLIB_H
|
#define LIBBSD_STDLIB_H
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/* For compatibility with NetBSD, which defines humanize_number here. */
|
|
||||||
#include <libutil.h>
|
|
||||||
|
|
||||||
/* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */
|
|
||||||
#include <bsd/stdio.h>
|
|
||||||
#include <bsd/unistd.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
u_int32_t arc4random();
|
u_int32_t arc4random();
|
||||||
void arc4random_stir();
|
void arc4random_stir();
|
||||||
void arc4random_addrandom(u_char *dat, int datlen);
|
void arc4random_addrandom(u_char *dat, int datlen);
|
||||||
|
void arc4random_buf(void *_buf, size_t n);
|
||||||
|
u_int32_t arc4random_uniform(u_int32_t upper_bound);
|
||||||
|
|
||||||
int dehumanize_number(const char *str, int64_t *size);
|
int dehumanize_number(const char *str, int64_t *size);
|
||||||
|
|
||||||
char *getprogname ();
|
const char *getprogname(void);
|
||||||
void setprogname (char *);
|
void setprogname(const char *);
|
||||||
|
|
||||||
int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
||||||
|
int mergesort(void *base, size_t nmemb, size_t size,
|
||||||
|
int (*cmp)(const void *, const void *));
|
||||||
|
int radixsort(const unsigned char **base, int nmemb,
|
||||||
|
const unsigned char *table, unsigned endbyte);
|
||||||
|
int sradixsort(const unsigned char **base, int nmemb,
|
||||||
|
const unsigned char *table, unsigned endbyte);
|
||||||
|
|
||||||
|
void *reallocf(void *ptr, size_t size);
|
||||||
|
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
|
|
||||||
long long strtonum(const char *nptr, long long minval, long long maxval,
|
long long strtonum(const char *nptr, long long minval, long long maxval,
|
||||||
const char **errstr);
|
const char **errstr);
|
||||||
|
|
||||||
|
char *getbsize(int *headerlenp, long *blocksizep);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2009 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,22 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <string.h>
|
||||||
|
#else
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_STRING_H
|
#ifndef LIBBSD_STRING_H
|
||||||
#define LIBBSD_STRING_H
|
#define LIBBSD_STRING_H
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
|
|
||||||
#include <bsd/stdio.h>
|
|
||||||
|
|
||||||
__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);
|
||||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||||
|
char *strnstr(const char *str, const char *find, size_t str_len);
|
||||||
void strmode(mode_t mode, char *str);
|
void strmode(mode_t mode, char *str);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
54
include/bsd/stringlist.h
Normal file
54
include/bsd/stringlist.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* $NetBSD: stringlist.h,v 1.6 2006/07/27 15:37:19 christos Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Christos Zoulas.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _STRINGLIST_H
|
||||||
|
#define _STRINGLIST_H
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simple string list
|
||||||
|
*/
|
||||||
|
typedef struct _stringlist {
|
||||||
|
char **sl_str;
|
||||||
|
size_t sl_max;
|
||||||
|
size_t sl_cur;
|
||||||
|
} StringList;
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
StringList *sl_init(void);
|
||||||
|
int sl_add(StringList *, char *);
|
||||||
|
void sl_free(StringList *, int);
|
||||||
|
char *sl_find(StringList *, const char *);
|
||||||
|
int sl_delete(StringList *, const char *, int);
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* _STRINGLIST_H */
|
146
include/bsd/sys/bitstring.h
Normal file
146
include/bsd/sys/bitstring.h
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1989, 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.
|
||||||
|
*
|
||||||
|
* $FreeBSD$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SYS_BITSTRING_H_
|
||||||
|
#define _SYS_BITSTRING_H_
|
||||||
|
|
||||||
|
typedef unsigned char bitstr_t;
|
||||||
|
|
||||||
|
/* internal macros */
|
||||||
|
/* byte of the bitstring bit is in */
|
||||||
|
#define _bit_byte(bit) \
|
||||||
|
((bit) >> 3)
|
||||||
|
|
||||||
|
/* mask for the bit within its byte */
|
||||||
|
#define _bit_mask(bit) \
|
||||||
|
(1 << ((bit)&0x7))
|
||||||
|
|
||||||
|
/* external macros */
|
||||||
|
/* bytes in a bitstring of nbits bits */
|
||||||
|
#define bitstr_size(nbits) \
|
||||||
|
(((nbits) + 7) >> 3)
|
||||||
|
|
||||||
|
/* allocate a bitstring */
|
||||||
|
#define bit_alloc(nbits) \
|
||||||
|
(bitstr_t *)calloc((size_t)bitstr_size(nbits), sizeof(bitstr_t))
|
||||||
|
|
||||||
|
/* allocate a bitstring on the stack */
|
||||||
|
#define bit_decl(name, nbits) \
|
||||||
|
((name)[bitstr_size(nbits)])
|
||||||
|
|
||||||
|
/* is bit N of bitstring name set? */
|
||||||
|
#define bit_test(name, bit) \
|
||||||
|
((name)[_bit_byte(bit)] & _bit_mask(bit))
|
||||||
|
|
||||||
|
/* set bit N of bitstring name */
|
||||||
|
#define bit_set(name, bit) \
|
||||||
|
((name)[_bit_byte(bit)] |= _bit_mask(bit))
|
||||||
|
|
||||||
|
/* clear bit N of bitstring name */
|
||||||
|
#define bit_clear(name, bit) \
|
||||||
|
((name)[_bit_byte(bit)] &= ~_bit_mask(bit))
|
||||||
|
|
||||||
|
/* clear bits start ... stop in bitstring */
|
||||||
|
#define bit_nclear(name, start, stop) do { \
|
||||||
|
register bitstr_t *_name = (name); \
|
||||||
|
register int _start = (start), _stop = (stop); \
|
||||||
|
register int _startbyte = _bit_byte(_start); \
|
||||||
|
register int _stopbyte = _bit_byte(_stop); \
|
||||||
|
if (_startbyte == _stopbyte) { \
|
||||||
|
_name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \
|
||||||
|
(0xff << ((_stop&0x7) + 1))); \
|
||||||
|
} else { \
|
||||||
|
_name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \
|
||||||
|
while (++_startbyte < _stopbyte) \
|
||||||
|
_name[_startbyte] = 0; \
|
||||||
|
_name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* set bits start ... stop in bitstring */
|
||||||
|
#define bit_nset(name, start, stop) do { \
|
||||||
|
register bitstr_t *_name = (name); \
|
||||||
|
register int _start = (start), _stop = (stop); \
|
||||||
|
register int _startbyte = _bit_byte(_start); \
|
||||||
|
register int _stopbyte = _bit_byte(_stop); \
|
||||||
|
if (_startbyte == _stopbyte) { \
|
||||||
|
_name[_startbyte] |= ((0xff << (_start&0x7)) & \
|
||||||
|
(0xff >> (7 - (_stop&0x7)))); \
|
||||||
|
} else { \
|
||||||
|
_name[_startbyte] |= 0xff << ((_start)&0x7); \
|
||||||
|
while (++_startbyte < _stopbyte) \
|
||||||
|
_name[_startbyte] = 0xff; \
|
||||||
|
_name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* find first bit clear in name */
|
||||||
|
#define bit_ffc(name, nbits, value) do { \
|
||||||
|
register bitstr_t *_name = (name); \
|
||||||
|
register int _byte, _nbits = (nbits); \
|
||||||
|
register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \
|
||||||
|
if (_nbits > 0) \
|
||||||
|
for (_byte = 0; _byte <= _stopbyte; ++_byte) \
|
||||||
|
if (_name[_byte] != 0xff) { \
|
||||||
|
bitstr_t _lb; \
|
||||||
|
_value = _byte << 3; \
|
||||||
|
for (_lb = _name[_byte]; (_lb&0x1); \
|
||||||
|
++_value, _lb >>= 1); \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
if (_value >= nbits) \
|
||||||
|
_value = -1; \
|
||||||
|
*(value) = _value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* find first bit set in name */
|
||||||
|
#define bit_ffs(name, nbits, value) do { \
|
||||||
|
register bitstr_t *_name = (name); \
|
||||||
|
register int _byte, _nbits = (nbits); \
|
||||||
|
register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \
|
||||||
|
if (_nbits > 0) \
|
||||||
|
for (_byte = 0; _byte <= _stopbyte; ++_byte) \
|
||||||
|
if (_name[_byte]) { \
|
||||||
|
bitstr_t _lb; \
|
||||||
|
_value = _byte << 3; \
|
||||||
|
for (_lb = _name[_byte]; !(_lb&0x1); \
|
||||||
|
++_value, _lb >>= 1); \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
if (_value >= nbits) \
|
||||||
|
_value = -1; \
|
||||||
|
*(value) = _value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif /* !_SYS_BITSTRING_H_ */
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2004, 2005, 2006, 2009 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,17 +24,61 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_CDEFS_H
|
#ifdef LIBBSD_OVERLAY
|
||||||
#define LIBBSD_CDEFS_H
|
#include_next <sys/cdefs.h>
|
||||||
|
#else
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_CDEFS_H
|
||||||
|
#define LIBBSD_SYS_CDEFS_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some kFreeBSD headers expect those macros to be set for sanity checks.
|
||||||
|
*/
|
||||||
|
#ifndef _SYS_CDEFS_H_
|
||||||
|
#define _SYS_CDEFS_H_
|
||||||
|
#endif
|
||||||
|
#ifndef _SYS_CDEFS_H
|
||||||
|
#define _SYS_CDEFS_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
|
||||||
|
#else
|
||||||
|
#define LIBBSD_GCC_VERSION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __dead2
|
#ifndef __dead2
|
||||||
# define __dead2
|
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||||
|
# define __dead2 __attribute__((__noreturn__))
|
||||||
|
# else
|
||||||
|
# define __dead2
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __pure2
|
#ifndef __pure2
|
||||||
# define __pure2
|
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||||
|
# define __pure2 __attribute__((__const__))
|
||||||
|
# else
|
||||||
|
# define __pure2
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __packed
|
||||||
|
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||||
|
# define __packed __attribute__((__packed__))
|
||||||
|
# else
|
||||||
|
# define __packed
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __aligned
|
||||||
|
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||||
|
# define __aligned(x) __attribute__((__aligned__(x)))
|
||||||
|
# else
|
||||||
|
# define __aligned(x)
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Linux headers define a struct with a member names __unused.
|
/* Linux headers define a struct with a member names __unused.
|
||||||
@@ -42,7 +86,7 @@
|
|||||||
* Disable for now. */
|
* Disable for now. */
|
||||||
#if 0
|
#if 0
|
||||||
#ifndef __unused
|
#ifndef __unused
|
||||||
# ifdef __GNUC__
|
# if LIBBSD_GCC_VERSION >= 0x0300
|
||||||
# define __unused __attribute__((unused))
|
# define __unused __attribute__((unused))
|
||||||
# else
|
# else
|
||||||
# define __unused
|
# define __unused
|
||||||
@@ -51,13 +95,21 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __printflike
|
#ifndef __printflike
|
||||||
# ifdef __GNUC__
|
# if LIBBSD_GCC_VERSION >= 0x0300
|
||||||
# define __printflike(x, y) __attribute((format(printf, (x), (y))))
|
# define __printflike(x, y) __attribute((format(printf, (x), (y))))
|
||||||
# else
|
# else
|
||||||
# define __printflike(x, y)
|
# define __printflike(x, y)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __nonnull
|
||||||
|
# if LIBBSD_GCC_VERSION >= 0x0302
|
||||||
|
# define __nonnull(x) __attribute__((__nonnull__(x)))
|
||||||
|
# else
|
||||||
|
# define __nonnull(x)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __bounded__
|
#ifndef __bounded__
|
||||||
# define __bounded__(x, y, z)
|
# define __bounded__(x, y, z)
|
||||||
#endif
|
#endif
|
||||||
|
188
include/bsd/sys/endian.h
Normal file
188
include/bsd/sys/endian.h
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <endian.h>
|
||||||
|
#else
|
||||||
|
#include <endian.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_ENDIAN_H
|
||||||
|
#define LIBBSD_SYS_ENDIAN_H
|
||||||
|
|
||||||
|
#ifndef _BYTE_ORDER
|
||||||
|
#define _BYTE_ORDER __BYTE_ORDER
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _LITTLE_ENDIAN
|
||||||
|
#define _LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _BIG_ENDIAN
|
||||||
|
#define _BIG_ENDIAN __BIG_ENDIAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _PDP_ENDIAN
|
||||||
|
#define _PDP_ENDIAN __PDP_ENDIAN
|
||||||
|
#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
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 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,12 +24,17 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_IP_ICMP_H
|
#ifdef LIBBSD_OVERLAY
|
||||||
#define LIBBSD_BSD_IP_ICMP_H
|
#include_next <sys/poll.h>
|
||||||
|
#else
|
||||||
#warning "This header is deprecated, use <bsd/netinet/ip_icmp.h> instead."
|
#include <sys/poll.h>
|
||||||
|
|
||||||
#include <bsd/netinet/ip_icmp.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_SYS_POLL_H
|
||||||
|
#define LIBBSD_SYS_POLL_H
|
||||||
|
|
||||||
|
#ifndef INFTIM
|
||||||
|
#define INFTIM (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
57
include/bsd/timeconv.h
Normal file
57
include/bsd/timeconv.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
* (c) UNIX System Laboratories, Inc.
|
||||||
|
* All or some portions of this file are derived from material licensed
|
||||||
|
* to the University of California by American Telephone and Telegraph
|
||||||
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||||
|
* the permission of UNIX System Laboratories, Inc.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. 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.
|
||||||
|
*
|
||||||
|
* @(#)time.h 8.3 (Berkeley) 1/21/94
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $FreeBSD$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TIMECONV_H_
|
||||||
|
#define _TIMECONV_H_
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
time_t _time32_to_time(int32_t t32);
|
||||||
|
int32_t _time_to_time32(time_t t);
|
||||||
|
time_t _time64_to_time(int64_t t64);
|
||||||
|
int64_t _time_to_time64(time_t t);
|
||||||
|
long _time_to_long(time_t t);
|
||||||
|
time_t _long_to_time(long tlong);
|
||||||
|
int _time_to_int(time_t t);
|
||||||
|
time_t _int_to_time(int tint);
|
||||||
|
|
||||||
|
#endif /* _TIMECONV_H_ */
|
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2008, 2009 Guillem Jover
|
* Copyright © 2006 Robert Millan
|
||||||
|
* 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
|
||||||
@@ -24,6 +25,12 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LIBBSD_UNISTD_H
|
#ifndef LIBBSD_UNISTD_H
|
||||||
#define LIBBSD_UNISTD_H
|
#define LIBBSD_UNISTD_H
|
||||||
|
|
||||||
@@ -35,10 +42,27 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
extern int optreset;
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#undef getopt
|
||||||
|
#define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Compatibility with sendmail implementations. */
|
||||||
|
#define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))
|
||||||
|
|
||||||
|
void setproctitle_init(int argc, char *argv[], char *envp[]);
|
||||||
void setproctitle(const char *fmt, ...);
|
void setproctitle(const char *fmt, ...);
|
||||||
|
|
||||||
|
int getpeereid(int s, uid_t *euid, gid_t *egid);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover
|
* Copyright © 2012-2013 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -24,12 +24,32 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_CDEFS_H
|
#if defined(__need_wchar_t) || defined(__need_wint_t) || \
|
||||||
#define LIBBSD_BSD_CDEFS_H
|
defined(__need_mbstate_t)
|
||||||
|
#define LIBBSD_WCHAR_H_SKIP
|
||||||
#warning "This header is deprecated, use the one in bsd/sys/cdefs.h instead."
|
|
||||||
|
|
||||||
#include <bsd/sys/cdefs.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <wchar.h>
|
||||||
|
#else
|
||||||
|
#include <wchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIBBSD_WCHAR_H_SKIP
|
||||||
|
#ifndef LIBBSD_WCHAR_H
|
||||||
|
#define LIBBSD_WCHAR_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
wchar_t *fgetwln(FILE *stream, size_t *len);
|
||||||
|
|
||||||
|
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
|
||||||
|
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#undef LIBBSD_WCHAR_H_SKIP
|
0
src/.gitignore → man/.gitignore
vendored
0
src/.gitignore → man/.gitignore
vendored
61
man/Makefile.am
Normal file
61
man/Makefile.am
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
## 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 \
|
||||||
|
fgetwln.3 \
|
||||||
|
flopen.3 \
|
||||||
|
fmtcheck.3 \
|
||||||
|
fparseln.3 \
|
||||||
|
funopen.3 \
|
||||||
|
getbsize.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 \
|
||||||
|
stringlist.3 \
|
||||||
|
strlcat.3 \
|
||||||
|
strlcpy.3 \
|
||||||
|
strnstr.3 \
|
||||||
|
strmode.3 \
|
||||||
|
strtonum.3 \
|
||||||
|
tree.3 \
|
||||||
|
unvis.3 \
|
||||||
|
vis.3 \
|
||||||
|
wcslcat.3 \
|
||||||
|
wcslcpy.3 \
|
||||||
|
$(nil)
|
@@ -44,7 +44,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In bsd/stdlib.h
|
||||||
.Ft u_int32_t
|
.Ft u_int32_t
|
||||||
.Fn arc4random "void"
|
.Fn arc4random "void"
|
||||||
.Ft void
|
.Ft void
|
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 .
|
@@ -38,7 +38,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In bsd/stdio.h
|
||||||
.Ft char *
|
.Ft char *
|
||||||
.Fn fgetln "FILE *stream" "size_t *len"
|
.Fn fgetln "FILE *stream" "size_t *len"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
117
man/fgetwln.3
Normal file
117
man/fgetwln.3
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd July 16, 2004
|
||||||
|
.Dt FGETWLN 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm fgetwln
|
||||||
|
.Nd get a line of wide characters from a stream
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In stdio.h
|
||||||
|
.In bsd/wchar.h
|
||||||
|
.Ft wchar_t *
|
||||||
|
.Fn fgetwln "FILE * restrict stream" "size_t * restrict len"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn fgetwln
|
||||||
|
function
|
||||||
|
returns a pointer to the next line from the stream referenced by
|
||||||
|
.Fa stream .
|
||||||
|
This line is
|
||||||
|
.Em not
|
||||||
|
a standard wide character string as it does not end with a terminating
|
||||||
|
null wide character.
|
||||||
|
The length of the line, including the final newline,
|
||||||
|
is stored in the memory location to which
|
||||||
|
.Fa len
|
||||||
|
points.
|
||||||
|
(Note, however, that if the line is the last
|
||||||
|
in a file that does not end in a newline,
|
||||||
|
the returned text will not contain a newline.)
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
Upon successful completion a pointer is returned;
|
||||||
|
this pointer becomes invalid after the next
|
||||||
|
.Tn I/O
|
||||||
|
operation on
|
||||||
|
.Fa stream
|
||||||
|
(whether successful or not)
|
||||||
|
or as soon as the stream is closed.
|
||||||
|
Otherwise,
|
||||||
|
.Dv NULL
|
||||||
|
is returned.
|
||||||
|
The
|
||||||
|
.Fn fgetwln
|
||||||
|
function
|
||||||
|
does not distinguish between end-of-file and error; the routines
|
||||||
|
.Xr feof 3
|
||||||
|
and
|
||||||
|
.Xr ferror 3
|
||||||
|
must be used
|
||||||
|
to determine which occurred.
|
||||||
|
If an error occurs, the global variable
|
||||||
|
.Va errno
|
||||||
|
is set to indicate the error.
|
||||||
|
The end-of-file condition is remembered, even on a terminal, and all
|
||||||
|
subsequent attempts to read will return
|
||||||
|
.Dv NULL
|
||||||
|
until the condition is
|
||||||
|
cleared with
|
||||||
|
.Xr clearerr 3 .
|
||||||
|
.Pp
|
||||||
|
The text to which the returned pointer points may be modified,
|
||||||
|
provided that no changes are made beyond the returned size.
|
||||||
|
These changes are lost as soon as the pointer becomes invalid.
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EBADF
|
||||||
|
The argument
|
||||||
|
.Fa stream
|
||||||
|
is not a stream open for reading.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn fgetwln
|
||||||
|
function
|
||||||
|
may also fail and set
|
||||||
|
.Va errno
|
||||||
|
for any of the errors specified for the routines
|
||||||
|
.Xr mbrtowc 3 ,
|
||||||
|
.Xr realloc 3 ,
|
||||||
|
or
|
||||||
|
.Xr read 2 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr ferror 3 ,
|
||||||
|
.Xr fgetln 3 ,
|
||||||
|
.Xr fgetws 3 ,
|
||||||
|
.Xr fopen 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,13 +30,13 @@
|
|||||||
.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
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In sys/fcntl.h
|
.In sys/fcntl.h
|
||||||
.In libutil.h
|
.In bsd/libutil.h
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn flopen "const char *path" "int flags"
|
.Fn flopen "const char *path" "int flags"
|
||||||
.Ft int
|
.Ft int
|
||||||
@@ -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
|
@@ -37,7 +37,7 @@ format string
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdio.h
|
.In bsd/stdio.h
|
||||||
.Ft const char *
|
.Ft const char *
|
||||||
.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
|
.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
149
man/fparseln.3
Normal file
149
man/fparseln.3
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
.\" $NetBSD: fparseln.3,v 1.4 2009/10/21 01:07:45 snj Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1997 Christos Zoulas. 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 ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.Dd November 30, 2002
|
||||||
|
.Dt FPARSELN 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm fparseln
|
||||||
|
.Nd return the next logical line from a stream
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdio.h
|
||||||
|
.Ft "char *"
|
||||||
|
.Fo "fparseln"
|
||||||
|
.Fa "FILE *stream" "size_t *len" "size_t *lineno"
|
||||||
|
.Fa "const char delim[3]" "int flags"
|
||||||
|
.Fc
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn fparseln
|
||||||
|
function
|
||||||
|
returns a pointer to the next logical line from the stream referenced by
|
||||||
|
.Fa stream .
|
||||||
|
This string is
|
||||||
|
.Dv NUL
|
||||||
|
terminated and it is dynamically allocated on each invocation.
|
||||||
|
It is the responsibility of the caller to free the pointer.
|
||||||
|
.Pp
|
||||||
|
By default, if a character is escaped, both it and the preceding escape
|
||||||
|
character will be present in the returned string.
|
||||||
|
Various
|
||||||
|
.Fa flags
|
||||||
|
alter this behaviour.
|
||||||
|
.Pp
|
||||||
|
The meaning of the arguments is as follows:
|
||||||
|
.Bl -tag -width "lineno"
|
||||||
|
.It Fa stream
|
||||||
|
The stream to read from.
|
||||||
|
.It Fa len
|
||||||
|
If not
|
||||||
|
.Dv NULL ,
|
||||||
|
the length of the string is stored in the memory location to which it
|
||||||
|
points.
|
||||||
|
.It Fa lineno
|
||||||
|
If not
|
||||||
|
.Dv NULL ,
|
||||||
|
the value of the memory location to which is pointed to, is incremented
|
||||||
|
by the number of lines actually read from the file.
|
||||||
|
.It Fa delim
|
||||||
|
Contains the escape, continuation, and comment characters.
|
||||||
|
If a character is
|
||||||
|
.Dv NUL
|
||||||
|
then processing for that character is disabled.
|
||||||
|
If
|
||||||
|
.Dv NULL ,
|
||||||
|
all characters default to values specified below.
|
||||||
|
The contents of
|
||||||
|
.Fa delim
|
||||||
|
is as follows:
|
||||||
|
.Bl -tag -width "delim[0]"
|
||||||
|
.It Fa delim[0]
|
||||||
|
The escape character, which defaults to
|
||||||
|
.Cm \e ,
|
||||||
|
is used to remove any special meaning from the next character.
|
||||||
|
.It Fa delim[1]
|
||||||
|
The continuation character, which defaults to
|
||||||
|
.Cm \e ,
|
||||||
|
is used to indicate that the next line should be concatenated with the
|
||||||
|
current one if this character is the last character on the current line
|
||||||
|
and is not escaped.
|
||||||
|
.It Fa delim[2]
|
||||||
|
The comment character, which defaults to
|
||||||
|
.Cm # ,
|
||||||
|
if not escaped indicates the beginning of a comment that extends until the
|
||||||
|
end of the current line.
|
||||||
|
.El
|
||||||
|
.It Fa flags
|
||||||
|
If non-zero, alter the operation of
|
||||||
|
.Fn fparseln .
|
||||||
|
The various flags, which may be
|
||||||
|
.Em or Ns -ed
|
||||||
|
together, are:
|
||||||
|
.Bl -tag -width "FPARSELN_UNESCCOMM"
|
||||||
|
.It Dv FPARSELN_UNESCCOMM
|
||||||
|
Remove escape preceding an escaped comment.
|
||||||
|
.It Dv FPARSELN_UNESCCONT
|
||||||
|
Remove escape preceding an escaped continuation.
|
||||||
|
.It Dv FPARSELN_UNESCESC
|
||||||
|
Remove escape preceding an escaped escape.
|
||||||
|
.It Dv FPARSELN_UNESCREST
|
||||||
|
Remove escape preceding any other character.
|
||||||
|
.It Dv FPARSELN_UNESCALL
|
||||||
|
All of the above.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
.El
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
Upon successful completion a pointer to the parsed line is returned;
|
||||||
|
otherwise,
|
||||||
|
.Dv NULL
|
||||||
|
is returned.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn fparseln
|
||||||
|
function uses internally
|
||||||
|
.Xr fgetln 3 ,
|
||||||
|
so all error conditions that apply to
|
||||||
|
.Xr fgetln 3 ,
|
||||||
|
apply to
|
||||||
|
.Fn fparseln .
|
||||||
|
In addition
|
||||||
|
.Fn fparseln
|
||||||
|
may set
|
||||||
|
.Va errno
|
||||||
|
to
|
||||||
|
.Bq Er ENOMEM
|
||||||
|
and return
|
||||||
|
.Dv NULL
|
||||||
|
if it runs out of memory.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr fgetln 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn fparseln
|
||||||
|
function first appeared in
|
||||||
|
.Nx 1.4 .
|
191
man/funopen.3
Normal file
191
man/funopen.3
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek.
|
||||||
|
.\" 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.
|
||||||
|
.\"
|
||||||
|
.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd March 19, 2004
|
||||||
|
.Dt FUNOPEN 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm funopen ,
|
||||||
|
.Nm fropen ,
|
||||||
|
.Nm fwopen
|
||||||
|
.Nd open a stream
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdio.h
|
||||||
|
.Ft FILE *
|
||||||
|
.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "off_t (*seekfn)(void *, off_t, int)" "int (*closefn)(void *)"
|
||||||
|
.Ft FILE *
|
||||||
|
.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
|
||||||
|
.Ft FILE *
|
||||||
|
.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn funopen
|
||||||
|
function
|
||||||
|
associates a stream with up to four
|
||||||
|
.Dq Tn I/O No functions .
|
||||||
|
Either
|
||||||
|
.Fa readfn
|
||||||
|
or
|
||||||
|
.Fa writefn
|
||||||
|
must be specified;
|
||||||
|
the others can be given as an appropriately-typed
|
||||||
|
.Dv NULL
|
||||||
|
pointer.
|
||||||
|
These
|
||||||
|
.Tn I/O
|
||||||
|
functions will be used to read, write, seek and
|
||||||
|
close the new stream.
|
||||||
|
.Pp
|
||||||
|
In general, omitting a function means that any attempt to perform the
|
||||||
|
associated operation on the resulting stream will fail.
|
||||||
|
If the close function is omitted, closing the stream will flush
|
||||||
|
any buffered output and then succeed.
|
||||||
|
.Pp
|
||||||
|
The calling conventions of
|
||||||
|
.Fa readfn ,
|
||||||
|
.Fa writefn ,
|
||||||
|
.Fa seekfn
|
||||||
|
and
|
||||||
|
.Fa closefn
|
||||||
|
must match those, respectively, of
|
||||||
|
.Xr read 2 ,
|
||||||
|
.Xr write 2 ,
|
||||||
|
.Xr lseek 2 ,
|
||||||
|
and
|
||||||
|
.Xr close 2
|
||||||
|
with the single exception that they are passed the
|
||||||
|
.Fa cookie
|
||||||
|
argument specified to
|
||||||
|
.Fn funopen
|
||||||
|
in place of the traditional file descriptor argument.
|
||||||
|
.Pp
|
||||||
|
Read and write
|
||||||
|
.Tn I/O
|
||||||
|
functions are allowed to change the underlying buffer
|
||||||
|
on fully buffered or line buffered streams by calling
|
||||||
|
.Xr setvbuf 3 .
|
||||||
|
They are also not required to completely fill or empty the buffer.
|
||||||
|
They are not, however, allowed to change streams from unbuffered to buffered
|
||||||
|
or to change the state of the line buffering flag.
|
||||||
|
They must also be prepared to have read or write calls occur on buffers other
|
||||||
|
than the one most recently specified.
|
||||||
|
.Pp
|
||||||
|
All user
|
||||||
|
.Tn I/O
|
||||||
|
functions can report an error by returning \-1.
|
||||||
|
Additionally, all of the functions should set the external variable
|
||||||
|
.Va errno
|
||||||
|
appropriately if an error occurs.
|
||||||
|
.Pp
|
||||||
|
An error on
|
||||||
|
.Fn closefn
|
||||||
|
does not keep the stream open.
|
||||||
|
.Pp
|
||||||
|
As a convenience, the include file
|
||||||
|
.In stdio.h
|
||||||
|
defines the macros
|
||||||
|
.Fn fropen
|
||||||
|
and
|
||||||
|
.Fn fwopen
|
||||||
|
as calls to
|
||||||
|
.Fn funopen
|
||||||
|
with only a read or write function specified.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
Upon successful completion,
|
||||||
|
.Fn funopen
|
||||||
|
returns a
|
||||||
|
.Dv FILE
|
||||||
|
pointer.
|
||||||
|
Otherwise,
|
||||||
|
.Dv NULL
|
||||||
|
is returned and the global variable
|
||||||
|
.Va errno
|
||||||
|
is set to indicate the error.
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The
|
||||||
|
.Fn funopen
|
||||||
|
function
|
||||||
|
was called without either a read or write function.
|
||||||
|
The
|
||||||
|
.Fn funopen
|
||||||
|
function
|
||||||
|
may also fail and set
|
||||||
|
.Va errno
|
||||||
|
for any of the errors
|
||||||
|
specified for the routine
|
||||||
|
.Xr malloc 3 .
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr fcntl 2 ,
|
||||||
|
.Xr open 2 ,
|
||||||
|
.Xr fclose 3 ,
|
||||||
|
.Xr fopen 3 ,
|
||||||
|
.Xr fseek 3 ,
|
||||||
|
.Xr setbuf 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn funopen
|
||||||
|
functions first appeared in
|
||||||
|
.Bx 4.4 .
|
||||||
|
.Sh BUGS
|
||||||
|
The
|
||||||
|
.Fn funopen
|
||||||
|
function
|
||||||
|
may not be portable to systems other than
|
||||||
|
.Bx .
|
||||||
|
.Pp
|
||||||
|
On
|
||||||
|
.Fx ,
|
||||||
|
.Ox
|
||||||
|
and
|
||||||
|
.Dx
|
||||||
|
the
|
||||||
|
.Fn funopen
|
||||||
|
interface erroneously assumes that
|
||||||
|
.Vt fpos_t
|
||||||
|
is an integral type, and uses it in the
|
||||||
|
.Fa seekfn
|
||||||
|
hook; but because code using a
|
||||||
|
.Fa seekfn
|
||||||
|
hook will fail to build on systems where
|
||||||
|
.Vt fpos_t
|
||||||
|
is a struct, and it will need to be slightly fixed anyway, the
|
||||||
|
implementation provided by libbsd (in the same way as
|
||||||
|
.Nx )
|
||||||
|
uses the correct
|
||||||
|
.Vt off_t
|
||||||
|
types.
|
95
man/getbsize.3
Normal file
95
man/getbsize.3
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
.\" Copyright (c) 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd November 16, 2012
|
||||||
|
.Dt GETBSIZE 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm getbsize
|
||||||
|
.Nd get preferred block size
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdlib.h
|
||||||
|
.Ft char *
|
||||||
|
.Fn getbsize "int *headerlenp" "long *blocksizep"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn getbsize
|
||||||
|
function returns a preferred block size for reporting by system utilities
|
||||||
|
.Xr df 1 ,
|
||||||
|
.Xr du 1 ,
|
||||||
|
.Xr ls 1
|
||||||
|
and
|
||||||
|
.Xr systat 1 ,
|
||||||
|
based on the value of the
|
||||||
|
.Ev BLOCKSIZE
|
||||||
|
environment variable.
|
||||||
|
.Ev BLOCKSIZE
|
||||||
|
may be specified directly in bytes, or in multiples of a kilobyte by
|
||||||
|
specifying a number followed by ``K'' or ``k'', in multiples of a
|
||||||
|
megabyte by specifying a number followed by ``M'' or ``m'' or in
|
||||||
|
multiples of a gigabyte by specifying a number followed by ``G'' or
|
||||||
|
``g''.
|
||||||
|
Multiples must be integers.
|
||||||
|
.Pp
|
||||||
|
Valid values of
|
||||||
|
.Ev BLOCKSIZE
|
||||||
|
are 512 bytes to 1 gigabyte.
|
||||||
|
Sizes less than 512 bytes are rounded up to 512 bytes, and sizes
|
||||||
|
greater than 1 GB are rounded down to 1 GB.
|
||||||
|
In each case
|
||||||
|
.Fn getbsize
|
||||||
|
produces a warning message.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn getbsize
|
||||||
|
function returns a pointer to a null-terminated string describing
|
||||||
|
the block size, something like
|
||||||
|
.Dq 1K-blocks .
|
||||||
|
The memory referenced by
|
||||||
|
.Fa headerlenp
|
||||||
|
is filled in with the length of the string (not including the
|
||||||
|
terminating null).
|
||||||
|
The memory referenced by
|
||||||
|
.Fa blocksizep
|
||||||
|
is filled in with block size, in bytes.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr df 1 ,
|
||||||
|
.Xr du 1 ,
|
||||||
|
.Xr ls 1 ,
|
||||||
|
.Xr systat 1 ,
|
||||||
|
.Xr environ 7
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn getbsize
|
||||||
|
function first appeared in
|
||||||
|
.Bx 4.4 .
|
138
man/getpeereid.3
Normal file
138
man/getpeereid.3
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
.\"
|
||||||
|
.\" Copyright (c) 2001 Dima Dorfman.
|
||||||
|
.\" 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 July 15, 2001
|
||||||
|
.Dt GETPEEREID 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm getpeereid
|
||||||
|
.Nd get the effective credentials of a UNIX-domain peer
|
||||||
|
.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 int
|
||||||
|
.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn getpeereid
|
||||||
|
function returns the effective user and group IDs of the
|
||||||
|
peer connected to a
|
||||||
|
.Ux Ns -domain
|
||||||
|
socket.
|
||||||
|
The argument
|
||||||
|
.Fa s
|
||||||
|
must be a
|
||||||
|
.Ux Ns -domain
|
||||||
|
socket
|
||||||
|
.Pq Xr unix 4
|
||||||
|
of type
|
||||||
|
.Dv SOCK_STREAM
|
||||||
|
on which either
|
||||||
|
.Xr connect 2
|
||||||
|
or
|
||||||
|
.Xr listen 2
|
||||||
|
have been called.
|
||||||
|
The effective used ID is placed in
|
||||||
|
.Fa euid ,
|
||||||
|
and the effective group ID in
|
||||||
|
.Fa egid .
|
||||||
|
.Pp
|
||||||
|
The credentials returned to the
|
||||||
|
.Xr listen 2
|
||||||
|
caller are those of its peer at the time it called
|
||||||
|
.Xr connect 2 ;
|
||||||
|
the credentials returned to the
|
||||||
|
.Xr connect 2
|
||||||
|
caller are those of its peer at the time it called
|
||||||
|
.Xr listen 2 .
|
||||||
|
This mechanism is reliable; there is no way for either side to influence
|
||||||
|
the credentials returned to its peer except by calling the appropriate
|
||||||
|
system call (i.e., either
|
||||||
|
.Xr connect 2
|
||||||
|
or
|
||||||
|
.Xr listen 2 )
|
||||||
|
under different effective credentials.
|
||||||
|
.Pp
|
||||||
|
One common use of this routine is for a
|
||||||
|
.Ux Ns -domain
|
||||||
|
server
|
||||||
|
to verify the credentials of its client.
|
||||||
|
Likewise, the client can verify the credentials of the server.
|
||||||
|
.Sh IMPLEMENTATION NOTES
|
||||||
|
On
|
||||||
|
.Fx ,
|
||||||
|
.Fn getpeereid
|
||||||
|
is implemented in terms of the
|
||||||
|
.Dv LOCAL_PEERCRED
|
||||||
|
.Xr unix 4
|
||||||
|
socket option.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
.Rv -std getpeereid
|
||||||
|
.Sh ERRORS
|
||||||
|
The
|
||||||
|
.Fn getpeereid
|
||||||
|
function
|
||||||
|
fails if:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EBADF
|
||||||
|
The argument
|
||||||
|
.Fa s
|
||||||
|
is not a valid descriptor.
|
||||||
|
.It Bq Er ENOTSOCK
|
||||||
|
The argument
|
||||||
|
.Fa s
|
||||||
|
is a file, not a socket.
|
||||||
|
.It Bq Er ENOTCONN
|
||||||
|
The argument
|
||||||
|
.Fa s
|
||||||
|
does not refer to a socket on which
|
||||||
|
.Xr connect 2
|
||||||
|
or
|
||||||
|
.Xr listen 2
|
||||||
|
have been called.
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The argument
|
||||||
|
.Fa s
|
||||||
|
does not refer to a socket of type
|
||||||
|
.Dv SOCK_STREAM ,
|
||||||
|
or the kernel returned invalid data.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr connect 2 ,
|
||||||
|
.Xr getpeername 2 ,
|
||||||
|
.Xr getsockname 2 ,
|
||||||
|
.Xr getsockopt 2 ,
|
||||||
|
.Xr listen 2 ,
|
||||||
|
.Xr unix 4
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn getpeereid
|
||||||
|
function appeared in
|
||||||
|
.Fx 4.6 .
|
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 .
|
208
man/heapsort.3
Normal file
208
man/heapsort.3
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" the American National Standards Committee X3, on Information
|
||||||
|
.\" Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 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.
|
||||||
|
.\"
|
||||||
|
.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd September 30, 2003
|
||||||
|
.Dt QSORT 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm heapsort , mergesort
|
||||||
|
.Nd sort functions
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdlib.h
|
||||||
|
.Ft int
|
||||||
|
.Fo heapsort
|
||||||
|
.Fa "void *base"
|
||||||
|
.Fa "size_t nmemb"
|
||||||
|
.Fa "size_t size"
|
||||||
|
.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
|
||||||
|
.Fc
|
||||||
|
.Ft int
|
||||||
|
.Fo mergesort
|
||||||
|
.Fa "void *base"
|
||||||
|
.Fa "size_t nmemb"
|
||||||
|
.Fa "size_t size"
|
||||||
|
.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
|
||||||
|
.Fc
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn heapsort
|
||||||
|
function is a modified selection sort.
|
||||||
|
The
|
||||||
|
.Fn mergesort
|
||||||
|
function is a modified merge sort with exponential search
|
||||||
|
intended for sorting data with pre-existing order.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn heapsort
|
||||||
|
function sorts an array of
|
||||||
|
.Fa nmemb
|
||||||
|
objects, the initial member of which is pointed to by
|
||||||
|
.Fa base .
|
||||||
|
The size of each object is specified by
|
||||||
|
.Fa size .
|
||||||
|
The
|
||||||
|
.Fn mergesort
|
||||||
|
function
|
||||||
|
behaves similarly, but
|
||||||
|
.Em requires
|
||||||
|
that
|
||||||
|
.Fa size
|
||||||
|
be greater than
|
||||||
|
.Dq "sizeof(void *) / 2" .
|
||||||
|
.Pp
|
||||||
|
The contents of the array
|
||||||
|
.Fa base
|
||||||
|
are sorted in ascending order according to
|
||||||
|
a comparison function pointed to by
|
||||||
|
.Fa compar ,
|
||||||
|
which requires two arguments pointing to the objects being
|
||||||
|
compared.
|
||||||
|
.Pp
|
||||||
|
The comparison function must return an integer less than, equal to, or
|
||||||
|
greater than zero if the first argument is considered to be respectively
|
||||||
|
less than, equal to, or greater than the second.
|
||||||
|
.Pp
|
||||||
|
The algorithm implemented by
|
||||||
|
.Fn heapsort
|
||||||
|
is
|
||||||
|
.Em not
|
||||||
|
stable, that is, if two members compare as equal, their order in
|
||||||
|
the sorted array is undefined.
|
||||||
|
The
|
||||||
|
.Fn mergesort
|
||||||
|
algorithm is stable.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn heapsort
|
||||||
|
function is an implementation of
|
||||||
|
.An "J.W.J. William" Ns 's
|
||||||
|
.Dq heapsort
|
||||||
|
algorithm,
|
||||||
|
a variant of selection sorting; in particular, see
|
||||||
|
.An "D.E. Knuth" Ns 's
|
||||||
|
.%T "Algorithm H" .
|
||||||
|
.Sy Heapsort
|
||||||
|
takes O N lg N worst-case time.
|
||||||
|
Its
|
||||||
|
.Em only
|
||||||
|
advantage over
|
||||||
|
.Fn qsort
|
||||||
|
is that it uses almost no additional memory; while
|
||||||
|
.Fn qsort
|
||||||
|
does not allocate memory, it is implemented using recursion.
|
||||||
|
.Pp
|
||||||
|
The function
|
||||||
|
.Fn mergesort
|
||||||
|
requires additional memory of size
|
||||||
|
.Fa nmemb *
|
||||||
|
.Fa size
|
||||||
|
bytes; it should be used only when space is not at a premium.
|
||||||
|
The
|
||||||
|
.Fn mergesort
|
||||||
|
function
|
||||||
|
is optimized for data with pre-existing order; its worst case
|
||||||
|
time is O N lg N; its best case is O N.
|
||||||
|
.Pp
|
||||||
|
Normally,
|
||||||
|
.Fn qsort
|
||||||
|
is faster than
|
||||||
|
.Fn mergesort
|
||||||
|
is faster than
|
||||||
|
.Fn heapsort .
|
||||||
|
Memory availability and pre-existing order in the data can make this
|
||||||
|
untrue.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
.Rv -std heapsort mergesort
|
||||||
|
.Sh ERRORS
|
||||||
|
The
|
||||||
|
.Fn heapsort
|
||||||
|
and
|
||||||
|
.Fn mergesort
|
||||||
|
functions succeed unless:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The
|
||||||
|
.Fa size
|
||||||
|
argument is zero, or,
|
||||||
|
the
|
||||||
|
.Fa size
|
||||||
|
argument to
|
||||||
|
.Fn mergesort
|
||||||
|
is less than
|
||||||
|
.Dq "sizeof(void *) / 2" .
|
||||||
|
.It Bq Er ENOMEM
|
||||||
|
The
|
||||||
|
.Fn heapsort
|
||||||
|
or
|
||||||
|
.Fn mergesort
|
||||||
|
functions
|
||||||
|
were unable to allocate memory.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr sort 1 ,
|
||||||
|
.Xr radixsort 3
|
||||||
|
.Rs
|
||||||
|
.%A Williams, J.W.J
|
||||||
|
.%D 1964
|
||||||
|
.%T "Heapsort"
|
||||||
|
.%J "Communications of the ACM"
|
||||||
|
.%V 7:1
|
||||||
|
.%P pp. 347-348
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%A Knuth, D.E.
|
||||||
|
.%D 1968
|
||||||
|
.%B "The Art of Computer Programming"
|
||||||
|
.%V Vol. 3
|
||||||
|
.%T "Sorting and Searching"
|
||||||
|
.%P pp. 114-123, 145-149
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%A McIlroy, P.M.
|
||||||
|
.%T "Optimistic Sorting and Information Theoretic Complexity"
|
||||||
|
.%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
|
||||||
|
.%V January 1992
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%A Bentley, J.L.
|
||||||
|
.%A McIlroy, M.D.
|
||||||
|
.%T "Engineering a Sort Function"
|
||||||
|
.%J "Software--Practice and Experience"
|
||||||
|
.%V Vol. 23(11)
|
||||||
|
.%P pp. 1249-1265
|
||||||
|
.%D November\ 1993
|
||||||
|
.Re
|
@@ -38,7 +38,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In bsd/stdlib.h
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn dehumanize_number "const char *str" "int64_t *result"
|
.Fn dehumanize_number "const char *str" "int64_t *result"
|
||||||
.Ft int
|
.Ft int
|
@@ -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 ,
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Fd #include <sys/types.h>
|
.Fd #include <sys/types.h>
|
||||||
.Fd #include <mdX.h>
|
.Fd #include <bsd/mdX.h>
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn MDXInit "MDX_CTX *context"
|
.Fn MDXInit "MDX_CTX *context"
|
||||||
.Ft void
|
.Ft void
|
1
man/mergesort.3
Normal file
1
man/mergesort.3
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/heapsort.3
|
@@ -38,7 +38,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In nlist.h
|
.In bsd/nlist.h
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn nlist "const char *filename" "struct nlist *nl"
|
.Fn nlist "const char *filename" "struct nlist *nl"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
@@ -32,12 +32,12 @@
|
|||||||
.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
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In libutil.h
|
.In bsd/libutil.h
|
||||||
.Ft "struct pidfh *"
|
.Ft "struct pidfh *"
|
||||||
.Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr"
|
.Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr"
|
||||||
.Ft int
|
.Ft int
|
||||||
@@ -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
168
man/radixsort.3
Normal file
168
man/radixsort.3
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
.\" $NetBSD: radixsort.3,v 1.12 2003/04/16 13:34:46 wiz Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
||||||
|
.\"
|
||||||
|
.Dd January 27, 1994
|
||||||
|
.Dt RADIXSORT 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm radixsort ,
|
||||||
|
.Nm sradixsort
|
||||||
|
.Nd radix sort
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In limits.h
|
||||||
|
.In bsd/stdlib.h
|
||||||
|
.Ft int
|
||||||
|
.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
|
||||||
|
.Ft int
|
||||||
|
.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn radixsort
|
||||||
|
and
|
||||||
|
.Fn sradixsort
|
||||||
|
functions
|
||||||
|
are implementations of radix sort.
|
||||||
|
.Pp
|
||||||
|
These functions sort an
|
||||||
|
.Fa nmemb
|
||||||
|
element array of pointers to byte strings, with
|
||||||
|
the initial member of which is referenced by
|
||||||
|
.Fa base .
|
||||||
|
The byte strings may contain any values.
|
||||||
|
End of strings is denoted
|
||||||
|
by character which has same weight as user specified value
|
||||||
|
.Fa endbyte .
|
||||||
|
.Fa endbyte
|
||||||
|
has to be between 0 and 255.
|
||||||
|
.Pp
|
||||||
|
Applications may specify a sort order by providing the
|
||||||
|
.Fa table
|
||||||
|
argument.
|
||||||
|
If
|
||||||
|
.Pf non- Dv NULL ,
|
||||||
|
.Fa table
|
||||||
|
must reference an array of
|
||||||
|
.Dv UCHAR_MAX
|
||||||
|
+ 1 bytes which contains the sort
|
||||||
|
weight of each possible byte value.
|
||||||
|
The end-of-string byte must have a sort weight of 0 or 255
|
||||||
|
(for sorting in reverse order).
|
||||||
|
More than one byte may have the same sort weight.
|
||||||
|
The
|
||||||
|
.Fa table
|
||||||
|
argument
|
||||||
|
is useful for applications which wish to sort different characters
|
||||||
|
equally, for example, providing a table with the same weights
|
||||||
|
for A-Z as for a-z will result in a case-insensitive sort.
|
||||||
|
If
|
||||||
|
.Fa table
|
||||||
|
is NULL, the contents of the array are sorted in ascending order
|
||||||
|
according to the
|
||||||
|
.Tn ASCII
|
||||||
|
order of the byte strings they reference and
|
||||||
|
.Fa endbyte
|
||||||
|
has a sorting weight of 0.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn sradixsort
|
||||||
|
function is stable, that is, if two elements compare as equal, their
|
||||||
|
order in the sorted array is unchanged.
|
||||||
|
The
|
||||||
|
.Fn sradixsort
|
||||||
|
function uses additional memory sufficient to hold
|
||||||
|
.Fa nmemb
|
||||||
|
pointers.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn radixsort
|
||||||
|
function is not stable, but uses no additional memory.
|
||||||
|
.Pp
|
||||||
|
These functions are variants of most-significant-byte radix sorting; in
|
||||||
|
particular, see
|
||||||
|
.An "D.E. Knuth" Ns 's
|
||||||
|
.%T "Algorithm R"
|
||||||
|
and section 5.2.5, exercise 10.
|
||||||
|
They take linear time relative to the number of bytes in the strings.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
.Rv -std radixsort
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The value of the
|
||||||
|
.Fa endbyte
|
||||||
|
element of
|
||||||
|
.Fa table
|
||||||
|
is not 0 or 255.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
Additionally, the
|
||||||
|
.Fn sradixsort
|
||||||
|
function
|
||||||
|
may fail and set
|
||||||
|
.Va errno
|
||||||
|
for any of the errors specified for the library routine
|
||||||
|
.Xr malloc 3 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr sort 1 ,
|
||||||
|
.Xr qsort 3
|
||||||
|
.Pp
|
||||||
|
.Rs
|
||||||
|
.%A Knuth, D.E.
|
||||||
|
.%D 1968
|
||||||
|
.%B "The Art of Computer Programming"
|
||||||
|
.%T "Sorting and Searching"
|
||||||
|
.%V Vol. 3
|
||||||
|
.%P pp. 170-178
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%A Paige, R.
|
||||||
|
.%D 1987
|
||||||
|
.%T "Three Partition Refinement Algorithms"
|
||||||
|
.%J "SIAM J. Comput."
|
||||||
|
.%V Vol. 16
|
||||||
|
.%N No. 6
|
||||||
|
.Re
|
||||||
|
.Rs
|
||||||
|
.%A McIlroy, P.
|
||||||
|
.%D 1993
|
||||||
|
.%B "Engineering Radix Sort"
|
||||||
|
.%T "Computing Systems"
|
||||||
|
.%V Vol. 6:1
|
||||||
|
.%P pp. 5-27
|
||||||
|
.Re
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn radixsort
|
||||||
|
function first appeared in
|
||||||
|
.Bx 4.4 .
|
@@ -28,7 +28,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Fd #include <readpassphrase.h>
|
.Fd #include <bsd/readpassphrase.h>
|
||||||
.Ft char *
|
.Ft char *
|
||||||
.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
|
.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
107
man/reallocf.3
Normal file
107
man/reallocf.3
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
.\" Copyright (c) 1980, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" the American National Standards Committee X3, on Information
|
||||||
|
.\" Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" @(#)malloc.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
|
||||||
|
.\"
|
||||||
|
.Dd September 26, 2009
|
||||||
|
.Dt MALLOC 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm reallocf
|
||||||
|
.Nd general purpose memory allocation functions
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stdlib.h
|
||||||
|
.Ft void *
|
||||||
|
.Fn reallocf "void *ptr" "size_t size"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn reallocf
|
||||||
|
function changes the size of the previously allocated memory referenced by
|
||||||
|
.Fa ptr
|
||||||
|
to
|
||||||
|
.Fa size
|
||||||
|
bytes.
|
||||||
|
The contents of the memory are unchanged up to the lesser of the new and
|
||||||
|
old sizes.
|
||||||
|
If the new size is larger,
|
||||||
|
the contents of the newly allocated portion of the memory are undefined.
|
||||||
|
Upon success, the memory referenced by
|
||||||
|
.Fa ptr
|
||||||
|
is freed and a pointer to the newly allocated memory is returned.
|
||||||
|
Note that
|
||||||
|
.Fn reallocf
|
||||||
|
may move the memory allocation, resulting in a different return value than
|
||||||
|
.Fa ptr .
|
||||||
|
If
|
||||||
|
.Fa ptr
|
||||||
|
is
|
||||||
|
.Dv NULL ,
|
||||||
|
the
|
||||||
|
.Fn reallocf
|
||||||
|
function behaves identically to
|
||||||
|
.Fn malloc
|
||||||
|
for the specified size.
|
||||||
|
Upon failure, when the requested memory cannot be allocated, the passed pointer
|
||||||
|
is freed to ease the problems with traditional coding styles for
|
||||||
|
.Fn reallocf
|
||||||
|
causing memory leaks in libraries.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
The
|
||||||
|
.Fn reallocf
|
||||||
|
function returns a pointer, possibly identical to
|
||||||
|
.Fa ptr ,
|
||||||
|
to the allocated memory
|
||||||
|
if successful; otherwise a
|
||||||
|
.Dv NULL
|
||||||
|
pointer is returned, and
|
||||||
|
.Va errno
|
||||||
|
is set to
|
||||||
|
.Er ENOMEM
|
||||||
|
if the error was the result of an allocation failure.
|
||||||
|
The buffer is deallocated in this case.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr brk 2 ,
|
||||||
|
.Xr mmap 2 ,
|
||||||
|
.Xr alloca 3 ,
|
||||||
|
.Xr calloc 3 ,
|
||||||
|
.Xr free 3 ,
|
||||||
|
.Xr malloc 3 ,
|
||||||
|
.Xr posix_memalign 3 ,
|
||||||
|
.Xr realloc 3 ,
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn reallocf
|
||||||
|
function first appeared in
|
||||||
|
.Fx 3.0 .
|
@@ -1,3 +1,5 @@
|
|||||||
|
.\" $NetBSD: setmode.3,v 1.18.28.1 2009/01/04 17:02:19 christos Exp $
|
||||||
|
.\"
|
||||||
.\" Copyright (c) 1989, 1991, 1993
|
.\" Copyright (c) 1989, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
@@ -9,7 +11,7 @@
|
|||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
.\" 4. Neither the name of the University nor the names of its contributors
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
.\" may be used to endorse or promote products derived from this software
|
.\" may be used to endorse or promote products derived from this software
|
||||||
.\" without specific prior written permission.
|
.\" without specific prior written permission.
|
||||||
.\"
|
.\"
|
||||||
@@ -28,7 +30,7 @@
|
|||||||
.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
|
.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
|
||||||
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 28, 1995
|
.Dd January 4, 2009
|
||||||
.Dt SETMODE 3
|
.Dt SETMODE 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -39,35 +41,41 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In unistd.h
|
.In bsd/unistd.h
|
||||||
.Ft mode_t
|
|
||||||
.Fn getmode "const void *set" "mode_t mode"
|
|
||||||
.Ft void *
|
.Ft void *
|
||||||
.Fn setmode "const char *mode_str"
|
.Fn setmode "const char *mode_str"
|
||||||
|
.Ft mode_t
|
||||||
|
.Fn getmode "const void *set" "mode_t mode"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
|
.Fn setmode
|
||||||
|
function accepts a string representation of a file mode change,
|
||||||
|
compiles it to binary form, and returns an abstract representation
|
||||||
|
that may be passed to
|
||||||
|
.Fn getmode .
|
||||||
|
The string may be an numeric (octal) or symbolic string of the form
|
||||||
|
accepted by
|
||||||
|
.Xr chmod 1 ,
|
||||||
|
and may represent either an exact mode to set or a change to make to
|
||||||
|
the existing mode.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
.Fn getmode
|
.Fn getmode
|
||||||
function
|
function
|
||||||
returns a copy of the file permission bits
|
adjusts the file permission bits given by
|
||||||
.Fa mode
|
.Fa mode
|
||||||
as altered by the values pointed to by
|
according to the compiled change representation
|
||||||
.Fa set .
|
.Fa set ,
|
||||||
While only the mode bits are altered, other parts of the file mode
|
and returns the adjusted mode.
|
||||||
may be examined.
|
While only the permission bits are altered, other parts of the file
|
||||||
|
mode, particularly the type, may be examined.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
Because some of the possible symbolic values are defined relative to
|
||||||
.Fn setmode
|
the file creation mask,
|
||||||
function
|
|
||||||
takes an absolute (octal) or symbolic value, as described in
|
|
||||||
.Xr chmod 1 ,
|
|
||||||
as an argument
|
|
||||||
and returns a pointer to mode values to be supplied to
|
|
||||||
.Fn getmode .
|
|
||||||
Because some of the symbolic values are relative to the file
|
|
||||||
creation mask,
|
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
may call
|
may call
|
||||||
.Xr umask 2 .
|
.Xr umask 2 ,
|
||||||
|
temporarily changing the mask.
|
||||||
If this occurs, the file creation mask will be restored before
|
If this occurs, the file creation mask will be restored before
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
returns.
|
returns.
|
||||||
@@ -75,13 +83,13 @@ If the calling program changes the value of its file creation mask
|
|||||||
after calling
|
after calling
|
||||||
.Fn setmode ,
|
.Fn setmode ,
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
must be called again if
|
must be called again to recompile the mode string if
|
||||||
.Fn getmode
|
.Fn getmode
|
||||||
is to modify future file modes correctly.
|
is to modify future file modes correctly.
|
||||||
.Pp
|
.Pp
|
||||||
If the mode passed to
|
If the mode passed to
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
is invalid or if memory cannot be allocated for the return value,
|
is invalid,
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
returns
|
returns
|
||||||
.Dv NULL .
|
.Dv NULL .
|
||||||
@@ -94,13 +102,40 @@ and should be returned to the system with
|
|||||||
.Fn free
|
.Fn free
|
||||||
when the program is done with it, generally after a call to
|
when the program is done with it, generally after a call to
|
||||||
.Fn getmode .
|
.Fn getmode .
|
||||||
|
.Sh EXAMPLES
|
||||||
|
The effects of the shell command
|
||||||
|
.Ql "chmod a+x myscript.sh"
|
||||||
|
can be duplicated as follows:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
const char *file = "myscript.sh";
|
||||||
|
struct stat st;
|
||||||
|
mode_t newmode;
|
||||||
|
|
||||||
|
stat(file, \*[Am]st);
|
||||||
|
newmode = getmode(setmode("a+x"), st.st_mode);
|
||||||
|
chmod(file, newmode);
|
||||||
|
.Ed
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
The
|
The
|
||||||
.Fn setmode
|
.Fn setmode
|
||||||
function
|
function
|
||||||
may fail and set errno for any of the errors specified for the library
|
may fail and set
|
||||||
routine
|
.Va errno
|
||||||
.Xr malloc 3 .
|
for any of the errors specified for the library routines
|
||||||
|
.Xr malloc 3
|
||||||
|
or
|
||||||
|
.Xr strtol 3 .
|
||||||
|
In addition,
|
||||||
|
.Fn setmode
|
||||||
|
will fail and set
|
||||||
|
.Va errno
|
||||||
|
to:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The
|
||||||
|
.Fa mode
|
||||||
|
argument does not represent a valid mode.
|
||||||
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr chmod 1 ,
|
.Xr chmod 1 ,
|
||||||
.Xr stat 2 ,
|
.Xr stat 2 ,
|
||||||
@@ -113,3 +148,9 @@ and
|
|||||||
.Fn setmode
|
.Fn setmode
|
||||||
functions first appeared in
|
functions first appeared in
|
||||||
.Bx 4.4 .
|
.Bx 4.4 .
|
||||||
|
.Sh BUGS
|
||||||
|
The type of
|
||||||
|
.Fa set
|
||||||
|
should really be some opaque struct type used only by these functions
|
||||||
|
rather than
|
||||||
|
.Ft void * .
|
140
man/setproctitle.3
Normal file
140
man/setproctitle.3
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
.\" 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_init "int argc" "char *argv[]" "char *envp[]"
|
||||||
|
.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
|
||||||
|
.Fn setproctitle_init
|
||||||
|
library routine only needs to be called (before any call to
|
||||||
|
.Fn setproctitle
|
||||||
|
and with
|
||||||
|
.Fn main
|
||||||
|
arguments), if the automatic constructor support has not
|
||||||
|
been linked in through the libbsd-ctor pkg-config file.
|
||||||
|
.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.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn setproctitle_init
|
||||||
|
function is a libbsd extension not present on the BSDs, avoid using it
|
||||||
|
in portable code.
|
||||||
|
.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
|
1
man/sradixsort.3
Normal file
1
man/sradixsort.3
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/radixsort.3
|
147
man/stringlist.3
Normal file
147
man/stringlist.3
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
.\" $NetBSD: stringlist.3,v 1.15 2010/05/06 09:46:49 jruoho Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
|
||||||
|
.\" All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.Dd May 6, 2010
|
||||||
|
.Dt STRINGLIST 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm stringlist ,
|
||||||
|
.Nm sl_init ,
|
||||||
|
.Nm sl_add ,
|
||||||
|
.Nm sl_free ,
|
||||||
|
.Nm sl_find ,
|
||||||
|
.Nm sl_delete
|
||||||
|
.Nd stringlist manipulation functions
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/stringlist.h
|
||||||
|
.Ft StringList *
|
||||||
|
.Fn sl_init "void"
|
||||||
|
.Ft int
|
||||||
|
.Fn sl_add "StringList *sl" "char *item"
|
||||||
|
.Ft void
|
||||||
|
.Fn sl_free "StringList *sl" "int freeall"
|
||||||
|
.Ft char *
|
||||||
|
.Fn sl_find "StringList *sl" "const char *item"
|
||||||
|
.Ft int
|
||||||
|
.Fn sl_delete "StringList *sl" "const char *item" "int freeit"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
functions manipulate stringlists, which are lists of
|
||||||
|
strings that extend automatically if necessary.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Ar StringList
|
||||||
|
structure has the following definition:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
typedef struct _stringlist {
|
||||||
|
char **sl_str;
|
||||||
|
size_t sl_max;
|
||||||
|
size_t sl_cur;
|
||||||
|
} StringList;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
where:
|
||||||
|
.Bl -tag -width "sl_str" -offset indent
|
||||||
|
.It Ar sl_str
|
||||||
|
is a pointer to the base of the array containing the list,
|
||||||
|
.It Ar sl_max
|
||||||
|
is the size of
|
||||||
|
.Ar sl_str ,
|
||||||
|
and
|
||||||
|
.It Ar sl_cur
|
||||||
|
is the offset in
|
||||||
|
.Ar sl_str
|
||||||
|
of the current element.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following stringlist manipulation functions are available:
|
||||||
|
.Bl -tag -width "sl_delete()" -offset 2n
|
||||||
|
.It Fn sl_init
|
||||||
|
Create a stringlist.
|
||||||
|
Returns a pointer to a
|
||||||
|
.Ar StringList ,
|
||||||
|
or
|
||||||
|
.Dv NULL
|
||||||
|
in case of failure.
|
||||||
|
.It Fn sl_free
|
||||||
|
Releases memory occupied by
|
||||||
|
.Ar sl
|
||||||
|
and the
|
||||||
|
.Ar sl-\*[Gt]sl_str
|
||||||
|
array.
|
||||||
|
If
|
||||||
|
.Ar freeall
|
||||||
|
is non-zero, then each of the items within
|
||||||
|
.Ar sl-\*[Gt]sl_str
|
||||||
|
is released as well.
|
||||||
|
.It Fn sl_add
|
||||||
|
Add
|
||||||
|
.Ar item
|
||||||
|
to
|
||||||
|
.Ar sl-\*[Gt]sl_str
|
||||||
|
at
|
||||||
|
.Ar sl-\*[Gt]sl_cur ,
|
||||||
|
extending the size of
|
||||||
|
.Ar sl-\*[Gt]sl_str .
|
||||||
|
Returns zero upon success, \-1 upon failure.
|
||||||
|
.It Fn sl_find
|
||||||
|
Find
|
||||||
|
.Ar item
|
||||||
|
in
|
||||||
|
.Ar sl ,
|
||||||
|
returning
|
||||||
|
.Dv NULL
|
||||||
|
if it's not found.
|
||||||
|
.It Fn sl_delete
|
||||||
|
Remove
|
||||||
|
.Ar item
|
||||||
|
from the list.
|
||||||
|
If
|
||||||
|
.Ar freeit
|
||||||
|
is non-zero, the string is freed.
|
||||||
|
Returns
|
||||||
|
.Dv 0
|
||||||
|
if the name is found
|
||||||
|
and
|
||||||
|
.Dv \-1
|
||||||
|
if the name is not found.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr free 3 ,
|
||||||
|
.Xr malloc 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
functions appeared in
|
||||||
|
.Fx 2.2.6
|
||||||
|
and
|
||||||
|
.Nx 1.3 .
|
@@ -25,7 +25,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In bsd/string.h
|
||||||
.Ft size_t
|
.Ft size_t
|
||||||
.Fn strlcpy "char *dst" "const char *src" "size_t size"
|
.Fn strlcpy "char *dst" "const char *src" "size_t size"
|
||||||
.Ft size_t
|
.Ft size_t
|
@@ -38,7 +38,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In string.h
|
.In bsd/string.h
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn strmode "mode_t mode" "char *bp"
|
.Fn strmode "mode_t mode" "char *bp"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
110
man/strnstr.3
Normal file
110
man/strnstr.3
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" @(#)strstr.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd October 11, 2001
|
||||||
|
.Dt STRSTR 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm strnstr
|
||||||
|
.Nd locate a substring in a string
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/string.h
|
||||||
|
.Ft char *
|
||||||
|
.Fn strnstr "const char *big" "const char *little" "size_t len"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn strnstr
|
||||||
|
function
|
||||||
|
locates the first occurrence of the null-terminated string
|
||||||
|
.Fa little
|
||||||
|
in the string
|
||||||
|
.Fa big ,
|
||||||
|
where not more than
|
||||||
|
.Fa len
|
||||||
|
characters are searched.
|
||||||
|
Characters that appear after a
|
||||||
|
.Ql \e0
|
||||||
|
character are not searched.
|
||||||
|
Since the
|
||||||
|
.Fn strnstr
|
||||||
|
function is a
|
||||||
|
.Fx
|
||||||
|
specific API, it should only be used when portability is not a concern.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
If
|
||||||
|
.Fa little
|
||||||
|
is an empty string,
|
||||||
|
.Fa big
|
||||||
|
is returned;
|
||||||
|
if
|
||||||
|
.Fa little
|
||||||
|
occurs nowhere in
|
||||||
|
.Fa big ,
|
||||||
|
.Dv NULL
|
||||||
|
is returned;
|
||||||
|
otherwise a pointer to the first character of the first occurrence of
|
||||||
|
.Fa little
|
||||||
|
is returned.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
The following sets the pointer
|
||||||
|
.Va ptr
|
||||||
|
to
|
||||||
|
.Dv NULL ,
|
||||||
|
because only the first 4 characters of
|
||||||
|
.Va largestring
|
||||||
|
are searched:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
const char *largestring = "Foo Bar Baz";
|
||||||
|
const char *smallstring = "Bar";
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
ptr = strnstr(largestring, smallstring, 4);
|
||||||
|
.Ed
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr strstr 3 ,
|
||||||
|
.Xr strcasestr 3 ,
|
||||||
|
.Xr memchr 3 ,
|
||||||
|
.Xr memmem 3 ,
|
||||||
|
.Xr strchr 3 ,
|
||||||
|
.Xr strcspn 3 ,
|
||||||
|
.Xr strpbrk 3 ,
|
||||||
|
.Xr strrchr 3 ,
|
||||||
|
.Xr strsep 3 ,
|
||||||
|
.Xr strspn 3 ,
|
||||||
|
.Xr strtok 3 ,
|
||||||
|
.Xr wcsstr 3
|
@@ -20,13 +20,13 @@
|
|||||||
.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
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
|
||||||
.In limits.h
|
.In limits.h
|
||||||
|
.In bsd/stdlib.h
|
||||||
.Ft long long
|
.Ft long long
|
||||||
.Fo strtonum
|
.Fo strtonum
|
||||||
.Fa "const char *nptr"
|
.Fa "const char *nptr"
|
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 .
|
@@ -39,7 +39,7 @@
|
|||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In vis.h
|
.In bsd/vis.h
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn unvis "char *cp" "char c" "int *astate" "int flag"
|
.Fn unvis "char *cp" "char c" "int *astate" "int flag"
|
||||||
.Ft int
|
.Ft int
|
@@ -41,7 +41,7 @@
|
|||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
.In vis.h
|
.In bsd/vis.h
|
||||||
.Ft char *
|
.Ft char *
|
||||||
.Fn vis "char *dst" "int c" "int flag" "int nextc"
|
.Fn vis "char *dst" "int c" "int flag" "int nextc"
|
||||||
.Ft int
|
.Ft int
|
1
man/wcslcat.3
Normal file
1
man/wcslcat.3
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.so man3/wcslcpy.3
|
67
man/wcslcpy.3
Normal file
67
man/wcslcpy.3
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
.\" $NetBSD: wmemchr.3,v 1.4 2001/01/02 11:26:23 itojun Exp $
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
.\" are met:
|
||||||
|
.\" 1. Redistributions of source code must retain the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer.
|
||||||
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
.\" notice, this list of conditions and the following disclaimer in the
|
||||||
|
.\" documentation and/or other materials provided with the distribution.
|
||||||
|
.\" 3. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
.\" SUCH DAMAGE.
|
||||||
|
.\"
|
||||||
|
.\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\"
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd March 4, 2009
|
||||||
|
.Dt WCSLCPY 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm wcslcat ,
|
||||||
|
.Nm wcslcpy ,
|
||||||
|
.Nd wide character string manipulation operations
|
||||||
|
.Sh LIBRARY
|
||||||
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
|
.Lb libbsd
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In bsd/wchar.h
|
||||||
|
.Ft size_t
|
||||||
|
.Fn wcslcat "wchar_t *s1" "const wchar_t *s2" "size_t n"
|
||||||
|
.Ft size_t
|
||||||
|
.Fn wcslcpy "wchar_t *s1" "const wchar_t *s2" "size_t n"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The functions implement string manipulation operations over wide character
|
||||||
|
strings.
|
||||||
|
For a detailed description, refer to documents for the respective single-byte
|
||||||
|
counterpart, such as
|
||||||
|
.Xr strlcpy 3 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr strlcat 3 ,
|
||||||
|
.Xr strlcpy 3 ,
|
||||||
|
.Sh STANDARDS
|
||||||
|
.Fn wcslcat
|
||||||
|
and
|
||||||
|
.Fn wcslcpy ,
|
||||||
|
which are BSD extensions.
|
109
src/Makefile.am
Normal file
109
src/Makefile.am
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
## 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-ctor.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
|
||||||
|
lib_LIBRARIES =
|
||||||
|
|
||||||
|
if BUILD_LIBBSD_CTOR
|
||||||
|
pkgconfig_DATA += libbsd-ctor.pc
|
||||||
|
|
||||||
|
lib_LIBRARIES += libbsd-ctor.a
|
||||||
|
endif
|
||||||
|
|
||||||
|
hash/md5hl.c: $(srcdir)/hash/helper.c
|
||||||
|
$(AM_V_at) $(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 $(LIBBSD_ABI)
|
||||||
|
libbsd_la_SOURCES = \
|
||||||
|
arc4random.c \
|
||||||
|
bsd_getopt.c \
|
||||||
|
closefrom.c \
|
||||||
|
dehumanize_number.c \
|
||||||
|
err.c \
|
||||||
|
expand_number.c \
|
||||||
|
fgetln.c \
|
||||||
|
fgetwln.c \
|
||||||
|
flopen.c \
|
||||||
|
fmtcheck.c \
|
||||||
|
fparseln.c \
|
||||||
|
fpurge.c \
|
||||||
|
funopen.c \
|
||||||
|
getbsize.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 \
|
||||||
|
reallocarray.c \
|
||||||
|
reallocf.c \
|
||||||
|
setmode.c \
|
||||||
|
setproctitle.c \
|
||||||
|
strlcat.c \
|
||||||
|
strlcpy.c \
|
||||||
|
stringlist.c \
|
||||||
|
strmode.c \
|
||||||
|
strnstr.c \
|
||||||
|
strtonum.c \
|
||||||
|
timeconv.c \
|
||||||
|
unvis.c \
|
||||||
|
vis.c \
|
||||||
|
wcslcat.c \
|
||||||
|
wcslcpy.c \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
libbsd_ctor_a_SOURCES = \
|
||||||
|
setproctitle_ctor.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*
|
@@ -24,17 +24,21 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bsd/getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
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;
|
||||||
optind = 0;
|
optind = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getopt(argc, argv, shortopts);
|
/*
|
||||||
|
* Make sure we are using the system getopt() and not a possible
|
||||||
|
* overlay macro.
|
||||||
|
*/
|
||||||
|
return (getopt)(argc, argv, shortopts);
|
||||||
}
|
}
|
||||||
|
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 */
|
@@ -1,12 +1,5 @@
|
|||||||
/* $NetBSD: dehumanize_number.c,v 1.2 2007/12/14 17:32:47 xtraeme Exp $ */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
|
* Copyright © 2012-2013 Guillem Jover <guillem@hadrons.org>
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
|
||||||
* by Julio M. Merino Vidal, developed as part of Google's Summer of Code
|
|
||||||
* 2005 program.
|
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -16,99 +9,60 @@
|
|||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
__RCSID("$NetBSD: dehumanize_number.c,v 1.2 2007/12/14 17:32:47 xtraeme Exp $");
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <ctype.h>
|
||||||
|
#include <libutil.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* Converts the number given in 'str', which may be given in a humanized
|
|
||||||
* form (as described in humanize_number(3), but with some limitations),
|
|
||||||
* to an int64_t without units.
|
|
||||||
* In case of success, 0 is returned and *size holds the value.
|
|
||||||
* Otherwise, -1 is returned and *size is untouched.
|
|
||||||
*
|
|
||||||
* TODO: Internationalization, SI units.
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
dehumanize_number(const char *str, int64_t *size)
|
dehumanize_number(const char *buf, int64_t *num)
|
||||||
{
|
{
|
||||||
char *ep, unit;
|
uint64_t rval, rmax;
|
||||||
const char *delimit;
|
int sign = +1;
|
||||||
long multiplier;
|
int rc;
|
||||||
long long tmp, tmp2;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
len = strlen(str);
|
/* The current expand_number() implementation uses bit shifts, so
|
||||||
if (len == 0) {
|
* we cannot pass negative numbers, preserve the sign and apply it
|
||||||
errno = EINVAL;
|
* later. */
|
||||||
|
while (isspace(*buf))
|
||||||
|
buf++;
|
||||||
|
if (*buf == '-') {
|
||||||
|
sign = -1;
|
||||||
|
buf++;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = expand_number(buf, &rval);
|
||||||
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
/* The sign has been stripped, so rval has the absolute value.
|
||||||
|
* Error out, regardless of the sign, if rval is greater than
|
||||||
|
* abs(INT64_MIN) (== INT64_MAX + 1), or if the sign is positive
|
||||||
|
* and the value has overflown by one (INT64_MAX + 1). */
|
||||||
|
rmax = INT64_MAX + 1ULL;
|
||||||
|
if (rval > rmax || (rval == rmax && sign == +1)) {
|
||||||
|
errno = ERANGE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
*num = rval * sign;
|
||||||
multiplier = 1;
|
|
||||||
|
|
||||||
unit = str[len - 1];
|
|
||||||
if (isalpha((unsigned char)unit)) {
|
|
||||||
switch (tolower((unsigned char)unit)) {
|
|
||||||
case 'b':
|
|
||||||
multiplier = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'k':
|
|
||||||
multiplier = 1024;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm':
|
|
||||||
multiplier = 1024 * 1024;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'g':
|
|
||||||
multiplier = 1024 * 1024 * 1024;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1; /* Invalid suffix. */
|
|
||||||
}
|
|
||||||
|
|
||||||
delimit = &str[len - 1];
|
|
||||||
} else
|
|
||||||
delimit = NULL;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
tmp = strtoll(str, &ep, 10);
|
|
||||||
if (str[0] == '\0' || (ep != delimit && *ep != '\0'))
|
|
||||||
return -1; /* Not a number. */
|
|
||||||
else if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN))
|
|
||||||
return -1; /* Out of range. */
|
|
||||||
|
|
||||||
tmp2 = tmp * multiplier;
|
|
||||||
tmp2 = tmp2 / multiplier;
|
|
||||||
if (tmp != tmp2) {
|
|
||||||
errno = ERANGE;
|
|
||||||
return -1; /* Out of range. */
|
|
||||||
}
|
|
||||||
*size = tmp * multiplier;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
15
src/err.c
15
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
|
||||||
@@ -24,22 +25,17 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bsd/err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
35
src/fgetln.c
35
src/fgetln.c
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005 Hector Garcia Alvarez
|
* Copyright © 2005 Hector Garcia Alvarez
|
||||||
* Copyright © 2005, 2008, 2009 Guillem Jover
|
* Copyright © 2005, 2008-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
|
||||||
@@ -30,23 +30,44 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef HAVE_GETLINE
|
||||||
|
struct filebuf {
|
||||||
|
FILE *fp;
|
||||||
|
char *buf;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FILEBUF_POOL_ITEMS 32
|
||||||
|
|
||||||
|
static struct filebuf fb_pool[FILEBUF_POOL_ITEMS];
|
||||||
|
static int fb_pool_cur;
|
||||||
|
|
||||||
char *
|
char *
|
||||||
fgetln(FILE *stream, size_t *len)
|
fgetln(FILE *stream, size_t *len)
|
||||||
{
|
{
|
||||||
static char *line = NULL;
|
struct filebuf *fb;
|
||||||
static size_t line_len = 0;
|
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
|
|
||||||
nread = getline(&line, &line_len, stream);
|
/* Try to diminish the possibility of several fgetln() calls being
|
||||||
|
* used on different streams, by using a pool of buffers per file. */
|
||||||
|
fb = &fb_pool[fb_pool_cur];
|
||||||
|
if (fb->fp != stream && fb->fp != NULL) {
|
||||||
|
fb_pool_cur++;
|
||||||
|
fb_pool_cur %= FILEBUF_POOL_ITEMS;
|
||||||
|
fb = &fb_pool[fb_pool_cur];
|
||||||
|
}
|
||||||
|
fb->fp = stream;
|
||||||
|
|
||||||
|
nread = getline(&fb->buf, &fb->len, stream);
|
||||||
/* Note: the getdelim/getline API ensures nread != 0. */
|
/* Note: the getdelim/getline API ensures nread != 0. */
|
||||||
if (nread == -1) {
|
if (nread == -1) {
|
||||||
*len = 0;
|
*len = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
*len = (size_t)nread;
|
*len = (size_t)nread;
|
||||||
return line;
|
return fb->buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "Function fgetln() needs to be ported."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
87
src/fgetwln.c
Normal file
87
src/fgetwln.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
struct filewbuf {
|
||||||
|
FILE *fp;
|
||||||
|
wchar_t *wbuf;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FILEWBUF_INIT_LEN 128
|
||||||
|
#define FILEWBUF_POOL_ITEMS 32
|
||||||
|
|
||||||
|
static struct filewbuf fb_pool[FILEWBUF_POOL_ITEMS];
|
||||||
|
static int fb_pool_cur;
|
||||||
|
|
||||||
|
wchar_t *
|
||||||
|
fgetwln(FILE *stream, size_t *lenp)
|
||||||
|
{
|
||||||
|
struct filewbuf *fb;
|
||||||
|
wint_t wc;
|
||||||
|
size_t wused = 0;
|
||||||
|
|
||||||
|
/* Try to diminish the possibility of several fgetwln() calls being
|
||||||
|
* used on different streams, by using a pool of buffers per file. */
|
||||||
|
fb = &fb_pool[fb_pool_cur];
|
||||||
|
if (fb->fp != stream && fb->fp != NULL) {
|
||||||
|
fb_pool_cur++;
|
||||||
|
fb_pool_cur %= FILEWBUF_POOL_ITEMS;
|
||||||
|
fb = &fb_pool[fb_pool_cur];
|
||||||
|
}
|
||||||
|
fb->fp = stream;
|
||||||
|
|
||||||
|
while ((wc = fgetwc(stream)) != WEOF) {
|
||||||
|
if (!fb->len || wused > fb->len) {
|
||||||
|
wchar_t *wp;
|
||||||
|
|
||||||
|
if (fb->len)
|
||||||
|
fb->len *= 2;
|
||||||
|
else
|
||||||
|
fb->len = FILEWBUF_INIT_LEN;
|
||||||
|
|
||||||
|
wp = realloc(fb->wbuf, fb->len * sizeof(wchar_t));
|
||||||
|
if (wp == NULL) {
|
||||||
|
wused = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fb->wbuf = wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
fb->wbuf[wused++] = wc;
|
||||||
|
|
||||||
|
if (wc == L'\n')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*lenp = wused;
|
||||||
|
return wused ? fb->wbuf : NULL;
|
||||||
|
}
|
@@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
|
230
src/fparseln.c
Normal file
230
src/fparseln.c
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
/* $NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1997 Christos Zoulas. 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 ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
__RCSID("$NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $");
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define FLOCKFILE(fp)
|
||||||
|
#define FUNLOCKFILE(fp)
|
||||||
|
#define _DIAGASSERT(t)
|
||||||
|
|
||||||
|
static int isescaped(const char *, const char *, int);
|
||||||
|
|
||||||
|
/* isescaped():
|
||||||
|
* Return true if the character in *p that belongs to a string
|
||||||
|
* that starts in *sp, is escaped by the escape character esc.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
isescaped(const char *sp, const char *p, int esc)
|
||||||
|
{
|
||||||
|
const char *cp;
|
||||||
|
size_t ne;
|
||||||
|
|
||||||
|
_DIAGASSERT(sp != NULL);
|
||||||
|
_DIAGASSERT(p != NULL);
|
||||||
|
|
||||||
|
/* No escape character */
|
||||||
|
if (esc == '\0')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Count the number of escape characters that precede ours */
|
||||||
|
for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Return true if odd number of escape characters */
|
||||||
|
return (ne & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* fparseln():
|
||||||
|
* Read a line from a file parsing continuations ending in \
|
||||||
|
* and eliminating trailing newlines, or comments starting with
|
||||||
|
* the comment char.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
|
||||||
|
{
|
||||||
|
static const char dstr[3] = { '\\', '\\', '#' };
|
||||||
|
|
||||||
|
size_t s, len;
|
||||||
|
char *buf;
|
||||||
|
char *ptr, *cp;
|
||||||
|
int cnt;
|
||||||
|
char esc, con, nl, com;
|
||||||
|
|
||||||
|
_DIAGASSERT(fp != NULL);
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
buf = NULL;
|
||||||
|
cnt = 1;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
str = dstr;
|
||||||
|
|
||||||
|
esc = str[0];
|
||||||
|
con = str[1];
|
||||||
|
com = str[2];
|
||||||
|
/*
|
||||||
|
* XXX: it would be cool to be able to specify the newline character,
|
||||||
|
* but unfortunately, fgetln does not let us
|
||||||
|
*/
|
||||||
|
nl = '\n';
|
||||||
|
|
||||||
|
FLOCKFILE(fp);
|
||||||
|
|
||||||
|
while (cnt) {
|
||||||
|
cnt = 0;
|
||||||
|
|
||||||
|
if (lineno)
|
||||||
|
(*lineno)++;
|
||||||
|
|
||||||
|
if ((ptr = fgetln(fp, &s)) == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (s && com) { /* Check and eliminate comments */
|
||||||
|
for (cp = ptr; cp < ptr + s; cp++)
|
||||||
|
if (*cp == com && !isescaped(ptr, cp, esc)) {
|
||||||
|
s = cp - ptr;
|
||||||
|
cnt = s == 0 && buf == NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s && nl) { /* Check and eliminate newlines */
|
||||||
|
cp = &ptr[s - 1];
|
||||||
|
|
||||||
|
if (*cp == nl)
|
||||||
|
s--; /* forget newline */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s && con) { /* Check and eliminate continuations */
|
||||||
|
cp = &ptr[s - 1];
|
||||||
|
|
||||||
|
if (*cp == con && !isescaped(ptr, cp, esc)) {
|
||||||
|
s--; /* forget continuation char */
|
||||||
|
cnt = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s == 0) {
|
||||||
|
/*
|
||||||
|
* nothing to add, skip realloc except in case
|
||||||
|
* we need a minimal buf to return an empty line
|
||||||
|
*/
|
||||||
|
if (cnt || buf != NULL)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cp = realloc(buf, len + s + 1)) == NULL) {
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf = cp;
|
||||||
|
|
||||||
|
(void) memcpy(buf + len, ptr, s);
|
||||||
|
len += s;
|
||||||
|
buf[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
|
||||||
|
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
|
||||||
|
strchr(buf, esc) != NULL) {
|
||||||
|
ptr = cp = buf;
|
||||||
|
while (cp[0] != '\0') {
|
||||||
|
int skipesc;
|
||||||
|
|
||||||
|
while (cp[0] != '\0' && cp[0] != esc)
|
||||||
|
*ptr++ = *cp++;
|
||||||
|
if (cp[0] == '\0' || cp[1] == '\0')
|
||||||
|
break;
|
||||||
|
|
||||||
|
skipesc = 0;
|
||||||
|
if (cp[1] == com)
|
||||||
|
skipesc += (flags & FPARSELN_UNESCCOMM);
|
||||||
|
if (cp[1] == con)
|
||||||
|
skipesc += (flags & FPARSELN_UNESCCONT);
|
||||||
|
if (cp[1] == esc)
|
||||||
|
skipesc += (flags & FPARSELN_UNESCESC);
|
||||||
|
if (cp[1] != com && cp[1] != con && cp[1] != esc)
|
||||||
|
skipesc = (flags & FPARSELN_UNESCREST);
|
||||||
|
|
||||||
|
if (skipesc)
|
||||||
|
cp++;
|
||||||
|
else
|
||||||
|
*ptr++ = *cp++;
|
||||||
|
*ptr++ = *cp++;
|
||||||
|
}
|
||||||
|
*ptr = '\0';
|
||||||
|
len = strlen(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
*size = len;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
int main(int, char **);
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
size_t size, line;
|
||||||
|
|
||||||
|
line = 0;
|
||||||
|
while ((ptr = fparseln(stdin, &size, &line, NULL,
|
||||||
|
FPARSELN_UNESCALL)) != NULL)
|
||||||
|
printf("line %d (%d) |%s|\n", line, size, ptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
# This is a test
|
||||||
|
line 1
|
||||||
|
line 2 \
|
||||||
|
line 3 # Comment
|
||||||
|
line 4 \# Not comment \\\\
|
||||||
|
|
||||||
|
# And a comment \
|
||||||
|
line 5 \\\
|
||||||
|
line 6
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* TEST */
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 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,12 +24,43 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBBSD_BSD_QUEUE_H
|
#include <errno.h>
|
||||||
#define LIBBSD_BSD_QUEUE_H
|
#include <stdio.h>
|
||||||
|
#include <stdio_ext.h>
|
||||||
|
|
||||||
#warning "This header is deprecated, use the one in bsd/sys/queue.h instead."
|
#ifdef HAVE___FPURGE
|
||||||
|
int
|
||||||
|
fpurge(FILE *fp)
|
||||||
|
{
|
||||||
|
if (fp == NULL || fileno(fp) < 0) {
|
||||||
|
errno = EBADF;
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
#include <bsd/sys/queue.h>
|
__fpurge(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error "Function fpurge() needs to be ported."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
static FILE fp_bad;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
if (fpurge(&fp_bad) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
fp = fopen("/dev/zero", "r");
|
||||||
|
if (fpurge(fp) < 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
142
src/funopen.c
Normal file
142
src/funopen.c
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2011, 2013 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_FOPENCOOKIE
|
||||||
|
struct funopen_cookie {
|
||||||
|
void *orig_cookie;
|
||||||
|
|
||||||
|
int (*readfn)(void *cookie, char *buf, int size);
|
||||||
|
int (*writefn)(void *cookie, const char *buf, int size);
|
||||||
|
off_t (*seekfn)(void *cookie, off_t offset, int whence);
|
||||||
|
int (*closefn)(void *cookie);
|
||||||
|
};
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
funopen_read(void *cookie, char *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct funopen_cookie *cookiewrap = cookie;
|
||||||
|
|
||||||
|
if (cookiewrap->readfn == NULL) {
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookiewrap->readfn(cookiewrap->orig_cookie, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
funopen_write(void *cookie, const char *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct funopen_cookie *cookiewrap = cookie;
|
||||||
|
|
||||||
|
if (cookiewrap->writefn == NULL)
|
||||||
|
return EOF;
|
||||||
|
|
||||||
|
return cookiewrap->writefn(cookiewrap->orig_cookie, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
funopen_seek(void *cookie, off64_t *offset, int whence)
|
||||||
|
{
|
||||||
|
struct funopen_cookie *cookiewrap = cookie;
|
||||||
|
off_t soff = *offset;
|
||||||
|
|
||||||
|
if (cookiewrap->seekfn == NULL) {
|
||||||
|
errno = ESPIPE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
soff = cookiewrap->seekfn(cookiewrap->orig_cookie, soff, whence);
|
||||||
|
*offset = soff;
|
||||||
|
|
||||||
|
return *offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
funopen_close(void *cookie)
|
||||||
|
{
|
||||||
|
struct funopen_cookie *cookiewrap = cookie;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (cookiewrap->closefn == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
rc = cookiewrap->closefn(cookiewrap->orig_cookie);
|
||||||
|
|
||||||
|
free(cookiewrap);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *
|
||||||
|
funopen(const void *cookie,
|
||||||
|
int (*readfn)(void *cookie, char *buf, int size),
|
||||||
|
int (*writefn)(void *cookie, const char *buf, int size),
|
||||||
|
off_t (*seekfn)(void *cookie, off_t offset, int whence),
|
||||||
|
int (*closefn)(void *cookie))
|
||||||
|
{
|
||||||
|
struct funopen_cookie *cookiewrap;
|
||||||
|
cookie_io_functions_t funcswrap = {
|
||||||
|
.read = funopen_read,
|
||||||
|
.write = funopen_write,
|
||||||
|
.seek = funopen_seek,
|
||||||
|
.close = funopen_close,
|
||||||
|
};
|
||||||
|
const char *mode;
|
||||||
|
|
||||||
|
if (readfn) {
|
||||||
|
if (writefn == NULL)
|
||||||
|
mode = "r";
|
||||||
|
else
|
||||||
|
mode = "r+";
|
||||||
|
} else if (writefn) {
|
||||||
|
mode = "w";
|
||||||
|
} else {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cookiewrap = malloc(sizeof(*cookiewrap));
|
||||||
|
if (cookiewrap == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
cookiewrap->orig_cookie = (void *)cookie;
|
||||||
|
cookiewrap->readfn = readfn;
|
||||||
|
cookiewrap->writefn = writefn;
|
||||||
|
cookiewrap->seekfn = seekfn;
|
||||||
|
cookiewrap->closefn = closefn;
|
||||||
|
|
||||||
|
return fopencookie(cookiewrap, mode, funcswrap);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error "Function funopen() needs to be ported."
|
||||||
|
#endif
|
102
src/getbsize.c
Normal file
102
src/getbsize.c
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1991, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)getbsize.c 8.1 (Berkeley) 6/4/93
|
||||||
|
* $FreeBSD: src/lib/libc/gen/getbsize.c,v 1.9 2008/08/04 06:53:13 cperciva Exp $
|
||||||
|
* $DragonFly: src/lib/libc/gen/getbsize.c,v 1.4 2005/11/13 00:07:42 swildner Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
getbsize(int *headerlenp, long *blocksizep)
|
||||||
|
{
|
||||||
|
static char header[20];
|
||||||
|
long n, max, mul, blocksize;
|
||||||
|
char *ep, *p;
|
||||||
|
const char *form;
|
||||||
|
|
||||||
|
#define KB (1024L)
|
||||||
|
#define MB (1024L * 1024L)
|
||||||
|
#define GB (1024L * 1024L * 1024L)
|
||||||
|
#define MAXB GB /* No tera, peta, nor exa. */
|
||||||
|
form = "";
|
||||||
|
if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') {
|
||||||
|
if ((n = strtol(p, &ep, 10)) < 0)
|
||||||
|
goto underflow;
|
||||||
|
if (n == 0)
|
||||||
|
n = 1;
|
||||||
|
if (*ep && ep[1])
|
||||||
|
goto fmterr;
|
||||||
|
switch (*ep) {
|
||||||
|
case 'G': case 'g':
|
||||||
|
form = "G";
|
||||||
|
max = MAXB / GB;
|
||||||
|
mul = GB;
|
||||||
|
break;
|
||||||
|
case 'K': case 'k':
|
||||||
|
form = "K";
|
||||||
|
max = MAXB / KB;
|
||||||
|
mul = KB;
|
||||||
|
break;
|
||||||
|
case 'M': case 'm':
|
||||||
|
form = "M";
|
||||||
|
max = MAXB / MB;
|
||||||
|
mul = MB;
|
||||||
|
break;
|
||||||
|
case '\0':
|
||||||
|
max = MAXB;
|
||||||
|
mul = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fmterr: warnx("%s: unknown blocksize", p);
|
||||||
|
n = 512;
|
||||||
|
max = MAXB;
|
||||||
|
mul = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n > max) {
|
||||||
|
warnx("maximum blocksize is %ldG", MAXB / GB);
|
||||||
|
n = max;
|
||||||
|
}
|
||||||
|
if ((blocksize = n * mul) < 512) {
|
||||||
|
underflow: warnx("minimum blocksize is 512");
|
||||||
|
form = "";
|
||||||
|
blocksize = n = 512;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
blocksize = n = 512;
|
||||||
|
|
||||||
|
snprintf(header, sizeof(header), "%ld%s-blocks", n, form);
|
||||||
|
*headerlenp = strlen(header);
|
||||||
|
*blocksizep = blocksize;
|
||||||
|
return (header);
|
||||||
|
}
|
134
src/getpeereid.c
Normal file
134
src/getpeereid.c
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2010 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if defined(SO_PEERCRED)
|
||||||
|
/* Linux and OpenBSD */
|
||||||
|
int
|
||||||
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
|
{
|
||||||
|
/* XXX: This should be autodetected at build time instead. */
|
||||||
|
#if defined(__linux__)
|
||||||
|
struct ucred cred;
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
struct sockpeercred cred;
|
||||||
|
#endif
|
||||||
|
socklen_t credlen = sizeof(cred);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &credlen);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
*euid = cred.uid;
|
||||||
|
*egid = cred.gid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(LOCAL_PEERCRED)
|
||||||
|
/* FreeBSD */
|
||||||
|
#include <sys/ucred.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
|
{
|
||||||
|
struct xucred cred;
|
||||||
|
socklen_t credlen = sizeof(cred);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = getsockopt(s, 0, LOCAL_PEERCRED, &cred, &credlen);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
if (cred.cr_version != XUCRED_VERSION)
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
*euid = cred.cr_uid;
|
||||||
|
*egid = cred.cr_gid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(LOCAL_PEEREID)
|
||||||
|
/* NetBSD */
|
||||||
|
int
|
||||||
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
|
{
|
||||||
|
struct unpcbid cred;
|
||||||
|
socklen_t credlen = sizeof(cred);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = getsockopt(s, 0, LOCAL_PEEREID, &cred, &credlen);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
*euid = cred.unp_euid;
|
||||||
|
*egid = cred.unp_egid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(__sun)
|
||||||
|
/* Solaris */
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <ucred.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
|
{
|
||||||
|
ucred_t *cred = alloca(ucred_size());
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = getpeerucred(s, &cred);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
*euid = ucred_geteuid(cred);
|
||||||
|
if (*euid < 0)
|
||||||
|
return -1;
|
||||||
|
*egid = ucred_getegid(cred);
|
||||||
|
if (*egid < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#warning "This platform needs an implementation of getpeereid()"
|
||||||
|
int
|
||||||
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
|
{
|
||||||
|
*euid = geteuid();
|
||||||
|
*egid = getegid();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
@@ -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.
|
||||||
*
|
*
|
||||||
@@ -135,7 +135,7 @@ heapsort(vbase, nmemb, size, compar)
|
|||||||
size_t nmemb, size;
|
size_t nmemb, size;
|
||||||
int (*compar)(const void *, const void *);
|
int (*compar)(const void *, const void *);
|
||||||
{
|
{
|
||||||
int cnt, i, j, l;
|
size_t cnt, i, j, l;
|
||||||
char tmp, *tmp1, *tmp2;
|
char tmp, *tmp1, *tmp2;
|
||||||
char *base, *k, *p, *t;
|
char *base, *k, *p, *t;
|
||||||
|
|
||||||
|
12
src/libbsd-ctor.pc.in
Normal file
12
src/libbsd-ctor.pc.in
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
prefix=@prefix@
|
||||||
|
exec_prefix=@exec_prefix@
|
||||||
|
libdir=@libdir@
|
||||||
|
includedir=@includedir@
|
||||||
|
|
||||||
|
Name: libbsd-ctor
|
||||||
|
Description: Automatic constructor functions for libbsd
|
||||||
|
Version: @VERSION@
|
||||||
|
URL: http://libbsd.freedesktop.org/
|
||||||
|
Cflags: -I${includedir}
|
||||||
|
Libs: -L${libdir} -Wl,-z,nodlopen -Wl,-u,libbsd_init_func -lbsd-ctor
|
||||||
|
Requires: libbsd
|
11
src/libbsd-overlay.pc.in
Normal file
11
src/libbsd-overlay.pc.in
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
prefix=@prefix@
|
||||||
|
exec_prefix=@exec_prefix@
|
||||||
|
libdir=@libdir@
|
||||||
|
includedir=@includedir@
|
||||||
|
|
||||||
|
Name: libbsd
|
||||||
|
Description: Utility functions from BSD systems (overlay)
|
||||||
|
Version: @VERSION@
|
||||||
|
URL: http://libbsd.freedesktop.org/
|
||||||
|
Libs: -L${libdir} -lbsd
|
||||||
|
Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY
|
134
src/libbsd.map
Normal file
134
src/libbsd.map
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
LIBBSD_0.0 {
|
||||||
|
global:
|
||||||
|
arc4random;
|
||||||
|
arc4random_stir;
|
||||||
|
arc4random_addrandom;
|
||||||
|
|
||||||
|
bsd_getopt;
|
||||||
|
optreset;
|
||||||
|
|
||||||
|
errc;
|
||||||
|
warnc;
|
||||||
|
verrc;
|
||||||
|
vwarnc;
|
||||||
|
|
||||||
|
fgetln;
|
||||||
|
fmtcheck;
|
||||||
|
heapsort;
|
||||||
|
humanize_number;
|
||||||
|
|
||||||
|
inet_net_pton; /* XXX: Already provided by glibc, remove. */
|
||||||
|
|
||||||
|
getprogname;
|
||||||
|
setprogname;
|
||||||
|
|
||||||
|
strlcpy;
|
||||||
|
strlcat;
|
||||||
|
|
||||||
|
setmode;
|
||||||
|
getmode;
|
||||||
|
|
||||||
|
vis;
|
||||||
|
strvis;
|
||||||
|
strvisx;
|
||||||
|
unvis;
|
||||||
|
strunvis;
|
||||||
|
strunvisx;
|
||||||
|
|
||||||
|
MD5Init;
|
||||||
|
MD5Update;
|
||||||
|
MD5Pad;
|
||||||
|
MD5Final;
|
||||||
|
MD5Transform;
|
||||||
|
MD5End;
|
||||||
|
MD5File;
|
||||||
|
MD5FileChunk;
|
||||||
|
MD5Data;
|
||||||
|
|
||||||
|
local:
|
||||||
|
*;
|
||||||
|
};
|
||||||
|
|
||||||
|
LIBBSD_0.1 {
|
||||||
|
strmode;
|
||||||
|
|
||||||
|
__fdnlist; /* Private symbol, but libkvm uses it. */
|
||||||
|
nlist;
|
||||||
|
} LIBBSD_0.0;
|
||||||
|
|
||||||
|
LIBBSD_0.2 {
|
||||||
|
strtonum;
|
||||||
|
|
||||||
|
strnvis;
|
||||||
|
strnunvis;
|
||||||
|
|
||||||
|
dehumanize_number;
|
||||||
|
|
||||||
|
readpassphrase;
|
||||||
|
|
||||||
|
flopen;
|
||||||
|
|
||||||
|
pidfile_open;
|
||||||
|
pidfile_write;
|
||||||
|
pidfile_close;
|
||||||
|
pidfile_remove;
|
||||||
|
|
||||||
|
arc4random_buf;
|
||||||
|
arc4random_uniform;
|
||||||
|
} LIBBSD_0.1;
|
||||||
|
|
||||||
|
LIBBSD_0.3 {
|
||||||
|
reallocf;
|
||||||
|
getpeereid;
|
||||||
|
|
||||||
|
mergesort;
|
||||||
|
radixsort;
|
||||||
|
sradixsort;
|
||||||
|
|
||||||
|
fpurge;
|
||||||
|
} LIBBSD_0.2;
|
||||||
|
|
||||||
|
LIBBSD_0.4 {
|
||||||
|
closefrom;
|
||||||
|
expand_number;
|
||||||
|
} LIBBSD_0.3;
|
||||||
|
|
||||||
|
LIBBSD_0.5 {
|
||||||
|
fgetwln;
|
||||||
|
fparseln;
|
||||||
|
|
||||||
|
/* Introduced in 0.2 as a stub, implemented in 0.5. */
|
||||||
|
setproctitle;
|
||||||
|
|
||||||
|
strnstr;
|
||||||
|
|
||||||
|
wcslcat;
|
||||||
|
wcslcpy;
|
||||||
|
} LIBBSD_0.4;
|
||||||
|
|
||||||
|
LIBBSD_0.6 {
|
||||||
|
/* Exported to cope with the constructor+dlopen+threads mess. */
|
||||||
|
setproctitle_init;
|
||||||
|
} LIBBSD_0.5;
|
||||||
|
|
||||||
|
LIBBSD_0.7 {
|
||||||
|
getbsize;
|
||||||
|
|
||||||
|
funopen;
|
||||||
|
|
||||||
|
reallocarray;
|
||||||
|
|
||||||
|
sl_init;
|
||||||
|
sl_add;
|
||||||
|
sl_free;
|
||||||
|
sl_find;
|
||||||
|
|
||||||
|
_time32_to_time;
|
||||||
|
_time_to_time32;
|
||||||
|
_time64_to_time;
|
||||||
|
_time_to_time64;
|
||||||
|
_time_to_long;
|
||||||
|
_long_to_time;
|
||||||
|
_time_to_int;
|
||||||
|
_int_to_time;
|
||||||
|
} LIBBSD_0.6;
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover
|
* Copyright © 2009, 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
|
||||||
@@ -46,7 +46,11 @@
|
|||||||
#elif defined(__amd64__)
|
#elif defined(__amd64__)
|
||||||
|
|
||||||
#define ELF_TARG_MACH EM_X86_64
|
#define ELF_TARG_MACH EM_X86_64
|
||||||
|
#if defined(__ILP32__)
|
||||||
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
|
#else
|
||||||
#define ELF_TARG_CLASS ELFCLASS64
|
#define ELF_TARG_CLASS ELFCLASS64
|
||||||
|
#endif
|
||||||
#define ELF_TARG_DATA ELFDATA2LSB
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
|
|
||||||
#elif defined(__arm__)
|
#elif defined(__arm__)
|
||||||
@@ -59,6 +63,16 @@
|
|||||||
#define ELF_TARG_DATA ELFDATA2LSB
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
|
||||||
|
#define ELF_TARG_MACH EM_AARCH64
|
||||||
|
#define ELF_TARG_CLASS ELFCLASS64
|
||||||
|
#if defined(__AARCH64EB__)
|
||||||
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
#else
|
||||||
|
#define ELF_TARG_DATA ELFDATA2LSB
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(__avr32__)
|
#elif defined(__avr32__)
|
||||||
|
|
||||||
#ifndef EM_AVR32
|
#ifndef EM_AVR32
|
||||||
@@ -165,6 +179,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#define ELF_TARG_DATA ELFDATA2MSB
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
|
||||||
|
#elif defined(__or1k__)
|
||||||
|
|
||||||
|
#define ELF_TARG_MACH EM_OPENRISC
|
||||||
|
#define ELF_TARG_CLASS ELFCLASS32
|
||||||
|
#define ELF_TARG_DATA ELFDATA2MSB
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#error Unknown ELF machine type
|
#error Unknown ELF machine type
|
||||||
@@ -194,4 +214,3 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
351
src/merge.c
Normal file
351
src/merge.c
Normal file
@@ -0,0 +1,351 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1992, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to Berkeley by
|
||||||
|
* Peter McIlroy.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hybrid exponential search/linear search merge sort with hybrid
|
||||||
|
* natural/pairwise first pass. Requires about .3% more comparisons
|
||||||
|
* for random data than LSMS with pairwise first pass alone.
|
||||||
|
* It works for objects as small as two bytes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NATURAL
|
||||||
|
#define THRESHOLD 16 /* Best choice for natural merge cut-off. */
|
||||||
|
|
||||||
|
/* #define NATURAL to get hybrid natural merge.
|
||||||
|
* (The default is pairwise merging.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void setup(u_char *, u_char *, size_t, size_t,
|
||||||
|
int (*)(const void *, const void *));
|
||||||
|
static void insertionsort(u_char *, size_t, size_t,
|
||||||
|
int (*)(const void *, const void *));
|
||||||
|
|
||||||
|
#define ISIZE sizeof(int)
|
||||||
|
#define PSIZE sizeof(u_char *)
|
||||||
|
#define ICOPY_LIST(src, dst, last) \
|
||||||
|
do \
|
||||||
|
*(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \
|
||||||
|
while(src < last)
|
||||||
|
#define ICOPY_ELT(src, dst, i) \
|
||||||
|
do \
|
||||||
|
*(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \
|
||||||
|
while (i -= ISIZE)
|
||||||
|
|
||||||
|
#define CCOPY_LIST(src, dst, last) \
|
||||||
|
do \
|
||||||
|
*dst++ = *src++; \
|
||||||
|
while (src < last)
|
||||||
|
#define CCOPY_ELT(src, dst, i) \
|
||||||
|
do \
|
||||||
|
*dst++ = *src++; \
|
||||||
|
while (i -= 1)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the next possible pointer head. (Trickery for forcing an array
|
||||||
|
* to do double duty as a linked list when objects do not align with word
|
||||||
|
* boundaries.
|
||||||
|
*/
|
||||||
|
/* Assumption: PSIZE is a power of 2. */
|
||||||
|
#define EVAL(p) (u_char **) \
|
||||||
|
((u_char *)0 + \
|
||||||
|
(((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1)))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arguments are as for qsort.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
mergesort(base, nmemb, size, cmp)
|
||||||
|
void *base;
|
||||||
|
size_t nmemb;
|
||||||
|
size_t size;
|
||||||
|
int (*cmp)(const void *, const void *);
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int sense;
|
||||||
|
int big, iflag;
|
||||||
|
u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
|
||||||
|
u_char *list2, *list1, *p2, *p, *last, **p1;
|
||||||
|
|
||||||
|
if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nmemb == 0)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX
|
||||||
|
* Stupid subtraction for the Cray.
|
||||||
|
*/
|
||||||
|
iflag = 0;
|
||||||
|
if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE))
|
||||||
|
iflag = 1;
|
||||||
|
|
||||||
|
if ((list2 = malloc(nmemb * size + PSIZE)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
list1 = base;
|
||||||
|
setup(list1, list2, nmemb, size, cmp);
|
||||||
|
last = list2 + nmemb * size;
|
||||||
|
i = big = 0;
|
||||||
|
while (*EVAL(list2) != last) {
|
||||||
|
l2 = list1;
|
||||||
|
p1 = EVAL(list1);
|
||||||
|
for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) {
|
||||||
|
p2 = *EVAL(p2);
|
||||||
|
f1 = l2;
|
||||||
|
f2 = l1 = list1 + (p2 - list2);
|
||||||
|
if (p2 != last)
|
||||||
|
p2 = *EVAL(p2);
|
||||||
|
l2 = list1 + (p2 - list2);
|
||||||
|
while (f1 < l1 && f2 < l2) {
|
||||||
|
if ((*cmp)(f1, f2) <= 0) {
|
||||||
|
q = f2;
|
||||||
|
b = f1, t = l1;
|
||||||
|
sense = -1;
|
||||||
|
} else {
|
||||||
|
q = f1;
|
||||||
|
b = f2, t = l2;
|
||||||
|
sense = 0;
|
||||||
|
}
|
||||||
|
if (!big) { /* here i = 0 */
|
||||||
|
while ((b += size) < t && cmp(q, b) >sense)
|
||||||
|
if (++i == 6) {
|
||||||
|
big = 1;
|
||||||
|
goto EXPONENTIAL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EXPONENTIAL: for (i = size; ; i <<= 1)
|
||||||
|
if ((p = (b + i)) >= t) {
|
||||||
|
if ((p = t - size) > b &&
|
||||||
|
(*cmp)(q, p) <= sense)
|
||||||
|
t = p;
|
||||||
|
else
|
||||||
|
b = p;
|
||||||
|
break;
|
||||||
|
} else if ((*cmp)(q, p) <= sense) {
|
||||||
|
t = p;
|
||||||
|
if (i == size)
|
||||||
|
big = 0;
|
||||||
|
goto FASTCASE;
|
||||||
|
} else
|
||||||
|
b = p;
|
||||||
|
while (t > b+size) {
|
||||||
|
i = (((t - b) / size) >> 1) * size;
|
||||||
|
if ((*cmp)(q, p = b + i) <= sense)
|
||||||
|
t = p;
|
||||||
|
else
|
||||||
|
b = p;
|
||||||
|
}
|
||||||
|
goto COPY;
|
||||||
|
FASTCASE: while (i > size)
|
||||||
|
if ((*cmp)(q,
|
||||||
|
p = b + (i >>= 1)) <= sense)
|
||||||
|
t = p;
|
||||||
|
else
|
||||||
|
b = p;
|
||||||
|
COPY: b = t;
|
||||||
|
}
|
||||||
|
i = size;
|
||||||
|
if (q == f1) {
|
||||||
|
if (iflag) {
|
||||||
|
ICOPY_LIST(f2, tp2, b);
|
||||||
|
ICOPY_ELT(f1, tp2, i);
|
||||||
|
} else {
|
||||||
|
CCOPY_LIST(f2, tp2, b);
|
||||||
|
CCOPY_ELT(f1, tp2, i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (iflag) {
|
||||||
|
ICOPY_LIST(f1, tp2, b);
|
||||||
|
ICOPY_ELT(f2, tp2, i);
|
||||||
|
} else {
|
||||||
|
CCOPY_LIST(f1, tp2, b);
|
||||||
|
CCOPY_ELT(f2, tp2, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (f2 < l2) {
|
||||||
|
if (iflag)
|
||||||
|
ICOPY_LIST(f2, tp2, l2);
|
||||||
|
else
|
||||||
|
CCOPY_LIST(f2, tp2, l2);
|
||||||
|
} else if (f1 < l1) {
|
||||||
|
if (iflag)
|
||||||
|
ICOPY_LIST(f1, tp2, l1);
|
||||||
|
else
|
||||||
|
CCOPY_LIST(f1, tp2, l1);
|
||||||
|
}
|
||||||
|
*p1 = l2;
|
||||||
|
}
|
||||||
|
tp2 = list1; /* swap list1, list2 */
|
||||||
|
list1 = list2;
|
||||||
|
list2 = tp2;
|
||||||
|
last = list2 + nmemb*size;
|
||||||
|
}
|
||||||
|
if (base == list2) {
|
||||||
|
memmove(list2, list1, nmemb*size);
|
||||||
|
list2 = list1;
|
||||||
|
}
|
||||||
|
free(list2);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define swap(a, b) { \
|
||||||
|
s = b; \
|
||||||
|
i = size; \
|
||||||
|
do { \
|
||||||
|
tmp = *a; *a++ = *s; *s++ = tmp; \
|
||||||
|
} while (--i); \
|
||||||
|
a -= size; \
|
||||||
|
}
|
||||||
|
#define reverse(bot, top) { \
|
||||||
|
s = top; \
|
||||||
|
do { \
|
||||||
|
i = size; \
|
||||||
|
do { \
|
||||||
|
tmp = *bot; *bot++ = *s; *s++ = tmp; \
|
||||||
|
} while (--i); \
|
||||||
|
s -= size2; \
|
||||||
|
} while(bot < s); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Optional hybrid natural/pairwise first pass. Eats up list1 in runs of
|
||||||
|
* increasing order, list2 in a corresponding linked list. Checks for runs
|
||||||
|
* when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL
|
||||||
|
* is defined. Otherwise simple pairwise merging is used.)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
setup(list1, list2, n, size, cmp)
|
||||||
|
size_t n, size;
|
||||||
|
int (*cmp)(const void *, const void *);
|
||||||
|
u_char *list1, *list2;
|
||||||
|
{
|
||||||
|
int i, length, size2, tmp, sense;
|
||||||
|
u_char *f1, *f2, *s, *l2, *last, *p2;
|
||||||
|
|
||||||
|
size2 = size*2;
|
||||||
|
if (n <= 5) {
|
||||||
|
insertionsort(list1, n, size, cmp);
|
||||||
|
*EVAL(list2) = (u_char*) list2 + n*size;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Avoid running pointers out of bounds; limit n to evens
|
||||||
|
* for simplicity.
|
||||||
|
*/
|
||||||
|
i = 4 + (n & 1);
|
||||||
|
insertionsort(list1 + (n - i) * size, i, size, cmp);
|
||||||
|
last = list1 + size * (n - i);
|
||||||
|
*EVAL(list2 + (last - list1)) = list2 + n * size;
|
||||||
|
|
||||||
|
#ifdef NATURAL
|
||||||
|
p2 = list2;
|
||||||
|
f1 = list1;
|
||||||
|
sense = (cmp(f1, f1 + size) > 0);
|
||||||
|
for (; f1 < last; sense = !sense) {
|
||||||
|
length = 2;
|
||||||
|
/* Find pairs with same sense. */
|
||||||
|
for (f2 = f1 + size2; f2 < last; f2 += size2) {
|
||||||
|
if ((cmp(f2, f2+ size) > 0) != sense)
|
||||||
|
break;
|
||||||
|
length += 2;
|
||||||
|
}
|
||||||
|
if (length < THRESHOLD) { /* Pairwise merge */
|
||||||
|
do {
|
||||||
|
p2 = *EVAL(p2) = f1 + size2 - list1 + list2;
|
||||||
|
if (sense > 0)
|
||||||
|
swap (f1, f1 + size);
|
||||||
|
} while ((f1 += size2) < f2);
|
||||||
|
} else { /* Natural merge */
|
||||||
|
l2 = f2;
|
||||||
|
for (f2 = f1 + size2; f2 < l2; f2 += size2) {
|
||||||
|
if ((cmp(f2-size, f2) > 0) != sense) {
|
||||||
|
p2 = *EVAL(p2) = f2 - list1 + list2;
|
||||||
|
if (sense > 0)
|
||||||
|
reverse(f1, f2-size);
|
||||||
|
f1 = f2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sense > 0)
|
||||||
|
reverse (f1, f2-size);
|
||||||
|
f1 = f2;
|
||||||
|
if (f2 < last || cmp(f2 - size, f2) > 0)
|
||||||
|
p2 = *EVAL(p2) = f2 - list1 + list2;
|
||||||
|
else
|
||||||
|
p2 = *EVAL(p2) = list2 + n*size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else /* pairwise merge only. */
|
||||||
|
for (f1 = list1, p2 = list2; f1 < last; f1 += size2) {
|
||||||
|
p2 = *EVAL(p2) = p2 + size2;
|
||||||
|
if (cmp (f1, f1 + size) > 0)
|
||||||
|
swap(f1, f1 + size);
|
||||||
|
}
|
||||||
|
#endif /* NATURAL */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is to avoid out-of-bounds addresses in sorting the
|
||||||
|
* last 4 elements.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
insertionsort(a, n, size, cmp)
|
||||||
|
u_char *a;
|
||||||
|
size_t n, size;
|
||||||
|
int (*cmp)(const void *, const void *);
|
||||||
|
{
|
||||||
|
u_char *ai, *s, *t, *u, tmp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (ai = a+size; --n >= 1; ai += size)
|
||||||
|
for (t = ai; t > a; t -= size) {
|
||||||
|
u = t - size;
|
||||||
|
if (cmp(u, t) <= 0)
|
||||||
|
break;
|
||||||
|
swap(u, t);
|
||||||
|
}
|
||||||
|
}
|
@@ -100,7 +100,8 @@ __fdnlist(fd, list)
|
|||||||
int fd;
|
int fd;
|
||||||
struct nlist *list;
|
struct nlist *list;
|
||||||
{
|
{
|
||||||
int n = -1, i;
|
size_t i;
|
||||||
|
int n = -1;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) {
|
for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) {
|
||||||
n = (nlist_fn[i].fn)(fd, list);
|
n = (nlist_fn[i].fn)(fd, list);
|
||||||
@@ -138,7 +139,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 +228,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.
|
||||||
*/
|
*/
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user