mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-19 12:42:33 +02:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 |
208
COPYING
208
COPYING
@@ -66,7 +66,7 @@ for man/arc4random.3, man/tree.3 and man/getprogname.3.
|
|||||||
The rest of the licenses apply to code and/or man pages.
|
The rest of the licenses apply to code and/or man pages.
|
||||||
|
|
||||||
|
|
||||||
Copyright © 2004-2006, 2008-2011 Guillem Jover <guillem@hadrons.org>
|
Copyright © 2004-2006, 2008-2012 Guillem Jover <guillem@hadrons.org>
|
||||||
Copyright © 2005 Hector Garcia Alvarez
|
Copyright © 2005 Hector Garcia Alvarez
|
||||||
Copyright © 2005 Aurelien Jarno
|
Copyright © 2005 Aurelien Jarno
|
||||||
Copyright © 2006 Robert Millan
|
Copyright © 2006 Robert Millan
|
||||||
@@ -97,6 +97,7 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
Copyright © 1980, 1982, 1986, 1989-1994
|
Copyright © 1980, 1982, 1986, 1989-1994
|
||||||
The Regents of the University of California. All rights reserved.
|
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
|
Some code is derived from software contributed to Berkeley by
|
||||||
the American National Standards Committee X3, on Information
|
the American National Standards Committee X3, on Information
|
||||||
@@ -114,6 +115,9 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
Some code is derived from software contributed to Berkeley by
|
Some code is derived from software contributed to Berkeley by
|
||||||
Paul Vixie.
|
Paul Vixie.
|
||||||
|
|
||||||
|
Some code is derived from software contributed to Berkeley by
|
||||||
|
Chris Torek.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
are met:
|
are met:
|
||||||
@@ -197,7 +201,7 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright © 1997-2000, 2002, 2005, 2006, 2008 The NetBSD Foundation, Inc.
|
Copyright © 1997-2000, 2002, 2008 The NetBSD Foundation, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
||||||
@@ -233,7 +237,26 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright (c) 2009 Advanced Computing Technologies LLC
|
Copyright © 1998, M. Warner Losh <imp@freebsd.org>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Copyright © 2001 Dima Dorfman.
|
||||||
|
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>
|
Written by: John H. Baldwin <jhb@FreeBSD.org>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -260,58 +283,9 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright © 1998, M. Warner Losh <imp@freebsd.org>
|
Copyright © 1997 Christos Zoulas.
|
||||||
All rights reserved.
|
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 © 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.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Copyright © 2002 Niels Provos <provos@citi.umich.edu>
|
Copyright © 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -337,110 +311,6 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
Copyright © 2002 Thomas Moestl <tmm@FreeBSD.org>
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGE.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Copyright © 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGE.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Copyright © 2007 Eric Anderson <anderson@FreeBSD.org>
|
|
||||||
Copyright © 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGE.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
|
||||||
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
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
Copyright © 2007 Dag-Erling Coïdan Smørgrav
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
@@ -561,6 +431,30 @@ The rest of the licenses apply to code and/or man pages.
|
|||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
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.
|
This code implements the MD5 message-digest algorithm.
|
||||||
The algorithm is due to Ron Rivest. This code was
|
The algorithm is due to Ron Rivest. This code was
|
||||||
written by Colin Plumb in 1993, no copyright is claimed.
|
written by Colin Plumb in 1993, no copyright is claimed.
|
||||||
|
@@ -9,11 +9,8 @@ EXTRA_DIST = \
|
|||||||
get-version \
|
get-version \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
DISTCLEANFILES = ChangeLog
|
|
||||||
.PHONY: ChangeLog
|
|
||||||
|
|
||||||
ChangeLog:
|
|
||||||
git log --stat -C >$@
|
|
||||||
|
|
||||||
dist-hook:
|
dist-hook:
|
||||||
echo $(VERSION) >$(distdir)/.dist-version
|
echo $(VERSION) >$(distdir)/.dist-version
|
||||||
|
if [ -d .git ]; then \
|
||||||
|
git log --stat -C >$(distdir)/ChangeLog; \
|
||||||
|
fi
|
||||||
|
@@ -6,7 +6,7 @@ AC_CONFIG_SRCDIR([src/fgetln.c])
|
|||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([1.8 foreign nostdinc])
|
AM_INIT_AUTOMAKE([1.8 foreign nostdinc no-dist-gzip dist-xz])
|
||||||
|
|
||||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||||
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||||
@@ -38,6 +38,7 @@ AC_CHECK_HEADERS([sys/ndir.h sys/dir.h dir.h dirent.h])
|
|||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_TYPE_UID_T
|
AC_TYPE_UID_T
|
||||||
AC_C_INLINE
|
AC_C_INLINE
|
||||||
|
AC_C_TYPEOF
|
||||||
AC_TYPE_INT64_T
|
AC_TYPE_INT64_T
|
||||||
AC_TYPE_MODE_T
|
AC_TYPE_MODE_T
|
||||||
AC_TYPE_OFF_T
|
AC_TYPE_OFF_T
|
||||||
@@ -71,7 +72,7 @@ AC_LINK_IFELSE(
|
|||||||
AC_MSG_RESULT([yes])],
|
AC_MSG_RESULT([yes])],
|
||||||
[AC_MSG_RESULT([no])])
|
[AC_MSG_RESULT([no])])
|
||||||
|
|
||||||
AC_CHECK_FUNCS([dirfd __fpurge getexecname getline sysconf])
|
AC_CHECK_FUNCS([clearenv dirfd __fpurge getexecname getline sysconf])
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
|
@@ -21,4 +21,5 @@ nobase_include_HEADERS = \
|
|||||||
bsd/string.h \
|
bsd/string.h \
|
||||||
bsd/unistd.h \
|
bsd/unistd.h \
|
||||||
bsd/vis.h \
|
bsd/vis.h \
|
||||||
|
bsd/wchar.h \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
@@ -40,8 +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 <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/* for pidfile.c */
|
/* for pidfile.c */
|
||||||
struct pidfh {
|
struct pidfh {
|
||||||
@@ -62,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) */
|
||||||
@@ -73,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_ */
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
__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
|
||||||
|
|
||||||
|
47
include/bsd/wchar.h
Normal file
47
include/bsd/wchar.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef LIBBSD_OVERLAY
|
||||||
|
#include_next <wchar.h>
|
||||||
|
#else
|
||||||
|
#include <wchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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
|
@@ -24,8 +24,10 @@ dist_man_MANS = \
|
|||||||
dehumanize_number.3 \
|
dehumanize_number.3 \
|
||||||
expand_number.3 \
|
expand_number.3 \
|
||||||
fgetln.3 \
|
fgetln.3 \
|
||||||
|
fgetwln.3 \
|
||||||
flopen.3 \
|
flopen.3 \
|
||||||
fmtcheck.3 \
|
fmtcheck.3 \
|
||||||
|
fparseln.3 \
|
||||||
getmode.3 \
|
getmode.3 \
|
||||||
getpeereid.3 \
|
getpeereid.3 \
|
||||||
getprogname.3 \
|
getprogname.3 \
|
||||||
@@ -45,9 +47,12 @@ dist_man_MANS = \
|
|||||||
sradixsort.3 \
|
sradixsort.3 \
|
||||||
strlcat.3 \
|
strlcat.3 \
|
||||||
strlcpy.3 \
|
strlcpy.3 \
|
||||||
|
strnstr.3 \
|
||||||
strmode.3 \
|
strmode.3 \
|
||||||
strtonum.3 \
|
strtonum.3 \
|
||||||
tree.3 \
|
tree.3 \
|
||||||
unvis.3 \
|
unvis.3 \
|
||||||
vis.3 \
|
vis.3 \
|
||||||
|
wcslcat.3 \
|
||||||
|
wcslcpy.3 \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
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
|
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 .
|
@@ -1,3 +1,5 @@
|
|||||||
|
.\" $NetBSD: radixsort.3,v 1.12 2003/04/16 13:34:46 wiz Exp $
|
||||||
|
.\"
|
||||||
.\" Copyright (c) 1990, 1991, 1993
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
@@ -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.
|
||||||
.\"
|
.\"
|
||||||
@@ -25,14 +27,14 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
.\" from: @(#)radixsort.3 8.2 (Berkeley) 1/27/94
|
||||||
.\" $FreeBSD$
|
|
||||||
.\"
|
.\"
|
||||||
.Dd January 27, 1994
|
.Dd January 27, 1994
|
||||||
.Dt RADIXSORT 3
|
.Dt RADIXSORT 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm radixsort , sradixsort
|
.Nm radixsort ,
|
||||||
|
.Nm sradixsort
|
||||||
.Nd radix sort
|
.Nd radix sort
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||||
@@ -52,12 +54,17 @@ and
|
|||||||
functions
|
functions
|
||||||
are implementations of radix sort.
|
are implementations of radix sort.
|
||||||
.Pp
|
.Pp
|
||||||
These functions sort an array of pointers to byte strings, the initial
|
These functions sort an
|
||||||
member of which is referenced by
|
.Fa nmemb
|
||||||
|
element array of pointers to byte strings, with
|
||||||
|
the initial member of which is referenced by
|
||||||
.Fa base .
|
.Fa base .
|
||||||
The byte strings may contain any values; the end of each string
|
The byte strings may contain any values.
|
||||||
is denoted by the user-specified value
|
End of strings is denoted
|
||||||
|
by character which has same weight as user specified value
|
||||||
.Fa endbyte .
|
.Fa endbyte .
|
||||||
|
.Fa endbyte
|
||||||
|
has to be between 0 and 255.
|
||||||
.Pp
|
.Pp
|
||||||
Applications may specify a sort order by providing the
|
Applications may specify a sort order by providing the
|
||||||
.Fa table
|
.Fa table
|
||||||
|
@@ -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
|
||||||
@@ -40,34 +42,40 @@
|
|||||||
.Lb libbsd
|
.Lb libbsd
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In bsd/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 * .
|
||||||
|
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
|
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.
|
@@ -27,14 +27,14 @@ pkgconfig_DATA = \
|
|||||||
lib_LTLIBRARIES = libbsd.la
|
lib_LTLIBRARIES = libbsd.la
|
||||||
|
|
||||||
hash/md5hl.c: $(srcdir)/hash/helper.c
|
hash/md5hl.c: $(srcdir)/hash/helper.c
|
||||||
$(MKDIR_P) hash
|
$(AM_V_at) $(MKDIR_P) hash
|
||||||
$(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
|
$(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
|
||||||
|
|
||||||
libbsd_la_DEPENDENCIES = \
|
libbsd_la_DEPENDENCIES = \
|
||||||
libbsd.map
|
libbsd.map
|
||||||
libbsd_la_LDFLAGS = \
|
libbsd_la_LDFLAGS = \
|
||||||
-Wl,--version-script=$(srcdir)/libbsd.map \
|
-Wl,--version-script=$(srcdir)/libbsd.map \
|
||||||
-version-number 0:4:2
|
-version-number 0:5:1
|
||||||
libbsd_la_SOURCES = \
|
libbsd_la_SOURCES = \
|
||||||
arc4random.c \
|
arc4random.c \
|
||||||
bsd_getopt.c \
|
bsd_getopt.c \
|
||||||
@@ -43,8 +43,10 @@ libbsd_la_SOURCES = \
|
|||||||
err.c \
|
err.c \
|
||||||
expand_number.c \
|
expand_number.c \
|
||||||
fgetln.c \
|
fgetln.c \
|
||||||
|
fgetwln.c \
|
||||||
flopen.c \
|
flopen.c \
|
||||||
fmtcheck.c \
|
fmtcheck.c \
|
||||||
|
fparseln.c \
|
||||||
fpurge.c \
|
fpurge.c \
|
||||||
getpeereid.c \
|
getpeereid.c \
|
||||||
hash/md5.c \
|
hash/md5.c \
|
||||||
@@ -65,9 +67,12 @@ libbsd_la_SOURCES = \
|
|||||||
strlcat.c \
|
strlcat.c \
|
||||||
strlcpy.c \
|
strlcpy.c \
|
||||||
strmode.c \
|
strmode.c \
|
||||||
|
strnstr.c \
|
||||||
strtonum.c \
|
strtonum.c \
|
||||||
unvis.c \
|
unvis.c \
|
||||||
vis.c \
|
vis.c \
|
||||||
|
wcslcat.c \
|
||||||
|
wcslcpy.c \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
runtimelibdir = $(libdir)
|
runtimelibdir = $(libdir)
|
||||||
|
@@ -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 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,54 @@
|
|||||||
* 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;
|
||||||
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;
|
||||||
|
if (rval == UINT64_MAX && 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;
|
||||||
}
|
}
|
||||||
|
30
src/fgetln.c
30
src/fgetln.c
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005 Hector Garcia Alvarez
|
* Copyright © 2005 Hector Garcia Alvarez
|
||||||
* Copyright © 2005, 2008, 2009, 2011 Guillem Jover <guillem@hadrons.org>
|
* 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
|
||||||
@@ -31,21 +31,41 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef HAVE_GETLINE
|
#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
|
#else
|
||||||
|
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;
|
||||||
|
}
|
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 */
|
@@ -99,11 +99,13 @@ getpeereid(int s, uid_t *euid, gid_t *egid)
|
|||||||
}
|
}
|
||||||
#elif defined(__sun)
|
#elif defined(__sun)
|
||||||
/* Solaris */
|
/* Solaris */
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <ucred.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
getpeereid(int s, uid_t *euid, gid_t *egid)
|
getpeereid(int s, uid_t *euid, gid_t *egid)
|
||||||
{
|
{
|
||||||
ucred_t cred_inst;
|
ucred_t *cred = alloca(ucred_size());
|
||||||
ucred_t *cred = &cred_inst;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = getpeerucred(s, &cred);
|
ret = getpeerucred(s, &cred);
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -73,8 +73,6 @@ LIBBSD_0.2 {
|
|||||||
pidfile_close;
|
pidfile_close;
|
||||||
pidfile_remove;
|
pidfile_remove;
|
||||||
|
|
||||||
setproctitle;
|
|
||||||
|
|
||||||
arc4random_buf;
|
arc4random_buf;
|
||||||
arc4random_uniform;
|
arc4random_uniform;
|
||||||
} LIBBSD_0.1;
|
} LIBBSD_0.1;
|
||||||
@@ -94,3 +92,16 @@ LIBBSD_0.4 {
|
|||||||
closefrom;
|
closefrom;
|
||||||
expand_number;
|
expand_number;
|
||||||
} LIBBSD_0.3;
|
} 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;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2009 Guillem Jover <guillem@hadrons.org>
|
* 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
|
||||||
|
@@ -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);
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
/* $NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $ */
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1990, 1993
|
* Copyright (c) 1990, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -13,7 +14,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.
|
||||||
*
|
*
|
||||||
@@ -30,11 +31,14 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95";
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
#if 0
|
||||||
|
static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95";
|
||||||
|
#else
|
||||||
|
__RCSID("$NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $");
|
||||||
|
#endif
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Radixsort routines.
|
* Radixsort routines.
|
||||||
@@ -59,11 +63,10 @@ typedef struct {
|
|||||||
int sn, si;
|
int sn, si;
|
||||||
} stack;
|
} stack;
|
||||||
|
|
||||||
static inline void simplesort
|
static inline void simplesort(const u_char **, int, int, const u_char *, u_int);
|
||||||
(const u_char **, int, int, const u_char *, u_int);
|
|
||||||
static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
|
static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
|
||||||
static void r_sort_b(const u_char **, const u_char **, int, int,
|
static void r_sort_b(const u_char **,
|
||||||
const u_char *, u_int);
|
const u_char **, int, int, const u_char *, u_int);
|
||||||
|
|
||||||
#define THRESHOLD 20 /* Divert to simplesort(). */
|
#define THRESHOLD 20 /* Divert to simplesort(). */
|
||||||
#define SIZE 512 /* Default stack size. */
|
#define SIZE 512 /* Default stack size. */
|
||||||
@@ -88,13 +91,10 @@ static void r_sort_b(const u_char **, const u_char **, int, int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
radixsort(a, n, tab, endch)
|
radixsort(const u_char **a, int n, const u_char *tab, u_int endch)
|
||||||
const u_char **a, *tab;
|
|
||||||
int n;
|
|
||||||
u_int endch;
|
|
||||||
{
|
{
|
||||||
const u_char *tr;
|
const u_char *tr;
|
||||||
int c;
|
u_int c;
|
||||||
u_char tr0[256];
|
u_char tr0[256];
|
||||||
|
|
||||||
SETUP;
|
SETUP;
|
||||||
@@ -103,15 +103,17 @@ radixsort(a, n, tab, endch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sradixsort(a, n, tab, endch)
|
sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
|
||||||
const u_char **a, *tab;
|
|
||||||
int n;
|
|
||||||
u_int endch;
|
|
||||||
{
|
{
|
||||||
const u_char *tr, **ta;
|
const u_char *tr, **ta;
|
||||||
int c;
|
u_int c;
|
||||||
u_char tr0[256];
|
u_char tr0[256];
|
||||||
|
|
||||||
|
if (a == NULL) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
SETUP;
|
SETUP;
|
||||||
if (n < THRESHOLD)
|
if (n < THRESHOLD)
|
||||||
simplesort(a, n, 0, tr, endch);
|
simplesort(a, n, 0, tr, endch);
|
||||||
@@ -131,17 +133,13 @@ sradixsort(a, n, tab, endch)
|
|||||||
|
|
||||||
/* Unstable, in-place sort. */
|
/* Unstable, in-place sort. */
|
||||||
static void
|
static void
|
||||||
r_sort_a(a, n, i, tr, endch)
|
r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
|
||||||
const u_char **a;
|
|
||||||
int n, i;
|
|
||||||
const u_char *tr;
|
|
||||||
u_int endch;
|
|
||||||
{
|
{
|
||||||
static int count[256], nc, bmin;
|
static u_int count[256], nc, bmin;
|
||||||
int c;
|
u_int c;
|
||||||
const u_char **ak, *r;
|
const u_char **ak, *r;
|
||||||
stack s[SIZE], *sp, *sp0, *sp1, temp;
|
stack s[SIZE], *sp, *sp0, *sp1, temp;
|
||||||
int *cp, bigc;
|
u_int *cp, bigc;
|
||||||
const u_char **an, *t, **aj, **top[256];
|
const u_char **an, *t, **aj, **top[256];
|
||||||
|
|
||||||
/* Set up stack. */
|
/* Set up stack. */
|
||||||
@@ -177,7 +175,7 @@ r_sort_a(a, n, i, tr, endch)
|
|||||||
* character at position i, move on to the next
|
* character at position i, move on to the next
|
||||||
* character.
|
* character.
|
||||||
*/
|
*/
|
||||||
if (nc == 1 && count[bmin] == n) {
|
if (nc == 1 && count[bmin] == (u_int)n) {
|
||||||
push(a, n, i+1);
|
push(a, n, i+1);
|
||||||
nc = count[bmin] = 0;
|
nc = count[bmin] = 0;
|
||||||
continue;
|
continue;
|
||||||
@@ -233,18 +231,15 @@ r_sort_a(a, n, i, tr, endch)
|
|||||||
|
|
||||||
/* Stable sort, requiring additional memory. */
|
/* Stable sort, requiring additional memory. */
|
||||||
static void
|
static void
|
||||||
r_sort_b(a, ta, n, i, tr, endch)
|
r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr,
|
||||||
const u_char **a, **ta;
|
u_int endch)
|
||||||
int n, i;
|
|
||||||
const u_char *tr;
|
|
||||||
u_int endch;
|
|
||||||
{
|
{
|
||||||
static int count[256], nc, bmin;
|
static u_int count[256], nc, bmin;
|
||||||
int c;
|
u_int c;
|
||||||
const u_char **ak, **ai;
|
const u_char **ak, **ai;
|
||||||
stack s[512], *sp, *sp0, *sp1, temp;
|
stack s[512], *sp, *sp0, *sp1, temp;
|
||||||
const u_char **top[256];
|
const u_char **top[256];
|
||||||
int *cp, bigc;
|
u_int *cp, bigc;
|
||||||
|
|
||||||
sp = s;
|
sp = s;
|
||||||
push(a, n, i);
|
push(a, n, i);
|
||||||
@@ -304,12 +299,9 @@ r_sort_b(a, ta, n, i, tr, endch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* insertion sort */
|
||||||
static inline void
|
static inline void
|
||||||
simplesort(a, n, b, tr, endch) /* insertion sort */
|
simplesort(const u_char **a, int n, int b, const u_char *tr, u_int endch)
|
||||||
const u_char **a;
|
|
||||||
int n, b;
|
|
||||||
const u_char *tr;
|
|
||||||
u_int endch;
|
|
||||||
{
|
{
|
||||||
u_char ch;
|
u_char ch;
|
||||||
const u_char **ak, **ai, *s, *t;
|
const u_char **ak, **ai, *s, *t;
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* $NetBSD: setmode.c,v 1.34 2012/06/25 22:32:43 abs Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993, 1994
|
* Copyright (c) 1989, 1993, 1994
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -13,7 +15,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.
|
||||||
*
|
*
|
||||||
@@ -30,19 +32,23 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94";
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.11 2007/01/09 00:27:55 imp Exp $");
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
#if 0
|
||||||
|
static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94";
|
||||||
|
#else
|
||||||
|
__RCSID("$NetBSD: setmode.c,v 1.34 2012/06/25 22:32:43 abs Exp $");
|
||||||
|
#endif
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef SETMODE_DEBUG
|
#ifdef SETMODE_DEBUG
|
||||||
@@ -64,7 +70,7 @@ typedef struct bitcmd {
|
|||||||
#define CMD2_OBITS 0x08
|
#define CMD2_OBITS 0x08
|
||||||
#define CMD2_UBITS 0x10
|
#define CMD2_UBITS 0x10
|
||||||
|
|
||||||
static BITCMD *addcmd(BITCMD *, int, int, int, u_int);
|
static BITCMD *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t);
|
||||||
static void compress_mode(BITCMD *);
|
static void compress_mode(BITCMD *);
|
||||||
#ifdef SETMODE_DEBUG
|
#ifdef SETMODE_DEBUG
|
||||||
static void dumpmode(BITCMD *);
|
static void dumpmode(BITCMD *);
|
||||||
@@ -144,38 +150,38 @@ common: if (set->cmd2 & CMD2_CLR) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADDCMD(a, b, c, d) \
|
#define ADDCMD(a, b, c, d) do { \
|
||||||
if (set >= endset) { \
|
if (set >= endset) { \
|
||||||
BITCMD *newset; \
|
BITCMD *newset; \
|
||||||
setlen += SET_LEN_INCR; \
|
setlen += SET_LEN_INCR; \
|
||||||
newset = realloc(saveset, sizeof(BITCMD) * setlen); \
|
newset = realloc(saveset, sizeof(BITCMD) * setlen); \
|
||||||
if (!newset) { \
|
if (newset == NULL) \
|
||||||
if (saveset) \
|
goto out; \
|
||||||
free(saveset); \
|
|
||||||
saveset = NULL; \
|
|
||||||
return (NULL); \
|
|
||||||
} \
|
|
||||||
set = newset + (set - saveset); \
|
set = newset + (set - saveset); \
|
||||||
saveset = newset; \
|
saveset = newset; \
|
||||||
endset = newset + (setlen - 2); \
|
endset = newset + (setlen - 2); \
|
||||||
} \
|
} \
|
||||||
set = addcmd(set, (a), (b), (c), (d))
|
set = addcmd(set, (mode_t)(a), (mode_t)(b), (mode_t)(c), (d)); \
|
||||||
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
|
#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
|
||||||
|
|
||||||
void *
|
void *
|
||||||
setmode(const char *p)
|
setmode(const char *p)
|
||||||
{
|
{
|
||||||
int perm, who;
|
int serrno;
|
||||||
char op, *ep;
|
char op, *ep;
|
||||||
BITCMD *set, *saveset, *endset;
|
BITCMD *set, *saveset, *endset;
|
||||||
sigset_t sigset, sigoset;
|
sigset_t signset, sigoset;
|
||||||
mode_t mask;
|
mode_t mask, perm, permXbits, who;
|
||||||
int equalopdone=0, permXbits, setlen;
|
long lval;
|
||||||
long perml;
|
int equalopdone = 0; /* pacify gcc */
|
||||||
|
int setlen;
|
||||||
|
|
||||||
if (!*p)
|
if (!*p) {
|
||||||
return (NULL);
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a copy of the mask for the permissions that are mask relative.
|
* Get a copy of the mask for the permissions that are mask relative.
|
||||||
@@ -183,8 +189,8 @@ setmode(const char *p)
|
|||||||
* the caller is opening files inside a signal handler, protect them
|
* the caller is opening files inside a signal handler, protect them
|
||||||
* as best we can.
|
* as best we can.
|
||||||
*/
|
*/
|
||||||
sigfillset(&sigset);
|
sigfillset(&signset);
|
||||||
(void)sigprocmask(SIG_BLOCK, &sigset, &sigoset);
|
(void)sigprocmask(SIG_BLOCK, &signset, &sigoset);
|
||||||
(void)umask(mask = umask(0));
|
(void)umask(mask = umask(0));
|
||||||
mask = ~mask;
|
mask = ~mask;
|
||||||
(void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
|
(void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
|
||||||
@@ -201,12 +207,19 @@ setmode(const char *p)
|
|||||||
* or illegal bits.
|
* or illegal bits.
|
||||||
*/
|
*/
|
||||||
if (isdigit((unsigned char)*p)) {
|
if (isdigit((unsigned char)*p)) {
|
||||||
perml = strtol(p, &ep, 8);
|
errno = 0;
|
||||||
if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) {
|
lval = strtol(p, &ep, 8);
|
||||||
free(saveset);
|
if (*ep) {
|
||||||
return (NULL);
|
errno = EINVAL;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
perm = (mode_t)perml;
|
if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
|
||||||
|
goto out;
|
||||||
|
if (lval & ~(STANDARD_BITS|S_ISTXT)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
perm = (mode_t)lval;
|
||||||
ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
|
ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
|
||||||
set->cmd = 0;
|
set->cmd = 0;
|
||||||
return (saveset);
|
return (saveset);
|
||||||
@@ -238,8 +251,8 @@ setmode(const char *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
|
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
|
||||||
free(saveset);
|
errno = EINVAL;
|
||||||
return (NULL);
|
goto out;
|
||||||
}
|
}
|
||||||
if (op == '=')
|
if (op == '=')
|
||||||
equalopdone = 0;
|
equalopdone = 0;
|
||||||
@@ -251,13 +264,19 @@ getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
|
|||||||
perm |= S_IRUSR|S_IRGRP|S_IROTH;
|
perm |= S_IRUSR|S_IRGRP|S_IROTH;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/* If only "other" bits ignore set-id. */
|
/*
|
||||||
if (!who || who & ~S_IRWXO)
|
* If specific bits where requested and
|
||||||
|
* only "other" bits ignore set-id.
|
||||||
|
*/
|
||||||
|
if (who == 0 || (who & ~S_IRWXO))
|
||||||
perm |= S_ISUID|S_ISGID;
|
perm |= S_ISUID|S_ISGID;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
/* If only "other" bits ignore sticky. */
|
/*
|
||||||
if (!who || who & ~S_IRWXO) {
|
* If specific bits where requested and
|
||||||
|
* only "other" bits ignore set-id.
|
||||||
|
*/
|
||||||
|
if (who == 0 || (who & ~S_IRWXO)) {
|
||||||
who |= S_ISTXT;
|
who |= S_ISTXT;
|
||||||
perm |= S_ISTXT;
|
perm |= S_ISTXT;
|
||||||
}
|
}
|
||||||
@@ -328,10 +347,15 @@ apply: if (!*p)
|
|||||||
dumpmode(saveset);
|
dumpmode(saveset);
|
||||||
#endif
|
#endif
|
||||||
return (saveset);
|
return (saveset);
|
||||||
|
out:
|
||||||
|
serrno = errno;
|
||||||
|
free(saveset);
|
||||||
|
errno = serrno;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BITCMD *
|
static BITCMD *
|
||||||
addcmd(BITCMD *set, int op, int who, int oparg, u_int mask)
|
addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask)
|
||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case '=':
|
case '=':
|
||||||
|
@@ -1,32 +1,255 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2010 Guillem Jover <guillem@hadrons.org>
|
* Copyright © 2010 William Ahern
|
||||||
|
* Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* modification, are permitted provided that the following conditions
|
* copy of this software and associated documentation files (the
|
||||||
* are met:
|
* "Software"), to deal in the Software without restriction, including
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* persons to whom the Software is furnished to do so, subject to the
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* following conditions:
|
||||||
* 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,
|
* The above copyright notice and this permission notice shall be included
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
* in all copies or substantial portions of the Software.
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
*
|
||||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
#include <errno.h>
|
||||||
setproctitle(const char *fmt, ...)
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
/* Original value. */
|
||||||
|
const char *arg0;
|
||||||
|
|
||||||
|
/* Title space available. */
|
||||||
|
char *base, *end;
|
||||||
|
|
||||||
|
/* Pointer to original nul character within base. */
|
||||||
|
char *nul;
|
||||||
|
|
||||||
|
bool reset;
|
||||||
|
int error;
|
||||||
|
} SPT;
|
||||||
|
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
spt_min(size_t a, size_t b)
|
||||||
{
|
{
|
||||||
/* Stub so that we can implement it later on and programs will
|
return a < b ? a : b;
|
||||||
* automatically benefit from it, w/o needing to recompile. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For discussion on the portability of the various methods, see
|
||||||
|
* http://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
spt_clearenv(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_CLEARENV
|
||||||
|
return clearenv();
|
||||||
|
#else
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
|
tmp = malloc(sizeof(*tmp));
|
||||||
|
if (tmp == NULL)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
tmp[0] = NULL;
|
||||||
|
environ = tmp;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
spt_copyenv(char *oldenv[])
|
||||||
|
{
|
||||||
|
char *eq;
|
||||||
|
int i, error;
|
||||||
|
|
||||||
|
if (environ != oldenv)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error = spt_clearenv();
|
||||||
|
if (error) {
|
||||||
|
environ = oldenv;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; oldenv[i]; i++) {
|
||||||
|
eq = strchr(oldenv[i], '=');
|
||||||
|
if (eq == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
*eq = '\0';
|
||||||
|
if (setenv(oldenv[i], eq + 1, 1) < 0)
|
||||||
|
error = errno;
|
||||||
|
*eq = '=';
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
environ = oldenv;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
spt_copyargs(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 1; i < argc || (i >= argc && argv[i]); i++) {
|
||||||
|
if (argv[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tmp = strdup(argv[i]);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
argv[i] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __attribute__((constructor))
|
||||||
|
spt_init(int argc, char *argv[], char *envp[])
|
||||||
|
{
|
||||||
|
char *base, *end, *nul, *tmp;
|
||||||
|
int i, error;
|
||||||
|
|
||||||
|
base = argv[0];
|
||||||
|
if (base == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nul = &base[strlen(base)];
|
||||||
|
end = nul + 1;
|
||||||
|
|
||||||
|
for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
|
||||||
|
if (argv[i] == NULL || argv[i] < end)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
end = argv[i] + strlen(argv[i]) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; envp[i]; i++) {
|
||||||
|
if (envp[i] < end)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
end = envp[i] + strlen(envp[i]) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPT.arg0 = strdup(argv[0]);
|
||||||
|
if (SPT.arg0 == NULL) {
|
||||||
|
SPT.error = errno;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = strdup(getprogname());
|
||||||
|
if (tmp == NULL) {
|
||||||
|
SPT.error = errno;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setprogname(tmp);
|
||||||
|
|
||||||
|
error = spt_copyenv(envp);
|
||||||
|
if (error) {
|
||||||
|
SPT.error = error;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = spt_copyargs(argc, argv);
|
||||||
|
if (error) {
|
||||||
|
SPT.error = error;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPT.nul = nul;
|
||||||
|
SPT.base = base;
|
||||||
|
SPT.end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef SPT_MAXTITLE
|
||||||
|
#define SPT_MAXTITLE 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
setproctitle_impl(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
/* Use buffer in case argv[0] is passed. */
|
||||||
|
char buf[SPT_MAXTITLE + 1];
|
||||||
|
va_list ap;
|
||||||
|
char *nul;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (SPT.base == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fmt) {
|
||||||
|
if (fmt[0] == '-') {
|
||||||
|
/* Skip program name prefix. */
|
||||||
|
fmt++;
|
||||||
|
len = 0;
|
||||||
|
} else {
|
||||||
|
/* Print program name heading for grep. */
|
||||||
|
snprintf(buf, sizeof(buf), "%s: ", getprogname());
|
||||||
|
len = strlen(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len += vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
} else {
|
||||||
|
len = snprintf(buf, sizeof(buf), "%s", SPT.arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len <= 0) {
|
||||||
|
SPT.error = errno;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SPT.reset) {
|
||||||
|
memset(SPT.base, 0, SPT.end - SPT.base);
|
||||||
|
SPT.reset = true;
|
||||||
|
} else {
|
||||||
|
memset(SPT.base, 0, spt_min(sizeof(buf), SPT.end - SPT.base));
|
||||||
|
}
|
||||||
|
|
||||||
|
len = spt_min(len, spt_min(sizeof(buf), SPT.end - SPT.base) - 1);
|
||||||
|
memcpy(SPT.base, buf, len);
|
||||||
|
nul = &SPT.base[len];
|
||||||
|
|
||||||
|
if (nul < SPT.nul) {
|
||||||
|
*SPT.nul = '.';
|
||||||
|
} else if (nul == SPT.nul && &nul[1] < SPT.end) {
|
||||||
|
*SPT.nul = ' ';
|
||||||
|
*++nul = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
|
||||||
|
|
||||||
|
#ifdef HAVE_TYPEOF
|
||||||
|
/* The original function introduced in 0.2 was a stub, it only got implemented
|
||||||
|
* in 0.5, make the implementation available in the old version as an alias
|
||||||
|
* for code linking against that version, and change the default to use the
|
||||||
|
* new version, so that new code depends on the implemented version. */
|
||||||
|
extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl")));
|
||||||
|
__asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
|
||||||
|
#endif
|
||||||
|
65
src/strnstr.c
Normal file
65
src/strnstr.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||||
|
* Copyright (c) 1990, 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.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the first occurrence of find in s, where the search is limited to the
|
||||||
|
* first slen characters of s.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
strnstr(const char *s, const char *find, size_t slen)
|
||||||
|
{
|
||||||
|
char c, sc;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if ((c = *find++) != '\0') {
|
||||||
|
len = strlen(find);
|
||||||
|
do {
|
||||||
|
do {
|
||||||
|
if (slen-- < 1 || (sc = *s++) == '\0')
|
||||||
|
return (NULL);
|
||||||
|
} while (sc != c);
|
||||||
|
if (len > slen)
|
||||||
|
return (NULL);
|
||||||
|
} while (strncmp(s, find, len) != 0);
|
||||||
|
s--;
|
||||||
|
}
|
||||||
|
return ((char *)s);
|
||||||
|
}
|
74
src/wcslcat.c
Normal file
74
src/wcslcat.c
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
* 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. 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.
|
||||||
|
*
|
||||||
|
* from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if 0
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
__RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
#endif
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Appends src to string dst of size siz (unlike wcsncat, siz is the
|
||||||
|
* full size of dst, not space left). At most siz-1 characters
|
||||||
|
* will be copied. Always NUL terminates (unless siz == 0).
|
||||||
|
* Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
|
||||||
|
* truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
|
{
|
||||||
|
wchar_t *d = dst;
|
||||||
|
const wchar_t *s = src;
|
||||||
|
size_t n = siz;
|
||||||
|
size_t dlen;
|
||||||
|
|
||||||
|
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||||
|
while (*d != '\0' && n-- != 0)
|
||||||
|
d++;
|
||||||
|
dlen = d - dst;
|
||||||
|
n = siz - dlen;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return(dlen + wcslen(s));
|
||||||
|
while (*s != '\0') {
|
||||||
|
if (n != 1) {
|
||||||
|
*d++ = *s;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
*d = '\0';
|
||||||
|
|
||||||
|
return(dlen + (s - src)); /* count does not include NUL */
|
||||||
|
}
|
70
src/wcslcpy.c
Normal file
70
src/wcslcpy.c
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
* 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. 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.
|
||||||
|
*
|
||||||
|
* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if 0
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
#endif
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy src to string dst of size siz. At most siz-1 characters
|
||||||
|
* will be copied. Always NUL terminates (unless siz == 0).
|
||||||
|
* Returns wcslen(src); if retval >= siz, truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
|
{
|
||||||
|
wchar_t *d = dst;
|
||||||
|
const wchar_t *s = src;
|
||||||
|
size_t n = siz;
|
||||||
|
|
||||||
|
/* Copy as many bytes as will fit */
|
||||||
|
if (n != 0 && --n != 0) {
|
||||||
|
do {
|
||||||
|
if ((*d++ = *s++) == 0)
|
||||||
|
break;
|
||||||
|
} while (--n != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||||
|
if (n == 0) {
|
||||||
|
if (siz != 0)
|
||||||
|
*d = '\0'; /* NUL-terminate dst */
|
||||||
|
while (*s++)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(s - src - 1); /* count does not include NUL */
|
||||||
|
}
|
3
test/.gitignore
vendored
3
test/.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
endian
|
endian
|
||||||
|
fgetln
|
||||||
headers
|
headers
|
||||||
|
humanize
|
||||||
overlay
|
overlay
|
||||||
|
proctitle
|
||||||
|
@@ -11,6 +11,13 @@ check_PROGRAMS = \
|
|||||||
headers \
|
headers \
|
||||||
overlay \
|
overlay \
|
||||||
endian \
|
endian \
|
||||||
|
humanize \
|
||||||
|
fgetln \
|
||||||
|
proctitle \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
|
humanize_LDFLAGS = $(top_builddir)/src/libbsd.la
|
||||||
|
fgetln_LDFLAGS = $(top_builddir)/src/libbsd.la
|
||||||
|
proctitle_LDFLAGS = $(top_builddir)/src/libbsd.la
|
||||||
|
|
||||||
TESTS = $(check_PROGRAMS)
|
TESTS = $(check_PROGRAMS)
|
||||||
|
263
test/fgetln.c
Normal file
263
test/fgetln.c
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 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/wait.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#define skip(msg) \
|
||||||
|
do { \
|
||||||
|
printf("skip: %s\n", (msg)); \
|
||||||
|
return; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define DATA_LINES 3
|
||||||
|
|
||||||
|
static const char *data_ascii[] = {
|
||||||
|
"this represents an ascii sequence of lines to test the\n",
|
||||||
|
"fgetln() family of functions\n",
|
||||||
|
"last line without an ending newline",
|
||||||
|
};
|
||||||
|
static const wchar_t *data_wide[] = {
|
||||||
|
L"this represénts an utf-8 seqüence of lînes to test the\n",
|
||||||
|
L"«fgetln()» family of functions § but with an extremely long "
|
||||||
|
"line to test that the reallocation logic works fine, and that "
|
||||||
|
"the strings end up being equal…\n",
|
||||||
|
L"last line ☭ without an ‽ ending newline ♥",
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FILE_COUNT 32
|
||||||
|
|
||||||
|
#define LINE_COUNT 2
|
||||||
|
#define LINE_LEN 2
|
||||||
|
|
||||||
|
struct file {
|
||||||
|
FILE *fp;
|
||||||
|
const void **lines;
|
||||||
|
|
||||||
|
const void *got_buf;
|
||||||
|
int got_len;
|
||||||
|
};
|
||||||
|
|
||||||
|
static FILE *
|
||||||
|
pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int rc;
|
||||||
|
int pipefd[2];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
rc = pipe(pipefd);
|
||||||
|
assert(rc >= 0);
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
assert(pid >= 0);
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
int line;
|
||||||
|
|
||||||
|
/* Child writes data to pipe. */
|
||||||
|
rc = close(pipefd[0]);
|
||||||
|
assert(rc >= 0);
|
||||||
|
|
||||||
|
fp = fdopen(pipefd[1], "w");
|
||||||
|
assert(fp);
|
||||||
|
|
||||||
|
for (line = 0; line < buf_nmemb; line++) {
|
||||||
|
rc = fprintf(fp, fmt, buf[line]);
|
||||||
|
assert(rc >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = fclose(fp);
|
||||||
|
assert(rc >= 0);
|
||||||
|
|
||||||
|
_exit(0);
|
||||||
|
} else {
|
||||||
|
/* Parent gets a FILE and reads from it. */
|
||||||
|
rc = close(pipefd[1]);
|
||||||
|
assert(rc >= 0);
|
||||||
|
|
||||||
|
fp = fdopen(pipefd[0], "r");
|
||||||
|
assert(fp);
|
||||||
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
pipe_close(FILE *fp)
|
||||||
|
{
|
||||||
|
fclose(fp);
|
||||||
|
wait(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fgetln_single(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
size_t len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
fp = pipe_feed("%s", (const void **)data_ascii, DATA_LINES);
|
||||||
|
for (i = 0; i < DATA_LINES; i++) {
|
||||||
|
char *str = fgetln(fp, &len);
|
||||||
|
|
||||||
|
assert(str);
|
||||||
|
assert(memcmp(str, data_ascii[i], len) == 0);
|
||||||
|
}
|
||||||
|
assert(fgetln(fp, &len) == NULL);
|
||||||
|
pipe_close(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fgetln_multi(void)
|
||||||
|
{
|
||||||
|
struct file files[FILE_COUNT];
|
||||||
|
int i, l;
|
||||||
|
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = strdup("A\n");
|
||||||
|
str[0] += i;
|
||||||
|
|
||||||
|
files[i].lines = malloc(sizeof(char *) * LINE_COUNT);
|
||||||
|
files[i].lines[0] = str;
|
||||||
|
files[i].lines[1] = str;
|
||||||
|
files[i].fp = pipe_feed("%s", files[i].lines, LINE_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l = 0; l < LINE_COUNT; l++) {
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
size_t len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = fgetln(files[i].fp, &len);
|
||||||
|
|
||||||
|
assert(str);
|
||||||
|
assert(len == LINE_LEN);
|
||||||
|
|
||||||
|
files[i].got_len = len;
|
||||||
|
files[i].got_buf = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
assert(memcmp(files[i].lines[l], files[i].got_buf,
|
||||||
|
files[i].got_len) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < LINE_COUNT; i++)
|
||||||
|
pipe_close(files[i].fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fgetwln_single(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
size_t len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
fp = pipe_feed("%ls", (const void **)data_wide, DATA_LINES);
|
||||||
|
for (i = 0; i < DATA_LINES; i++) {
|
||||||
|
wchar_t *wstr;
|
||||||
|
|
||||||
|
wstr = fgetwln(fp, &len);
|
||||||
|
assert(wstr);
|
||||||
|
|
||||||
|
assert(wmemcmp(data_wide[i], wstr, len) == 0);
|
||||||
|
}
|
||||||
|
assert(fgetwln(fp, &len) == NULL);
|
||||||
|
pipe_close(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fgetwln_multi(void)
|
||||||
|
{
|
||||||
|
struct file files[FILE_COUNT];
|
||||||
|
int i, l;
|
||||||
|
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
wchar_t *wstr;
|
||||||
|
|
||||||
|
wstr = wcsdup(L"A\n");
|
||||||
|
wstr[0] += i;
|
||||||
|
|
||||||
|
files[i].lines = malloc(sizeof(char *) * LINE_COUNT);
|
||||||
|
files[i].lines[0] = wstr;
|
||||||
|
files[i].lines[1] = wstr;
|
||||||
|
files[i].fp = pipe_feed("%ls", files[i].lines, LINE_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l = 0; l < LINE_COUNT; l++) {
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
size_t len;
|
||||||
|
wchar_t *wstr;
|
||||||
|
|
||||||
|
wstr = fgetwln(files[i].fp, &len);
|
||||||
|
|
||||||
|
assert(wstr);
|
||||||
|
assert(len == LINE_LEN);
|
||||||
|
|
||||||
|
files[i].got_len = len;
|
||||||
|
files[i].got_buf = wstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < FILE_COUNT; i++) {
|
||||||
|
assert(wmemcmp(files[i].lines[l], files[i].got_buf,
|
||||||
|
files[i].got_len) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < LINE_COUNT; i++)
|
||||||
|
pipe_close(files[i].fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_fgetwln(void)
|
||||||
|
{
|
||||||
|
if (setlocale(LC_ALL, "C.UTF-8") == NULL &&
|
||||||
|
setlocale(LC_ALL, "en_US.UTF-8") == NULL)
|
||||||
|
skip("no default UTF-8 locale found");
|
||||||
|
|
||||||
|
test_fgetwln_single();
|
||||||
|
test_fgetwln_multi();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
test_fgetln_single();
|
||||||
|
test_fgetln_multi();
|
||||||
|
test_fgetwln();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
64
test/humanize.c
Normal file
64
test/humanize.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 Guillem Jover <guillem@hadrons.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
uint64_t uval;
|
||||||
|
int64_t val;
|
||||||
|
|
||||||
|
assert(expand_number("512", &uval) == 0);
|
||||||
|
assert(uval == 512);
|
||||||
|
|
||||||
|
assert(expand_number("512b", &uval) == 0);
|
||||||
|
assert(uval == 512);
|
||||||
|
|
||||||
|
assert(expand_number("10k", &uval) == 0);
|
||||||
|
assert(uval == 10240);
|
||||||
|
|
||||||
|
assert(expand_number("20M", &uval) == 0);
|
||||||
|
assert(uval == 20971520);
|
||||||
|
|
||||||
|
assert(dehumanize_number("512", &val) == 0);
|
||||||
|
assert(val == 512);
|
||||||
|
|
||||||
|
assert(dehumanize_number("512b", &val) == 0);
|
||||||
|
assert(val == 512);
|
||||||
|
|
||||||
|
assert(dehumanize_number("10k", &val) == 0);
|
||||||
|
assert(val == 10240);
|
||||||
|
|
||||||
|
assert(dehumanize_number("20M", &val) == 0);
|
||||||
|
assert(val == 20971520);
|
||||||
|
|
||||||
|
assert(dehumanize_number("-3G", &val) == 0);
|
||||||
|
assert(val == -3221225472LL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
48
test/proctitle.c
Normal file
48
test/proctitle.c
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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/types.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
const char newtitle_base[] = "test arg1 arg2";
|
||||||
|
char *newtitle_full;
|
||||||
|
|
||||||
|
setproctitle("-test %s arg2", "arg1");
|
||||||
|
assert(strcmp(argv[0], newtitle_base) == 0);
|
||||||
|
|
||||||
|
asprintf(&newtitle_full, "%s: %s", getprogname(), newtitle_base);
|
||||||
|
setproctitle("test %s arg2", "arg1");
|
||||||
|
assert(strcmp(argv[0], newtitle_full) == 0);
|
||||||
|
free(newtitle_full);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user