mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2025-09-10 07:59:52 +02:00
Compare commits
195 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74ba433a14 | ||
|
|
c980b0566a | ||
|
|
31896c21c6 | ||
|
|
773a88d33f | ||
|
|
cd78f85b0b | ||
|
|
2061cd8aa6 | ||
|
|
0c91ae335d | ||
|
|
0e40e9de57 | ||
|
|
0a3f944791 | ||
|
|
fa391362e1 | ||
|
|
8c243ff965 | ||
|
|
86cef85b36 | ||
|
|
65ba955988 | ||
|
|
dac5f12c6e | ||
|
|
26d3d090bd | ||
|
|
1eaacac312 | ||
|
|
5d0b158f4c | ||
|
|
982504452d | ||
|
|
48cae1e864 | ||
|
|
022889a457 | ||
|
|
adc62b5d9f | ||
|
|
1f4fcd083d | ||
|
|
9c8e4f6918 | ||
|
|
ed85df444a | ||
|
|
0dc4478f13 | ||
|
|
8ed84c3438 | ||
|
|
c55c0e7369 | ||
|
|
e3e9713fad | ||
|
|
6b8578af5e | ||
|
|
04d49874a2 | ||
|
|
18810ae65f | ||
|
|
d3dcb10f90 | ||
|
|
52b4d2a51a | ||
|
|
2b32399fdc | ||
|
|
44421c22a3 | ||
|
|
61a42e3743 | ||
|
|
60ca9e1599 | ||
|
|
0889381cbf | ||
|
|
1bdf77ad52 | ||
|
|
05a50b7848 | ||
|
|
2f61473e85 | ||
|
|
460ebb078e | ||
|
|
0d5508de13 | ||
|
|
ddf56e0440 | ||
|
|
2fbee63cc9 | ||
|
|
b27275c668 | ||
|
|
016f8c9998 | ||
|
|
10f3e12a0d | ||
|
|
83ae1bdd44 | ||
|
|
2a8f5104cd | ||
|
|
065f14f471 | ||
|
|
9a45c19667 | ||
|
|
f6240c49df | ||
|
|
b52a88607f | ||
|
|
f15842de47 | ||
|
|
c926d002b5 | ||
|
|
31b6c0489a | ||
|
|
a488f288a2 | ||
|
|
a7592cfcb2 | ||
|
|
3288ebb0d7 | ||
|
|
9934f50282 | ||
|
|
46d6df933e | ||
|
|
7b1967351c | ||
|
|
d01338eb3d | ||
|
|
a99c35b04d | ||
|
|
5e3a5ae519 | ||
|
|
1fd718e93c | ||
|
|
972967903d | ||
|
|
e0035fa4eb | ||
|
|
99be907838 | ||
|
|
1ead085826 | ||
|
|
695682d514 | ||
|
|
442d63051c | ||
|
|
7fc5292a29 | ||
|
|
cf5616a0aa | ||
|
|
13601dd3cf | ||
|
|
1ee192a9ff | ||
|
|
cbecb8cab8 | ||
|
|
fb992bae4c | ||
|
|
ac9e4915ad | ||
|
|
92465d59c6 | ||
|
|
921feefb12 | ||
|
|
0c65638b0f | ||
|
|
5c065bb0cb | ||
|
|
680afe6751 | ||
|
|
0fcf730104 | ||
|
|
f144582e17 | ||
|
|
9a913a2461 | ||
|
|
317d2c6384 | ||
|
|
292d68565a | ||
|
|
c352bb469d | ||
|
|
22a2a43021 | ||
|
|
4000c35ae3 | ||
|
|
99eccc3359 | ||
|
|
9965d234e5 | ||
|
|
a011b01af1 | ||
|
|
28fbe5a487 | ||
|
|
9b8023e69c | ||
|
|
b8497a3a7a | ||
|
|
c2e56e0de7 | ||
|
|
031e2fb5e9 | ||
|
|
e181802521 | ||
|
|
c58b5daa33 | ||
|
|
80325aca2d | ||
|
|
d3b5555f10 | ||
|
|
ca738e4414 | ||
|
|
21eb87e6ea | ||
|
|
7ef56a26fd | ||
|
|
aa2617b908 | ||
|
|
016958f2f0 | ||
|
|
1ce9d86c30 | ||
|
|
00b5a2db33 | ||
|
|
e34894bf3f | ||
|
|
b14e5c40b9 | ||
|
|
90f74735aa | ||
|
|
d6a62182f0 | ||
|
|
847ab6a518 | ||
|
|
b5b3690d06 | ||
|
|
57e2022b8d | ||
|
|
be6b4218e4 | ||
|
|
48a05a9ce9 | ||
|
|
fc3b301d4f | ||
|
|
c7e971bee0 | ||
|
|
b0312caf6f | ||
|
|
1c318d52de | ||
|
|
186b655094 | ||
|
|
8333cc3c0f | ||
|
|
c27c4a0957 | ||
|
|
a5e53ecc2c | ||
|
|
d5ab05998c | ||
|
|
a2be861b04 | ||
|
|
fbd87029cf | ||
|
|
3ece0355d5 | ||
|
|
1760ade090 | ||
|
|
ed017d44b2 | ||
|
|
8b09875b59 | ||
|
|
4e38e6a19c | ||
|
|
b3e779c090 | ||
|
|
17409787bb | ||
|
|
ac819e1044 | ||
|
|
36eb45201f | ||
|
|
b43255473f | ||
|
|
90a83264b9 | ||
|
|
43448b0493 | ||
|
|
854284f788 | ||
|
|
0e2ac2de24 | ||
|
|
03911ef780 | ||
|
|
32d4d0dd5e | ||
|
|
cfa2120e83 | ||
|
|
1c5e5d6277 | ||
|
|
41ec3548b0 | ||
|
|
5b27ec57b0 | ||
|
|
1e48b1fee5 | ||
|
|
5dc070cc86 | ||
|
|
b4ec994b26 | ||
|
|
2bf151cd93 | ||
|
|
153477479a | ||
|
|
fec0e89c20 | ||
|
|
407e8f0fdd | ||
|
|
461231f022 | ||
|
|
b705e9a9e7 | ||
|
|
b3677e5e38 | ||
|
|
cc0f637b6d | ||
|
|
7920f2c14a | ||
|
|
99f4994982 | ||
|
|
5afac2aee1 | ||
|
|
aa67daf63b | ||
|
|
f7a009c17c | ||
|
|
028e12ce3b | ||
|
|
f3f1ccfd87 | ||
|
|
08c38ab7cb | ||
|
|
d60e33e241 | ||
|
|
31a884dab7 | ||
|
|
74443830ea | ||
|
|
2ae61facc7 | ||
|
|
bb7fa1e932 | ||
|
|
16c8062085 | ||
|
|
17278118ee | ||
|
|
7f6fb43e7d | ||
|
|
ddc409b59e | ||
|
|
7eb3aab88b | ||
|
|
4fb3704c25 | ||
|
|
514b7fbc00 | ||
|
|
555c219d9e | ||
|
|
59964c164b | ||
|
|
7377f49ea8 | ||
|
|
969841cb77 | ||
|
|
c3e1fe230b | ||
|
|
1833a876ae | ||
|
|
0f5695bd59 | ||
|
|
42df6d7de2 | ||
|
|
9c0c57a1b4 | ||
|
|
a36f4cb451 | ||
|
|
ed0a1c9f94 | ||
|
|
f9da2d0e87 |
@@ -1 +1 @@
|
||||
6.12
|
||||
7.0
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
ChangeLog(-[0-9]+)?$
|
||||
^old/
|
||||
^src/c99-to-c98\.diff$
|
||||
^gl/.*
|
||||
1
.x-sc_po_check
Normal file
1
.x-sc_po_check
Normal file
@@ -0,0 +1 @@
|
||||
^gl/
|
||||
@@ -1,6 +1 @@
|
||||
ChangeLog
|
||||
^TODO$
|
||||
^lib/euidaccess-stat\.c$
|
||||
^maint\.mk$
|
||||
^doc/coreutils.texi$
|
||||
^tests/misc/stty-invalid$
|
||||
|
||||
4
.x-sc_prohibit_stat_st_blocks
Normal file
4
.x-sc_prohibit_stat_st_blocks
Normal file
@@ -0,0 +1,4 @@
|
||||
src/system.h
|
||||
tests/du/2g
|
||||
old/fileutils/ChangeLog-1997
|
||||
ChangeLog-2005
|
||||
@@ -1,2 +1 @@
|
||||
^src/system\.h
|
||||
ChangeLog
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
^lib/at-func\.c$
|
||||
^lib/bcopy\.c$
|
||||
^lib/buffer-lcm\.c$
|
||||
^lib/c-strtold\.c$
|
||||
^lib/fnmatch_loop\.c$
|
||||
^lib/full-read\.c$
|
||||
^lib/imaxtostr\.c$
|
||||
^lib/mempcpy\.c$
|
||||
^lib/memset\.c$
|
||||
^lib/offtostr\.c$
|
||||
^lib/regcomp\.c$
|
||||
^lib/regex_internal\.c$
|
||||
^lib/regexec\.c$
|
||||
^lib/safe-write\.c$
|
||||
^lib/strtoll\.c$
|
||||
^lib/strtoul\.c$
|
||||
^lib/strtoull\.c$
|
||||
^lib/strtoumax\.c$
|
||||
^lib/umaxtostr\.c$
|
||||
^lib/xstrtold\.c$
|
||||
^lib/xstrtoul\.c$
|
||||
^src/false\.c$
|
||||
^src/lbracket\.c$
|
||||
^src/ls-dir\.c$
|
||||
^src/ls-ls\.c$
|
||||
^src/ls-vdir\.c$
|
||||
^src/rand-isaac\.c$
|
||||
^src/tac-pipe\.c$
|
||||
^src/uname-arch\.c$
|
||||
^src/uname-uname\.c$
|
||||
|
||||
9
.x-sc_require_config_h_first
Normal file
9
.x-sc_require_config_h_first
Normal file
@@ -0,0 +1,9 @@
|
||||
^lib/buffer-lcm\.c$
|
||||
^src/false\.c$
|
||||
^src/lbracket\.c$
|
||||
^src/ls-dir\.c$
|
||||
^src/ls-ls\.c$
|
||||
^src/ls-vdir\.c$
|
||||
^src/tac-pipe\.c$
|
||||
^src/uname-arch\.c$
|
||||
^src/uname-uname\.c$
|
||||
2
AUTHORS
2
AUTHORS
@@ -25,7 +25,7 @@ du: Torbjörn Granlund, David MacKenzie, Paul Eggert, Jim Meyering
|
||||
echo: Brian Fox, Chet Ramey
|
||||
env: Richard Mlynarik, David MacKenzie
|
||||
expand: David MacKenzie
|
||||
expr: Mike Parker, James Youngman
|
||||
expr: Mike Parker, James Youngman, Paul Eggert
|
||||
factor: Paul Rubin
|
||||
false: Jim Meyering
|
||||
fmt: Ross Paterson
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
2008-12-16 Jim Meyering <meyering@redhat.com>
|
||||
|
||||
NB: ChangeLog files are no longer manually maintained.
|
||||
See HACKING for details.
|
||||
|
||||
2008-02-07 Jim Meyering <meyering@redhat.com>
|
||||
|
||||
We *do* need two different version files.
|
||||
|
||||
29
HACKING
29
HACKING
@@ -32,9 +32,14 @@ inside your new coreutils/ directory:
|
||||
If you have made *no* changes:
|
||||
git pull
|
||||
|
||||
If you *have* made changes and committed them to "master", do this:
|
||||
git fetch
|
||||
git rebase origin
|
||||
If you *have* made changes and mistakenly committed them to "master",
|
||||
do the following to put your changes on a private branch, "br", and
|
||||
to restore master to its unmodified (relative-to-upstream) state:
|
||||
git checkout -b br
|
||||
git checkout master
|
||||
git reset --hard origin
|
||||
|
||||
Then "git pull" should work.
|
||||
|
||||
|
||||
*Before* you commit changes
|
||||
@@ -288,7 +293,9 @@ Nearly every significant change must be accompanied by a test suite
|
||||
addition that exercises it. If you fix a bug, add at least one test that
|
||||
fails without the patch, but that succeeds once your patch is applied.
|
||||
If you add a feature, add tests to exercise as much of the new code
|
||||
as possible.
|
||||
as possible. Note to run tests/misc/newtest in isolation you can do:
|
||||
|
||||
(cd tests && make check TESTS=misc/newtest VERBOSE=yes)
|
||||
|
||||
There are hundreds of tests in the tests/ directories. You can use
|
||||
tests/sample-test as a template, or one of the various Perl-based ones
|
||||
@@ -323,6 +330,10 @@ you'd use doc/Copyright/request-assign.future:
|
||||
|
||||
You may make assignments for up to four projects at a time.
|
||||
|
||||
In case you're wondering why we bother with all of this, read this:
|
||||
|
||||
http://www.gnu.org/licenses/why-assign.html
|
||||
|
||||
|
||||
Run "make syntax-check", or even "make distcheck"
|
||||
================================================
|
||||
@@ -402,3 +413,13 @@ to generate HTML coverage reports. Follow these steps:
|
||||
|
||||
Then just open the index.html file (in the generated lcov-html directory)
|
||||
in your favorite web browser.
|
||||
|
||||
========================================================================
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
any later version published by the Free Software Foundation; with no
|
||||
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||
Texts. A copy of the license is included in the ``GNU Free
|
||||
Documentation License'' file as part of this distribution.
|
||||
|
||||
@@ -20,12 +20,13 @@ EXTRA_DIST = cfg.mk maint.mk \
|
||||
.prev-version THANKS-to-translators THANKStt.in \
|
||||
.version \
|
||||
.vg-suppressions \
|
||||
.x-po-check \
|
||||
.x-sc_GPL_version \
|
||||
.x-sc_file_system \
|
||||
.x-sc_obsolete_symbols \
|
||||
.x-sc_po_check \
|
||||
.x-sc_program_name \
|
||||
.x-sc_prohibit_atoi_atof \
|
||||
.x-sc_prohibit_stat_st_blocks \
|
||||
.x-sc_prohibit_strcmp \
|
||||
.x-sc_require_config_h \
|
||||
.x-sc_space_tab .x-sc_sun_os_names \
|
||||
@@ -101,8 +102,8 @@ MAINTAINERCLEANFILES = THANKS-to-translators
|
||||
THANKS-to-translators: po/LINGUAS THANKStt.in
|
||||
( \
|
||||
cat $(srcdir)/THANKStt.in; \
|
||||
for lang in `cat $(srcdir)/po/LINGUAS`; do \
|
||||
echo http://www.iro.umontreal.ca/contrib/po/HTML/team-$$lang.html; \
|
||||
for lang in `cat $(srcdir)/po/LINGUAS`; do \
|
||||
echo http://translationproject.org/team/$$lang.html; \
|
||||
done; \
|
||||
) > $@-tmp && mv $@-tmp $@
|
||||
|
||||
|
||||
72
NEWS
72
NEWS
@@ -1,5 +1,74 @@
|
||||
GNU coreutils NEWS -*- outline -*-
|
||||
|
||||
* Noteworthy changes in release 7.1 (2009-02-21) [stable]
|
||||
|
||||
** New features
|
||||
|
||||
Add extended attribute support available on certain filesystems like ext2
|
||||
and XFS.
|
||||
cp: Tries to copy xattrs when --preserve=xattr or --preserve=all specified
|
||||
mv: Always tries to copy xattrs
|
||||
install: Never copies xattrs
|
||||
|
||||
cp and mv accept a new option, --no-clobber (-n): silently refrain
|
||||
from overwriting any existing destination file
|
||||
|
||||
dd accepts iflag=cio and oflag=cio to open the file in CIO (concurrent I/O)
|
||||
mode where this feature is available.
|
||||
|
||||
install accepts a new option, --compare (-C): compare each pair of source
|
||||
and destination files, and if the destination has identical content and
|
||||
any specified owner, group, permissions, and possibly SELinux context, then
|
||||
do not modify the destination at all.
|
||||
|
||||
ls --color now highlights hard linked files, too
|
||||
|
||||
stat -f recognizes the Lustre file system type
|
||||
|
||||
** Bug fixes
|
||||
|
||||
chgrp, chmod, chown --silent (--quiet, -f) no longer print some diagnostics
|
||||
[bug introduced in coreutils-5.1]
|
||||
|
||||
cp uses much less memory in some situations
|
||||
|
||||
cp -a now correctly tries to preserve SELinux context (announced in 6.9.90),
|
||||
doesn't inform about failure, unlike with --preserve=all
|
||||
|
||||
du --files0-from=FILE no longer reads all of FILE into RAM before
|
||||
processing the first file name
|
||||
|
||||
seq 9223372036854775807 9223372036854775808 now prints only two numbers
|
||||
on systems with extended long double support and good library support.
|
||||
Even with this patch, on some systems, it still produces invalid output,
|
||||
from 3 to at least 1026 lines long. [bug introduced in coreutils-6.11]
|
||||
|
||||
seq -w now accounts for a decimal point added to the last number
|
||||
to correctly print all numbers to the same width.
|
||||
|
||||
wc --files0-from=FILE no longer reads all of FILE into RAM, before
|
||||
processing the first file name, unless the list of names is known
|
||||
to be small enough.
|
||||
|
||||
** Changes in behavior
|
||||
|
||||
cp and mv: the --reply={yes,no,query} option has been removed.
|
||||
Using it has elicited a warning for the last three years.
|
||||
|
||||
dd: user specified offsets that are too big are handled better.
|
||||
Previously, erroneous parameters to skip and seek could result
|
||||
in redundant reading of the file with no warnings or errors.
|
||||
|
||||
du: -H (initially equivalent to --si) is now equivalent to
|
||||
--dereference-args, and thus works as POSIX requires
|
||||
|
||||
shred: now does 3 overwrite passes by default rather than 25.
|
||||
|
||||
ls -l now marks SELinux-only files with the less obtrusive '.',
|
||||
rather than '+'. A file with any other combination of MAC and ACL
|
||||
is still marked with a '+'.
|
||||
|
||||
|
||||
* Noteworthy changes in release 7.0 (2008-10-05) [beta]
|
||||
|
||||
** New programs
|
||||
@@ -2304,8 +2373,7 @@ packages, see ./old/*/NEWS.
|
||||
|
||||
========================================================================
|
||||
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2001-2009 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
|
||||
23
README
23
README
@@ -92,11 +92,15 @@ compiler, due to the use of declarations after non-declaration statements
|
||||
in several files in src/. There is code in configure to find and, if
|
||||
possible, enable an appropriate compiler. However, if configure doesn't
|
||||
find a C99 compiler, it continues nonetheless, and your build will fail.
|
||||
If that happens, simply apply the included patch using the following
|
||||
If that happens, simply[*] apply the included patch using the following
|
||||
command, and then run make again:
|
||||
|
||||
cd src && patch < c99-to-c89.diff
|
||||
|
||||
[*] however, as of coreutils-7.1, the "c99-to-c89.diff" file is no longer
|
||||
maintained, so even if the patches still apply, the result will be an
|
||||
incomplete conversion. It's been 10 years. Get a decent compiler! ;-)
|
||||
|
||||
|
||||
***********************
|
||||
HPUX 11.x build failure
|
||||
@@ -161,17 +165,13 @@ Reporting bugs:
|
||||
IMPORTANT: if you take the time to report a test failure,
|
||||
please be sure to include the output of running `make check'
|
||||
in verbose mode for each failing test. For example,
|
||||
if the test that fails is tests/mv/hard-link-1, then you
|
||||
would run this command:
|
||||
if the test that fails is tests/misc/df, then you would
|
||||
run this command:
|
||||
|
||||
env VERBOSE=yes make check -C tests/mv TESTS=hard-link-1 >> log 2>&1
|
||||
(cd tests && make check TESTS=misc/df VERBOSE=yes) >> log 2>&1
|
||||
|
||||
For some tests, you can get even more detail by including
|
||||
DEBUG=yes in the environment:
|
||||
|
||||
env DEBUG=yes VERBOSE=yes make check -C tests/mv TESTS=hard-link-1 >> log 2>&1
|
||||
|
||||
and then include the contents of the file `log' in your bug report.
|
||||
For some tests, you can get even more detail by adding DEBUG=yes.
|
||||
Then include the contents of the file `log' in your bug report.
|
||||
|
||||
***************************************
|
||||
|
||||
@@ -231,8 +231,7 @@ the address on the last line of --help output.
|
||||
|
||||
========================================================================
|
||||
|
||||
Copyright (C) 1998, 2002, 2003, 2004, 2005, 2006 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 1998, 2002-2009 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
|
||||
These notes intend to help people working on the checked-out sources.
|
||||
These requirements do not apply when building from a distribution tarball.
|
||||
See also HACKING for more detailed coreutils contribution guidlines.
|
||||
|
||||
* Requirements
|
||||
|
||||
We've opted to keep only the highest-level sources in the GIT repository.
|
||||
This eases our maintenance burden, (fewer merges etc.), but imposes more
|
||||
requirements on anyone wishing to build from the just-checked-out sources.
|
||||
For example, you have to use the latest stable versions of the maintainer
|
||||
tools we depend upon, including:
|
||||
Specific tools and versions will be checked for and listed by the
|
||||
bootstrap script shown below, and will include:
|
||||
|
||||
- Automake <http://www.gnu.org/software/automake/>
|
||||
- Autoconf <http://www.gnu.org/software/autoconf/>
|
||||
@@ -22,41 +23,44 @@ tools we depend upon, including:
|
||||
- Rsync <http://samba.anu.edu.au/rsync/>
|
||||
- Tar <http://www.gnu.org/software/tar/>
|
||||
|
||||
Valgrind <http://valgrind.org/> is also highly recommended, if
|
||||
Valgrind supports your architecture.
|
||||
|
||||
Only building the initial full source tree will be a bit painful.
|
||||
Later, a plain `git pull && make' should be sufficient.
|
||||
|
||||
* LZMA
|
||||
- Valgrind
|
||||
|
||||
This package's build procedure uses LZMA to create a compressed
|
||||
Valgrind <http://valgrind.org/> is also highly recommended, if
|
||||
Valgrind supports your architecture. See also README-valgrind.
|
||||
|
||||
- XZ utils (successor to LZMA)
|
||||
|
||||
This package's build procedure uses XZ to create a compressed
|
||||
distribution tarball. Using this feature of Automake requires
|
||||
version 1.10.1 or newer, as well as the lzma program itself.
|
||||
Make sure you have the latest stable version of the LZMA Utils
|
||||
from <http://tukaani.org/lzma/>.
|
||||
version 1.10a or newer, as well as the xz program itself.
|
||||
Make sure you have the latest version of the XZ Utils from
|
||||
<http://tukaani.org/lzma/download>.
|
||||
|
||||
* First GIT checkout
|
||||
|
||||
You can get a copy of the source repository like this:
|
||||
|
||||
$ git clone git://git.sv.gnu.org/coreutils
|
||||
$ git clone git://git.sv.gnu.org/coreutils
|
||||
$ cd coreutils
|
||||
|
||||
The next step is to get other files needed to build, which are
|
||||
extracted from other source packages:
|
||||
The next step is to get and check other files needed to build,
|
||||
which are extracted from other source packages:
|
||||
|
||||
$ ./bootstrap
|
||||
$ ./bootstrap
|
||||
|
||||
And there you are! Just
|
||||
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check
|
||||
|
||||
At this point, there should be no difference between your local copy,
|
||||
and the GIT master copy:
|
||||
|
||||
$ git diff
|
||||
$ git diff
|
||||
|
||||
should output no difference.
|
||||
|
||||
@@ -64,7 +68,7 @@ Enjoy!
|
||||
|
||||
-----
|
||||
|
||||
Copyright (C) 2002-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -78,3 +82,7 @@ GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Local Variables:
|
||||
indent-tabs-mode: nil
|
||||
End:
|
||||
|
||||
31
README-prereq
Normal file
31
README-prereq
Normal file
@@ -0,0 +1,31 @@
|
||||
Detailed below are concrete examples for
|
||||
getting the prerequisites for particular systems.
|
||||
|
||||
- linux - fedora
|
||||
|
||||
This shows the steps for getting the required tools to build coreutils 7.0
|
||||
on a Fedora 8 system. We try to use official packages where possible.
|
||||
The 3 methods described for making these required packages available, should
|
||||
help clarify build requirements on any linux system at least.
|
||||
|
||||
1. Make sure offical distro git package is installed
|
||||
# yum install git
|
||||
|
||||
2. The distro autoconf is too old, but there is a newer one available
|
||||
so we rebuild that and make it available to the full system:
|
||||
# yum install emacs #autoconf build requires emacs (20MB)
|
||||
# rpmbuild --rebuild http://download.fedora.redhat.com/pub/fedora/linux/development/source/SRPMS/autoconf-2.63-1.fc10.src.rpm
|
||||
# rpm -Uvh /usr/src/redhat/RPMS/noarch/autoconf-2.63-1.fc8.noarch.rpm
|
||||
Apply the same method to install the lzma package.
|
||||
[FIXME: mention xz when it's packaged]
|
||||
|
||||
3. The latest released automake (1.10.1) was not new enough, so we download
|
||||
and build automake-1.10a from its repository and make it available
|
||||
just to coreutils:
|
||||
# yum install help2man #required to build automake fully
|
||||
$ git clone git://git.sv.gnu.org/automake.git
|
||||
$ cd automake && ./configure --prefix=$HOME/coreutils/deps
|
||||
$ make install
|
||||
|
||||
Now we can build coreutils as described in README-hacking
|
||||
as long as $PATH starts with $HOME/coreutils/deps
|
||||
11
THANKS
11
THANKS
@@ -10,6 +10,7 @@ the bug-report mailing list (as seen on last line of e.g., cp --help).
|
||||
A Costa agcosta@gis.net
|
||||
Aaron Hawley ashawley@uvm.edu
|
||||
Achim Blumensath blume@corona.oche.de
|
||||
Adam Jimerson vendion@charter.net
|
||||
Adam Klein aklein@debian.org
|
||||
Adrian Bunk bunk@stusta.de
|
||||
AIDA Shinra shinra@j10n.org
|
||||
@@ -21,6 +22,7 @@ Albert Hopkins ahopkins@dynacare.com
|
||||
Alberto Accomazzi alberto@cfa0.harvard.edu
|
||||
aldomel aldomel@ix.netcom.com
|
||||
Alen Muzinic zveki@fly.cc.fer.hr
|
||||
Alexander V. Lukyanov lav@netis.ru
|
||||
Allen Hewes allen@decisiv.net
|
||||
Axel Dörfler axeld@pinc-software.de
|
||||
Alexandre Duret-Lutz duret_g@epita.fr
|
||||
@@ -58,6 +60,7 @@ Augey Mikus mikus@dqc.org
|
||||
Aurelien Jarno aurel32@debian.org
|
||||
Austin Donnelly Austin.Donnelly@cl.cam.ac.uk
|
||||
Axel Kittenberger Anshil@gmx.net
|
||||
Barry Kelly http://barrkel.blogspot.com/
|
||||
Bauke Jan Douma bjdouma@xs4all.nl
|
||||
Ben Elliston bje@air.net.au
|
||||
Ben Harris bjh21@netbsd.org
|
||||
@@ -79,6 +82,7 @@ Bob Proulx rwp@fc.hp.com
|
||||
Branden Robinson branden@necrotic.deadbeast.net
|
||||
Brendan O'Dea bod@compusol.com.au
|
||||
Brian Kimball bfk@footbag.org
|
||||
Brian M. Carlson sandals@crustytoothpaste.ath.cx
|
||||
Brian Silverman bsilverman@conceptxdesign.com
|
||||
Brian Youmans 3diff@gnu.org
|
||||
Bruce Korb bkorb@veritas.com
|
||||
@@ -114,7 +118,7 @@ Cyril Bouthors cyril@bouthors.org
|
||||
Dale Scheetz dwarf@polaris.net
|
||||
Dameon G. Rogers dgr03@uark.edu
|
||||
Dan Hagerty hag@gnu.ai.it.edu
|
||||
Dan Jacobson http://www.geocities.com/jidani
|
||||
Dan Jacobson jidanni@jidanni.org
|
||||
Dan Pascu dan@services.iiruc.ro
|
||||
Daniel Bergstrom noa@melody.se
|
||||
Daniel Dunbar ddunbar@stanford.edu
|
||||
@@ -201,6 +205,7 @@ Guochun Shi gshi@ncsa.uiuc.edu
|
||||
GOTO Masanori gotom@debian.or.jp
|
||||
Greg Louis glouis@dynamicro.on.ca
|
||||
Greg McGary gkm@gnu.org
|
||||
Greg Metcalfe metcalfegreg@qwest.net
|
||||
Greg Schafer gschafer@zip.com.au
|
||||
Greg Troxel gdt@bbn.com
|
||||
Greg Wooledge gawooledge@sherwin.com
|
||||
@@ -240,6 +245,7 @@ James Tanis jtt@soscorp.com
|
||||
James Youngman james+usenet@free-lunch.demon.co.uk
|
||||
Jamie Lokier jamie@imbolc.ucc.ie
|
||||
Jamie McClelland jm@mayfirst.org
|
||||
Jan Engelhardt jengelh@medozas.de
|
||||
Jan Fedak J.Fedak@sh.cvut.cz
|
||||
Jan Moringen jan.moringen@uni-bielefeld.de
|
||||
Jan Nieuwenhuizen janneke@gnu.org
|
||||
@@ -440,6 +446,7 @@ Peter Moulder reiter@netspace.net.au
|
||||
Peter O'Gorman bug-coreutils@mlists.thewrittenword.com
|
||||
Peter Samuelson psamuels@sampo.creighton.edu
|
||||
Peter Seebach seebs@taniemarie.solon.com
|
||||
Petr Uzel petr.uzel@suse.cz
|
||||
Petter Reinholdtsen pere@hungry.com
|
||||
Phelippe Neveu pneveu@pcigeomatics.com
|
||||
Phil Richards phil.richards@vf.vodafone.co.uk
|
||||
@@ -548,7 +555,9 @@ Uwe H. Steinfeld usteinfeld@gmx.net
|
||||
Vesselin Atanasov vesselin@bgnet.bg
|
||||
Vin Shelton acs@alumni.princeton.edu
|
||||
Vineet Chadha chadha@acis.ufl.edu
|
||||
Vitali Lovich vlovich@gmail.com
|
||||
Vitaly A. Ostanin vyt@altlinux.org
|
||||
Vito Caputo vcaputo@pengaru.com
|
||||
Vlada Macek tuttle@bbs.fsik.cvut.cz
|
||||
Volker Borchert bt@teknon.de
|
||||
Volker Paul vpaul@dohle.com
|
||||
|
||||
12
TODO
12
TODO
@@ -12,8 +12,6 @@ Modify chmod so that it does not change an inode's st_ctime
|
||||
Discussed more recently on <http://bugs.debian.org/497514>.
|
||||
|
||||
document the following in coreutils.texi:
|
||||
runcon
|
||||
chcon
|
||||
mktemp
|
||||
[
|
||||
pinky
|
||||
@@ -38,6 +36,11 @@ printf:
|
||||
platforms where the native *printf(3) is deficient.
|
||||
Suggestion from Eric Blake.
|
||||
|
||||
pwd:
|
||||
Implement the options -P and -L in a POSIX-compatible way.
|
||||
Note the instructions in the initial paragraph of this file
|
||||
before starting.
|
||||
|
||||
renice: POSIX utility, needs implementing.
|
||||
suggestion from Karl Berry (among others).
|
||||
Bob Proulx is working on this.
|
||||
@@ -104,6 +107,9 @@ sort: Investigate better sorting algorithms; see Knuth vol. 3.
|
||||
5.3.1, who credits Lester Ford, Jr. and Selmer Johnson, American
|
||||
Mathematical Monthly 66 (1959), 387-389.
|
||||
|
||||
shred: Update shred as described here to conform to DoD 5220 rules:
|
||||
http://lists.gnu.org/archive/html/bug-coreutils/2007-05/msg00075.html
|
||||
|
||||
Remove suspicious uses of alloca (ones that may allocate more than
|
||||
about 4k)
|
||||
|
||||
@@ -170,7 +176,7 @@ pr's use of nstrftime can make it malloc a very large (up to SIZE_MAX) buffer
|
||||
|
||||
-----
|
||||
|
||||
Copyright (C) 2002-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
134
bootstrap
134
bootstrap
@@ -52,6 +52,9 @@ Options:
|
||||
If the file $0.conf exists in the same directory as this script, its
|
||||
contents are read as shell variables to configure the bootstrap.
|
||||
|
||||
For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
|
||||
are honored.
|
||||
|
||||
Running without arguments will suffice in most cases.
|
||||
"
|
||||
}
|
||||
@@ -195,7 +198,7 @@ insert_sorted_if_absent() {
|
||||
file=$1
|
||||
str=$2
|
||||
test -f $file || touch $file
|
||||
echo "$str" | sort -u - $file | cmp -s - $file \
|
||||
echo "$str" | sort -u - $file | cmp - $file > /dev/null \
|
||||
|| echo "$str" | sort -u - $file -o $file \
|
||||
|| exit 1
|
||||
}
|
||||
@@ -222,6 +225,100 @@ if test ! -d $build_aux; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Note this deviates from the version comparison in automake
|
||||
# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
|
||||
# but this should suffice as we won't be specifying old
|
||||
# version formats or redundant trailing .0 in bootstrap.conf.
|
||||
# If we did want full compatibility then we should probably
|
||||
# use m4_version_compare from autoconf.
|
||||
sort_ver() { #sort -V is not generally available
|
||||
ver1="$1"
|
||||
ver2="$2"
|
||||
|
||||
#split on '.' and compare each component
|
||||
i=1
|
||||
while : ; do
|
||||
p1=$(echo "$ver1" | cut -d. -f$i)
|
||||
p2=$(echo "$ver2" | cut -d. -f$i)
|
||||
if [ ! "$p1" ]; then
|
||||
echo "$1 $2"
|
||||
break
|
||||
elif [ ! "$p2" ]; then
|
||||
echo "$2 $1"
|
||||
break
|
||||
elif [ ! "$p1" = "$p2" ]; then
|
||||
if [ "$p1" -gt "$p2" ] 2>/dev/null; then #numeric comparision
|
||||
echo "$2 $1"
|
||||
elif [ "$p2" -gt "$p1" ] 2>/dev/null; then #numeric comparision
|
||||
echo "$1 $2"
|
||||
else #numeric, then lexographic comparison
|
||||
lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
|
||||
if [ "$lp" = "$p2" ]; then
|
||||
echo "$1 $2"
|
||||
else
|
||||
echo "$2 $1"
|
||||
fi
|
||||
fi
|
||||
break
|
||||
fi
|
||||
i=$(($i+1))
|
||||
done
|
||||
}
|
||||
|
||||
get_version() {
|
||||
app=$1
|
||||
|
||||
$app --version >/dev/null 2>&1 || return 1
|
||||
|
||||
$app --version 2>&1 |
|
||||
sed -n 's/[^0-9.]*\([0-9]\{1,\}\.[.a-z0-9-]*\).*/\1/p
|
||||
t done
|
||||
d
|
||||
:done
|
||||
q'
|
||||
}
|
||||
|
||||
check_versions() {
|
||||
ret=0
|
||||
|
||||
while read app req_ver; do
|
||||
# Honor $APP variables ($TAR, $AUTOCONF, etc.)
|
||||
appvar=`echo $app | tr '[a-z]' '[A-Z]'`
|
||||
test "$appvar" = TAR && appvar=AMTAR
|
||||
eval "app=\${$appvar-$app}"
|
||||
inst_ver=$(get_version $app)
|
||||
if [ ! "$inst_ver" ]; then
|
||||
echo "Error: '$app' not found" >&2
|
||||
ret=1
|
||||
elif [ ! "$req_ver" = "-" ]; then
|
||||
latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
|
||||
if [ ! "$latest_ver" = "$inst_ver" ]; then
|
||||
echo "Error: '$app' version == $inst_ver is too old" >&2
|
||||
echo " '$app' version >= $req_ver is required" >&2
|
||||
ret=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
print_versions() {
|
||||
echo "Program Min_version"
|
||||
echo "----------------------"
|
||||
printf "$buildreq"
|
||||
echo "----------------------"
|
||||
#can't depend on column -t
|
||||
}
|
||||
|
||||
if ! printf "$buildreq" | check_versions; then
|
||||
test -f README-prereq &&
|
||||
echo "Please see README-prereq for notes on obtaining these prerequisite programs:" >&2
|
||||
echo
|
||||
print_versions
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$0: Bootstrapping from checked-out $package sources..."
|
||||
|
||||
# See if we can use gnulib's git-merge-changelog merge driver.
|
||||
@@ -262,7 +359,8 @@ case ${GNULIB_SRCDIR--} in
|
||||
|
||||
trap cleanup_gnulib 1 2 13 15
|
||||
|
||||
git clone --depth 2 git://git.sv.gnu.org/gnulib ||
|
||||
git clone --help|grep depth > /dev/null && depth='--depth 2' || depth=
|
||||
git clone $depth git://git.sv.gnu.org/gnulib ||
|
||||
cleanup_gnulib
|
||||
|
||||
trap - 1 2 13 15
|
||||
@@ -322,9 +420,9 @@ update_po_files() {
|
||||
cksum_file="$ref_po_dir/$po.s1"
|
||||
if ! test -f "$cksum_file" ||
|
||||
! test -f "$po_dir/$po.po" ||
|
||||
! sha1sum -c --status "$cksum_file" < "$new_po" > /dev/null; then
|
||||
! ${SHA1SUM-sha1sum} -c --status "$cksum_file" < "$new_po" > /dev/null; then
|
||||
echo "updated $po_dir/$po.po..."
|
||||
cp "$new_po" "$po_dir/$po.po" && sha1sum < "$new_po" > "$cksum_file"
|
||||
cp "$new_po" "$po_dir/$po.po" && ${SHA1SUM-sha1sum} < "$new_po" > "$cksum_file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -487,7 +585,7 @@ slurp() {
|
||||
if test $file = Makefile.am; then
|
||||
copied=$copied${sep}$gnulib_mk; sep=$nl
|
||||
remove_intl='/^[^#].*\/intl/s/^/#/;'"s!$bt_regex/!!g"
|
||||
sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/$gnulib_mk || {
|
||||
sed "$remove_intl" $1/$dir/$file | cmp - $dir/$gnulib_mk > /dev/null || {
|
||||
echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..." &&
|
||||
rm -f $dir/$gnulib_mk &&
|
||||
sed "$remove_intl" $1/$dir/$file >$dir/$gnulib_mk
|
||||
@@ -569,9 +667,9 @@ grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
|
||||
with_gettext=no
|
||||
|
||||
if test $with_gettext = yes; then
|
||||
echo "$0: (cd $bt2; autopoint) ..."
|
||||
echo "$0: (cd $bt2; ${AUTOPOINT-autopoint}) ..."
|
||||
cp configure.ac $bt2 &&
|
||||
(cd $bt2 && autopoint && rm configure.ac) &&
|
||||
(cd $bt2 && ${AUTOPOINT-autopoint} && rm configure.ac) &&
|
||||
slurp $bt2 $bt || exit
|
||||
fi
|
||||
rm -fr $bt $bt2 || exit
|
||||
@@ -592,15 +690,23 @@ find "$m4_base" "$source_base" \
|
||||
|
||||
for command in \
|
||||
libtool \
|
||||
'aclocal --force -I m4' \
|
||||
'autoconf --force' \
|
||||
'autoheader --force' \
|
||||
'automake --add-missing --copy --force-missing';
|
||||
"${ACLOCAL-aclocal} --force -I m4" \
|
||||
"${AUTOCONF-autoconf} --force" \
|
||||
"${AUTOHEADER-autoheader} --force" \
|
||||
"${AUTOMAKE-automake} --add-missing --copy --force-missing"
|
||||
do
|
||||
if test "$command" = libtool; then
|
||||
grep '^[ ]*AM_PROG_LIBTOOL\>' configure.ac >/dev/null ||
|
||||
continue
|
||||
command='libtoolize -c -f'
|
||||
use_libtool=0
|
||||
# We'd like to use grep -E, to see if any of LT_INIT,
|
||||
# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
|
||||
# but that's not portable enough (e.g., for Solaris).
|
||||
grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
|
||||
&& use_libtool=1
|
||||
grep '^[ ]*LT_INIT' configure.ac >/dev/null \
|
||||
&& use_libtool=1
|
||||
test $use_libtool = 0 \
|
||||
&& continue
|
||||
command="${LIBTOOLIZE-libtoolize} -c -f"
|
||||
fi
|
||||
echo "$0: $command ..."
|
||||
$command || exit
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Bootstrap configuration.
|
||||
|
||||
# Copyright (C) 2006-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2006-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -16,11 +16,11 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# We don't need these modules, even though gnulib-tool mistakenly
|
||||
# includes them because of gettext and fchdir dependencies.
|
||||
# We don't need these modules.
|
||||
avoided_gnulib_modules='
|
||||
--avoid=lock
|
||||
--avoid=canonicalize-lgpl
|
||||
--avoid=dummy
|
||||
--avoid=lock
|
||||
'
|
||||
|
||||
# These modules are obsolete and can probably be removed soon,
|
||||
@@ -34,7 +34,9 @@ obsolete_gnulib_modules='
|
||||
gnulib_modules="
|
||||
$avoided_gnulib_modules
|
||||
$obsolete_gnulib_modules
|
||||
acl alloca announce-gen argmatch assert
|
||||
acl alloca announce-gen argmatch
|
||||
argv-iter
|
||||
assert
|
||||
autobuild
|
||||
backupfile base64
|
||||
c-strcase c-strtod
|
||||
@@ -61,9 +63,13 @@ gnulib_modules="
|
||||
gitlog-to-changelog
|
||||
gnu-make gnumakefile gnupload
|
||||
group-member hard-locale hash hash-pjw host-os human idcache
|
||||
ignore-value
|
||||
inttostr inttypes isapipe
|
||||
lchmod lchown lib-ignore linebuffer link-follow
|
||||
long-options lstat malloc mbswidth memcasecmp mempcpy
|
||||
long-options lstat malloc
|
||||
mbrtowc
|
||||
mbswidth
|
||||
memcasecmp mempcpy
|
||||
memrchr mgetgroups
|
||||
mkancesdirs mkdir mkdir-p mkstemp mktime modechange
|
||||
mountlist mpsort obstack pathmax perl physmem
|
||||
@@ -84,9 +90,10 @@ gnulib_modules="
|
||||
safe-read same
|
||||
save-cwd savedir savewd
|
||||
selinux-at
|
||||
settime sig2str ssize_t stat-macros
|
||||
settime sig2str sigaction ssize_t stat-macros
|
||||
stat-time stdbool stdlib-safer stpcpy
|
||||
stpncpy
|
||||
strdup
|
||||
strftime
|
||||
strpbrk strtoimax strtoumax strverscmp sys_stat timespec tzset
|
||||
unicodeio unistd-safer unlink-busy unlinkdir unlocked-io
|
||||
@@ -95,9 +102,12 @@ gnulib_modules="
|
||||
userspec utimecmp utimens
|
||||
vasprintf-posix
|
||||
vc-list-files
|
||||
verify version-etc-fsf
|
||||
verify version-etc-fsf verror
|
||||
warnings
|
||||
wcwidth winsz-ioctl winsz-termios write-any-file
|
||||
xalloc xgetcwd xgethostname
|
||||
xalloc
|
||||
xfreopen
|
||||
xgetcwd xgethostname
|
||||
xmemcoll xnanosleep
|
||||
xprintf
|
||||
xprintf-posix
|
||||
@@ -160,5 +170,21 @@ fi
|
||||
|
||||
gnulib_tool_option_extras="--tests-base=$bt/gnulib-tests --with-tests"
|
||||
|
||||
# Build prerequisites
|
||||
buildreq="\
|
||||
autoconf 2.61
|
||||
automake 1.10a
|
||||
autopoint -
|
||||
bison -
|
||||
gettext -
|
||||
git 1.4.4
|
||||
gperf -
|
||||
gzip -
|
||||
makeinfo -
|
||||
perl 5.5
|
||||
rsync -
|
||||
tar -
|
||||
"
|
||||
|
||||
# Automake requires that ChangeLog exist.
|
||||
touch ChangeLog
|
||||
|
||||
153
cfg.mk
153
cfg.mk
@@ -1,5 +1,5 @@
|
||||
# Customize maint.mk -*- makefile -*-
|
||||
# Copyright (C) 2003-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2003-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -42,4 +42,153 @@ gnulib_dir = /gnulib
|
||||
# Now that we have better (check.mk) tests, make this the default.
|
||||
export VERBOSE = yes
|
||||
|
||||
old_NEWS_hash = 95fc7a26fa253d57cabe4b058167a4f9 -
|
||||
old_NEWS_hash = 791cf10529d00853f6363ca67f360747 -
|
||||
|
||||
# Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
|
||||
dd = $(srcdir)/src/dd.c
|
||||
sc_dd_O_FLAGS:
|
||||
@rm -f $@.1 $@.2
|
||||
@{ echo O_FULLBLOCK; perl -nle '/MAX \((O_\w*),/ and print $$1' \
|
||||
$(dd); } | sort > $@.1
|
||||
@{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \
|
||||
$(dd); } | sort > $@.2
|
||||
@diff -u $@.1 $@.2 || diff=1 || diff=; \
|
||||
rm -f $@.1 $@.2; \
|
||||
test "$$diff" \
|
||||
&& { echo '$(ME): $(dd) has inconsistent O_ flag lists'>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
# Ensure that dd's definition of LONGEST_SYMBOL stays in sync
|
||||
# with the strings from the two affected variables.
|
||||
dd_c = $(srcdir)/src/dd.c
|
||||
sc_dd_max_sym_length:
|
||||
ifneq ($(wildcard $(dd_c)),)
|
||||
@len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
|
||||
sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
|
||||
|sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
|
||||
| wc --max-line-length); \
|
||||
max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
|
||||
|tr -d '"' | wc --max-line-length); \
|
||||
if test "$$len" = "$$max"; then :; else \
|
||||
echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
endif
|
||||
|
||||
# Many m4 macros names once began with `jm_'.
|
||||
# On 2004-04-13, they were all changed to start with gl_ instead.
|
||||
# Make sure that none are inadvertently reintroduced.
|
||||
sc_prohibit_jm_in_m4:
|
||||
@grep -nE 'jm_[A-Z]' \
|
||||
$$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
|
||||
{ echo '$(ME): do not use jm_ in m4 macro names' \
|
||||
1>&2; exit 1; } || :
|
||||
|
||||
# Ensure that each root-requiring test is run via the "check-root" rule.
|
||||
sc_root_tests:
|
||||
@if test -d tests \
|
||||
&& grep check-root tests/Makefile.am>/dev/null 2>&1; then \
|
||||
t1=sc-root.expected; t2=sc-root.actual; \
|
||||
grep -nl '^require_root_$$' \
|
||||
$$($(VC_LIST) tests) |sed s,tests/,, |sort > $$t1; \
|
||||
sed -n '/^root_tests =[ ]*\\$$/,/[^\]$$/p' \
|
||||
$(srcdir)/tests/Makefile.am \
|
||||
| sed 's/^ *//;/^root_tests =/d' \
|
||||
| tr -s '\012\\' ' ' | fmt -1 | sort > $$t2; \
|
||||
diff -u $$t1 $$t2 || diff=1 || diff=; \
|
||||
rm -f $$t1 $$t2; \
|
||||
test "$$diff" \
|
||||
&& { echo 'tests/Makefile.am: missing check-root action'>&2; \
|
||||
exit 1; } || :; \
|
||||
fi
|
||||
|
||||
headers_with_interesting_macro_defs = \
|
||||
exit.h \
|
||||
fcntl_.h \
|
||||
fnmatch_.h \
|
||||
intprops.h \
|
||||
inttypes_.h \
|
||||
lchown.h \
|
||||
openat.h \
|
||||
stat-macros.h \
|
||||
stdint_.h
|
||||
|
||||
# Create a list of regular expressions matching the names
|
||||
# of macros that are guaranteed by parts of gnulib to be defined.
|
||||
.re-defmac:
|
||||
@(cd $(srcdir)/lib; \
|
||||
for f in $(headers_with_interesting_macro_defs); do \
|
||||
test -f $$f && \
|
||||
sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f; \
|
||||
done; \
|
||||
) | sort -u \
|
||||
| grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX' \
|
||||
| sed 's/^/^# *define /' \
|
||||
> $@-t
|
||||
@mv $@-t $@
|
||||
|
||||
# Don't define macros that we already get from gnulib header files.
|
||||
sc_always_defined_macros: .re-defmac
|
||||
@if test -f $(srcdir)/src/system.h; then \
|
||||
trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \
|
||||
grep -f .re-defmac $$($(VC_LIST)) \
|
||||
&& { echo '$(ME): define the above via some gnulib .h file' \
|
||||
1>&2; exit 1; } || :; \
|
||||
fi
|
||||
|
||||
# Create a list of regular expressions matching the names
|
||||
# of files included from system.h. Exclude a couple.
|
||||
.re-list:
|
||||
@sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
|
||||
| grep -Ev 'sys/(param|file)\.h' \
|
||||
| sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
|
||||
> $@-t
|
||||
@mv $@-t $@
|
||||
|
||||
# Files in src/ should not include directly any of
|
||||
# the headers already included via system.h.
|
||||
sc_system_h_headers: .re-list
|
||||
@if test -f $(srcdir)/src/system.h; then \
|
||||
trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
|
||||
grep -nE -f .re-list \
|
||||
$$($(VC_LIST) src | \
|
||||
grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
|
||||
&& { echo '$(ME): the above are already included via system.h'\
|
||||
1>&2; exit 1; } || :; \
|
||||
fi
|
||||
|
||||
sc_sun_os_names:
|
||||
@grep -nEi \
|
||||
'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
sc_tight_scope:
|
||||
@$(MAKE) -C src $@
|
||||
|
||||
# Perl-based tests used to exec perl from a #!/bin/sh script.
|
||||
# Now they all start with #!/usr/bin/perl and the portability
|
||||
# infrastructure is in tests/Makefile.am. Make sure no old-style
|
||||
# script sneaks back in.
|
||||
sc_no_exec_perl_coreutils:
|
||||
@if test -f $(srcdir)/tests/Coreutils.pm; then \
|
||||
grep '^exec *\$$PERL.*MCoreutils' $$($(VC_LIST) tests) && \
|
||||
{ echo 1>&2 '$(ME): found anachronistic Perl-based tests'; \
|
||||
exit 1; } || :; \
|
||||
fi
|
||||
|
||||
# Ensure that date's --help output stays in sync with the info
|
||||
# documentation for GNU strftime. The only exception is %N,
|
||||
# which date accepts but GNU strftime does not.
|
||||
extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
|
||||
sc_strftime_check:
|
||||
@if test -f $(srcdir)/src/date.c; then \
|
||||
grep '^ %. ' $(srcdir)/src/date.c | sort \
|
||||
| $(extract_char) > $@-src; \
|
||||
{ echo N; \
|
||||
info libc date calendar format | grep '^ `%.'\' \
|
||||
| $(extract_char); } | sort > $@-info; \
|
||||
diff -u $@-src $@-info || exit 1; \
|
||||
rm -f $@-src $@-info; \
|
||||
fi
|
||||
|
||||
109
configure.ac
109
configure.ac
@@ -18,7 +18,7 @@
|
||||
|
||||
dnl Written by Jim Meyering.
|
||||
|
||||
AC_PREREQ(2.61)
|
||||
AC_PREREQ([2.61])
|
||||
|
||||
# Make inter-release version strings look like, e.g., v6.9-219-g58ddd, which
|
||||
# indicates that it is built from the 219th delta (in _some_ repository)
|
||||
@@ -27,12 +27,12 @@ AC_INIT([GNU coreutils],
|
||||
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
|
||||
[bug-coreutils@gnu.org])
|
||||
|
||||
AC_CONFIG_SRCDIR(src/ls.c)
|
||||
AC_CONFIG_SRCDIR([src/ls.c])
|
||||
|
||||
AC_CONFIG_AUX_DIR(build-aux)
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
|
||||
|
||||
AM_INIT_AUTOMAKE([1.10a dist-lzma])
|
||||
AM_INIT_AUTOMAKE([1.10a dist-xz])
|
||||
|
||||
AC_PROG_CC_STDC
|
||||
AM_PROG_CC_C_O
|
||||
@@ -44,20 +44,53 @@ gl_EARLY
|
||||
gl_INIT
|
||||
coreutils_MACROS
|
||||
|
||||
AC_ARG_ENABLE([gcc-warnings],
|
||||
[AS_HELP_STRING([--enable-gcc-warnings],
|
||||
[turn on lots of GCC warnings (not recommended)])],
|
||||
[case $enableval in
|
||||
yes|no) ;;
|
||||
*) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
|
||||
esac
|
||||
gl_gcc_warnings=$enableval],
|
||||
[gl_gcc_warnings=no]
|
||||
)
|
||||
|
||||
if test "$gl_gcc_warnings" = yes; then
|
||||
gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
|
||||
AC_SUBST([WERROR_CFLAGS])
|
||||
gl_WARN_ADD([-Wall])
|
||||
gl_WARN_ADD([-Wextra])
|
||||
gl_WARN_ADD([-Wshadow])
|
||||
gl_WARN_ADD([-Wno-sign-compare])
|
||||
gl_WARN_ADD([-Wformat])
|
||||
gl_WARN_ADD([-Wformat-security])
|
||||
gl_WARN_ADD([-Wcast-align])
|
||||
gl_WARN_ADD([-Wpointer-arith])
|
||||
gl_WARN_ADD([-Wwrite-strings])
|
||||
gl_WARN_ADD([-Wbad-function-cast])
|
||||
gl_WARN_ADD([-Wmissing-declarations])
|
||||
gl_WARN_ADD([-Wmissing-prototypes])
|
||||
gl_WARN_ADD([-Wstrict-prototypes])
|
||||
AC_SUBST([WARN_CFLAGS])
|
||||
AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
|
||||
AC_DEFINE([_FORTIFY_SOURCE], [2],
|
||||
[enable compile-time and run-time bounds-checking, and some warnings])
|
||||
fi
|
||||
|
||||
AC_FUNC_FORK
|
||||
|
||||
optional_bin_progs=
|
||||
AC_CHECK_FUNCS(uname,
|
||||
AC_CHECK_FUNCS([uname],
|
||||
gl_ADD_PROG([optional_bin_progs], [uname]))
|
||||
AC_CHECK_FUNCS(chroot,
|
||||
AC_CHECK_FUNCS([chroot],
|
||||
gl_ADD_PROG([optional_bin_progs], [chroot]))
|
||||
AC_CHECK_FUNCS(gethostid,
|
||||
AC_CHECK_FUNCS([gethostid],
|
||||
gl_ADD_PROG([optional_bin_progs], [hostid]))
|
||||
|
||||
gl_WINSIZE_IN_PTEM
|
||||
|
||||
AC_MSG_CHECKING(whether localtime caches TZ)
|
||||
AC_CACHE_VAL(utils_cv_localtime_cache,
|
||||
AC_MSG_CHECKING([whether localtime caches TZ])
|
||||
AC_CACHE_VAL([utils_cv_localtime_cache],
|
||||
[if test x$ac_cv_func_tzset = xyes; then
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <time.h>
|
||||
#if STDC_HEADERS
|
||||
@@ -98,22 +131,22 @@ else
|
||||
# since we can't invalidate the cache if we don't have tzset.
|
||||
utils_cv_localtime_cache=no
|
||||
fi])dnl
|
||||
AC_MSG_RESULT($utils_cv_localtime_cache)
|
||||
AC_MSG_RESULT([$utils_cv_localtime_cache])
|
||||
if test $utils_cv_localtime_cache = yes; then
|
||||
AC_DEFINE(LOCALTIME_CACHE, 1, [FIXME])
|
||||
AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
|
||||
fi
|
||||
|
||||
# SCO-ODT-3.0 is reported to need -los to link programs using initgroups
|
||||
AC_CHECK_FUNCS(initgroups)
|
||||
AC_CHECK_FUNCS([initgroups])
|
||||
if test $ac_cv_func_initgroups = no; then
|
||||
AC_CHECK_LIB(os, initgroups)
|
||||
AC_CHECK_LIB([os], [initgroups])
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNCS(syslog)
|
||||
AC_CHECK_FUNCS([syslog])
|
||||
if test $ac_cv_func_syslog = no; then
|
||||
# syslog is not in the default libraries. See if it's in some other.
|
||||
for lib in bsd socket inet; do
|
||||
AC_CHECK_LIB($lib, syslog, [AC_DEFINE(HAVE_SYSLOG, 1, [FIXME])
|
||||
AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG], [1], [FIXME])
|
||||
LIBS="$LIBS -l$lib"; break])
|
||||
done
|
||||
fi
|
||||
@@ -147,29 +180,29 @@ AC_DEFUN([coreutils_DUMMY_1],
|
||||
])
|
||||
coreutils_DUMMY_1
|
||||
|
||||
AC_MSG_CHECKING(ut_host in struct utmp)
|
||||
AC_CACHE_VAL(su_cv_func_ut_host_in_utmp,
|
||||
AC_MSG_CHECKING([ut_host in struct utmp])
|
||||
AC_CACHE_VAL([su_cv_func_ut_host_in_utmp],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
|
||||
#include <utmp.h>]], [[struct utmp ut; return !sizeof ut.ut_host;]])],
|
||||
[su_cv_func_ut_host_in_utmp=yes],
|
||||
[su_cv_func_ut_host_in_utmp=no])])
|
||||
AC_MSG_RESULT($su_cv_func_ut_host_in_utmp)
|
||||
AC_MSG_RESULT([$su_cv_func_ut_host_in_utmp])
|
||||
if test $su_cv_func_ut_host_in_utmp = yes; then
|
||||
have_ut_host=1
|
||||
AC_DEFINE(HAVE_UT_HOST, 1, [FIXME])
|
||||
AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
|
||||
fi
|
||||
|
||||
if test -z "$have_ut_host"; then
|
||||
AC_MSG_CHECKING(ut_host in struct utmpx)
|
||||
AC_CACHE_VAL(su_cv_func_ut_host_in_utmpx,
|
||||
AC_MSG_CHECKING([ut_host in struct utmpx])
|
||||
AC_CACHE_VAL([su_cv_func_ut_host_in_utmpx],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
|
||||
#include <utmpx.h>]], [[struct utmpx ut; return !sizeof ut.ut_host;]])],
|
||||
[su_cv_func_ut_host_in_utmpx=yes],
|
||||
[su_cv_func_ut_host_in_utmpx=no])])
|
||||
AC_MSG_RESULT($su_cv_func_ut_host_in_utmpx)
|
||||
AC_MSG_RESULT([$su_cv_func_ut_host_in_utmpx])
|
||||
if test $su_cv_func_ut_host_in_utmpx = yes; then
|
||||
AC_DEFINE(HAVE_UTMPX_H, 1, [FIXME])
|
||||
AC_DEFINE(HAVE_UT_HOST, 1, [FIXME])
|
||||
AC_DEFINE([HAVE_UTMPX_H], [1], [FIXME])
|
||||
AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -181,24 +214,24 @@ gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
|
||||
if test $ac_cv_sys_posix_termios = yes; then
|
||||
gl_ADD_PROG([optional_bin_progs], [stty])
|
||||
|
||||
AC_MSG_CHECKING(whether termios.h needs _XOPEN_SOURCE)
|
||||
AC_CACHE_VAL(su_cv_sys_termios_needs_xopen_source,
|
||||
[AC_EGREP_CPP(yes, [#include <termios.h>
|
||||
AC_MSG_CHECKING([whether termios.h needs _XOPEN_SOURCE])
|
||||
AC_CACHE_VAL([su_cv_sys_termios_needs_xopen_source],
|
||||
[AC_EGREP_CPP([yes], [#include <termios.h>
|
||||
#ifdef IUCLC
|
||||
yes
|
||||
#endif], su_cv_sys_termios_needs_xopen_source=no,
|
||||
AC_EGREP_CPP(yes, [#define _XOPEN_SOURCE
|
||||
AC_EGREP_CPP([yes], [#define _XOPEN_SOURCE
|
||||
#include <termios.h>
|
||||
#ifdef IUCLC
|
||||
yes
|
||||
#endif], su_cv_sys_termios_needs_xopen_source=yes,
|
||||
su_cv_sys_termios_needs_xopen_source=no))])
|
||||
AC_MSG_RESULT($su_cv_sys_termios_needs_xopen_source)
|
||||
AC_MSG_RESULT([$su_cv_sys_termios_needs_xopen_source])
|
||||
test $su_cv_sys_termios_needs_xopen_source = yes &&
|
||||
AC_DEFINE(TERMIOS_NEEDS_XOPEN_SOURCE, 1, [FIXME])
|
||||
AC_DEFINE([TERMIOS_NEEDS_XOPEN_SOURCE], [1], [FIXME])
|
||||
|
||||
AC_MSG_CHECKING(c_line in struct termios)
|
||||
AC_CACHE_VAL(su_cv_sys_c_line_in_termios,
|
||||
AC_MSG_CHECKING([c_line in struct termios])
|
||||
AC_CACHE_VAL([su_cv_sys_c_line_in_termios],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#if TERMIOS_NEEDS_XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE
|
||||
#endif
|
||||
@@ -206,9 +239,9 @@ yes
|
||||
#include <termios.h>]], [[struct termios t; return !sizeof t.c_line;]])],
|
||||
[su_cv_sys_c_line_in_termios=yes],
|
||||
[su_cv_sys_c_line_in_termios=no])])
|
||||
AC_MSG_RESULT($su_cv_sys_c_line_in_termios)
|
||||
AC_MSG_RESULT([$su_cv_sys_c_line_in_termios])
|
||||
test $su_cv_sys_c_line_in_termios = yes \
|
||||
&& AC_DEFINE(HAVE_C_LINE, 1, [FIXME])
|
||||
&& AC_DEFINE([HAVE_C_LINE], [1], [FIXME])
|
||||
fi
|
||||
|
||||
# FIXME: note that this macro appears above, too.
|
||||
@@ -219,8 +252,8 @@ gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H
|
||||
|
||||
if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
|
||||
test $gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h = no; then
|
||||
AC_MSG_CHECKING(TIOCGWINSZ in sys/pty.h)
|
||||
AC_CACHE_VAL(su_cv_sys_tiocgwinsz_in_sys_pty_h,
|
||||
AC_MSG_CHECKING([TIOCGWINSZ in sys/pty.h])
|
||||
AC_CACHE_VAL([su_cv_sys_tiocgwinsz_in_sys_pty_h],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
|
||||
#ifdef WINSIZE_IN_PTEM
|
||||
# include <sys/stream.h>
|
||||
@@ -231,10 +264,10 @@ if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
|
||||
#include <sys/pty.h>]], [[int x = TIOCGWINSZ;]])],
|
||||
[su_cv_sys_tiocgwinsz_in_sys_pty_h=yes],
|
||||
[su_cv_sys_tiocgwinsz_in_sys_pty_h=no])])
|
||||
AC_MSG_RESULT($su_cv_sys_tiocgwinsz_in_sys_pty_h)
|
||||
AC_MSG_RESULT([$su_cv_sys_tiocgwinsz_in_sys_pty_h])
|
||||
|
||||
test $su_cv_sys_tiocgwinsz_in_sys_pty_h = yes \
|
||||
&& AC_DEFINE(GWINSZ_IN_SYS_PTY, 1,
|
||||
&& AC_DEFINE([GWINSZ_IN_SYS_PTY], [1],
|
||||
[Define if your system defines TIOCGWINSZ in sys/pty.h.])
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Make coreutils documentation. -*-Makefile-*-
|
||||
|
||||
# Copyright (C) 1995-1998, 2001-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1995-1998, 2001-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -29,10 +29,13 @@ EXTRA_DIST = perm.texi getdate.texi constants.texi fdl.texi
|
||||
# old systems.
|
||||
AM_MAKEINFOFLAGS = --no-split
|
||||
|
||||
constants.texi: $(top_srcdir)/src/tail.c
|
||||
constants.texi: $(top_srcdir)/src/tail.c $(top_srcdir)/src/shred.c
|
||||
LC_ALL=C \
|
||||
sed -n -e 's/^#define \(DEFAULT_MAX[_A-Z]*\) \(.*\)/@set \1 \2/p' \
|
||||
$(top_srcdir)/src/tail.c > t-$@
|
||||
LC_ALL=C \
|
||||
sed -n -e 's/.*\(DEFAULT_PASSES\)[ =]* \([0-9]*\).*/@set SHRED_\1 \2/p'\
|
||||
$(top_srcdir)/src/shred.c >> t-$@
|
||||
mv t-$@ $@
|
||||
|
||||
MAINTAINERCLEANFILES = constants.texi
|
||||
@@ -50,13 +53,14 @@ syntax_checks = \
|
||||
sc-avoid-timezone \
|
||||
sc-avoid-zeroes \
|
||||
sc-exponent-grouping \
|
||||
sc-lower-case-var \
|
||||
sc-use-small-caps-NUL
|
||||
|
||||
.PHONY: $(syntax_checks) check-texinfo
|
||||
|
||||
# List words/regexps here that should not appear in the texinfo documentation.
|
||||
check-texinfo: $(syntax_checks)
|
||||
fail=0; \
|
||||
@fail=0; \
|
||||
grep '@url{' $(srcdir)/*.texi && fail=1; \
|
||||
grep '\$$@"' $(srcdir)/*.texi && fail=1; \
|
||||
grep -n '[^[:punct:]]@footnote' $(srcdir)/*.texi && fail=1; \
|
||||
@@ -73,27 +77,45 @@ check-texinfo: $(syntax_checks)
|
||||
|
||||
# Use `time zone', not `timezone'.
|
||||
sc-avoid-timezone:
|
||||
$(EGREP) timezone $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) timezone $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# Check for insufficient exponent grouping, e.g.,
|
||||
# @math{2^64} should be @math{2^{64}}.
|
||||
sc-exponent-grouping:
|
||||
$(EGREP) '\{.*\^[0-9][0-9]' $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) '\{.*\^[0-9][0-9]' $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# E.g., use @sc{nul}, not NUL.
|
||||
sc-use-small-caps-NUL:
|
||||
$(EGREP) '$(_W)NUL$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) '$(_W)NUL$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# Say I/O, not IO.
|
||||
sc-avoid-io:
|
||||
$(EGREP) '$(_W)IO$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) '$(_W)IO$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# I prefer nonzero over non-zero.
|
||||
sc-avoid-non-zero:
|
||||
$(EGREP) non-zero $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) non-zero $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# Use `zeros', not `zeroes' (nothing wrong with `zeroes'. just be consistent).
|
||||
sc-avoid-zeroes:
|
||||
$(EGREP) -i '$(_W)zeroes$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
@$(EGREP) -i '$(_W)zeroes$(W_)' $(srcdir)/*.texi && exit 1 || :
|
||||
|
||||
# ME = $(subdir)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
ME = doc/Makefile
|
||||
|
||||
# The quantity inside @var{...} should not contain upper case letters.
|
||||
# The leading backslash exemption is to permit in-macro uses like
|
||||
# @var{\varName\} where the upper case letter is part of a parameter name.
|
||||
find_upper_case_var = \
|
||||
'/\@var{/ or next; \
|
||||
while (/\@var{(.+?)}/g) \
|
||||
{ \
|
||||
$$v = $$1; \
|
||||
$$v =~ /[A-Z]/ && $$v !~ /^\\/ and (print "$$ARGV:$$.:$$_"), $$m = 1 \
|
||||
} \
|
||||
END {$$m and (warn "$(ME): do not use upper case in \@var{...}\n"), exit 1}'
|
||||
sc-lower-case-var:
|
||||
@$(PERL) -e 1 2> /dev/null && \
|
||||
$(PERL) -lne $(find_upper_case_var) $(srcdir)/*.texi
|
||||
|
||||
check: check-texinfo
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
||||
@c File mode bits
|
||||
|
||||
@c Copyright (C) 1994, 1996, 1999, 2000, 2001, 2003, 2004, 2005, 2006
|
||||
@c Copyright (C) 1994, 1996, 1999-2001, 2003-2006, 2008
|
||||
@c Free Software Foundation, Inc.
|
||||
|
||||
@c Permission is granted to copy, distribute and/or modify this document
|
||||
@c under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
@c under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
@c any later version published by the Free Software Foundation; with no
|
||||
@c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||
@c Texts. A copy of the license is included in the ``GNU Free
|
||||
|
||||
117
gl/lib/argv-iter.c
Normal file
117
gl/lib/argv-iter.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* Iterate over arguments from argv or --files0-from=FILE
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#include <config.h>
|
||||
#include "argv-iter.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct argv_iterator
|
||||
{
|
||||
/* Test FP to determine whether in read-mode or argv-mode. */
|
||||
/* file-mode: fp records position */
|
||||
FILE *fp;
|
||||
size_t item_idx;
|
||||
char *tok;
|
||||
size_t buf_len;
|
||||
|
||||
/* argv-mode: record just argv and current pointer */
|
||||
char **arg_list;
|
||||
char **p;
|
||||
};
|
||||
|
||||
struct argv_iterator *
|
||||
argv_iter_init_argv (char **argv)
|
||||
{
|
||||
struct argv_iterator *ai = malloc (sizeof *ai);
|
||||
if (!ai)
|
||||
return NULL;
|
||||
ai->fp = NULL;
|
||||
ai->arg_list = argv;
|
||||
ai->p = argv;
|
||||
return ai;
|
||||
}
|
||||
|
||||
/* Initialize to read from the stream, FP.
|
||||
The input is expected to contain a list of NUL-delimited tokens. */
|
||||
struct argv_iterator *
|
||||
argv_iter_init_stream (FILE *fp)
|
||||
{
|
||||
struct argv_iterator *ai = malloc (sizeof *ai);
|
||||
if (!ai)
|
||||
return NULL;
|
||||
ai->fp = fp;
|
||||
ai->tok = NULL;
|
||||
ai->buf_len = 0;
|
||||
|
||||
ai->item_idx = 0;
|
||||
ai->arg_list = NULL;
|
||||
return ai;
|
||||
}
|
||||
|
||||
char *
|
||||
argv_iter (struct argv_iterator *ai, enum argv_iter_err *err)
|
||||
{
|
||||
if (ai->fp)
|
||||
{
|
||||
ssize_t len = getdelim (&ai->tok, &ai->buf_len, '\0', ai->fp);
|
||||
if (len < 0)
|
||||
{
|
||||
*err = feof (ai->fp) ? AI_ERR_EOF : AI_ERR_READ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*err = AI_ERR_OK;
|
||||
ai->item_idx++;
|
||||
return ai->tok;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*(ai->p) == NULL)
|
||||
{
|
||||
*err = AI_ERR_EOF;
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
*err = AI_ERR_OK;
|
||||
return *(ai->p++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
argv_iter_n_args (struct argv_iterator const *ai)
|
||||
{
|
||||
return ai->fp ? ai->item_idx : ai->p - ai->arg_list;
|
||||
}
|
||||
|
||||
void
|
||||
argv_iter_free (struct argv_iterator *ai)
|
||||
{
|
||||
if (ai->fp)
|
||||
free (ai->tok);
|
||||
free (ai);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*/
|
||||
47
gl/lib/argv-iter.h
Normal file
47
gl/lib/argv-iter.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Iterate over arguments from argv or --files0-from=FILE
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct argv_iterator;
|
||||
enum argv_iter_err;
|
||||
|
||||
#undef _ATTRIBUTE_NONNULL_
|
||||
#if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || 3 < __GNUC__
|
||||
# define _ATTRIBUTE_NONNULL_(m,...) __attribute__ ((__nonnull__ (m)))
|
||||
#else
|
||||
# define _ATTRIBUTE_NONNULL_(m,...)
|
||||
#endif
|
||||
|
||||
enum argv_iter_err
|
||||
{
|
||||
AI_ERR_OK = 1,
|
||||
AI_ERR_EOF,
|
||||
AI_ERR_MEM,
|
||||
AI_ERR_READ
|
||||
};
|
||||
|
||||
struct argv_iterator *argv_iter_init_argv (char **argv)
|
||||
_ATTRIBUTE_NONNULL_ (1);
|
||||
struct argv_iterator *argv_iter_init_stream (FILE *fp)
|
||||
_ATTRIBUTE_NONNULL_ (1);
|
||||
char *argv_iter (struct argv_iterator *, enum argv_iter_err *)
|
||||
_ATTRIBUTE_NONNULL_ (1, 2);
|
||||
size_t argv_iter_n_args (struct argv_iterator const *)
|
||||
_ATTRIBUTE_NONNULL_ (1);
|
||||
void argv_iter_free (struct argv_iterator *)
|
||||
_ATTRIBUTE_NONNULL_ (1);
|
||||
@@ -1,6 +1,6 @@
|
||||
/* mgetgroups.c -- return a list of the groups a user is in
|
||||
|
||||
Copyright (C) 2007-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2007-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -33,16 +33,16 @@
|
||||
#include "xalloc.h"
|
||||
|
||||
|
||||
static void *
|
||||
allocate_groupbuf (int size)
|
||||
static GETGROUPS_T *
|
||||
realloc_groupbuf (GETGROUPS_T *g, size_t num)
|
||||
{
|
||||
if (xalloc_oversized (size, sizeof (GETGROUPS_T)))
|
||||
if (xalloc_oversized (num, sizeof (*g)))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return malloc (size * sizeof (GETGROUPS_T));
|
||||
return realloc (g, num * sizeof (*g));
|
||||
}
|
||||
|
||||
/* Like getugroups, but store the result in malloc'd storage.
|
||||
@@ -65,45 +65,27 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
|
||||
performance characteristics.
|
||||
|
||||
In glibc 2.3.2, getgrouplist is buggy. If you pass a zero as the
|
||||
size of the output buffer, getgrouplist will still write to the
|
||||
length of the output buffer, getgrouplist will still write to the
|
||||
buffer. Contrary to what some versions of the getgrouplist
|
||||
manpage say, this doesn't happen with nonzero buffer sizes.
|
||||
Therefore our usage here just avoids a zero sized buffer. */
|
||||
if (username)
|
||||
{
|
||||
enum { N_GROUPS_INIT = 10 };
|
||||
GETGROUPS_T smallbuf[N_GROUPS_INIT];
|
||||
|
||||
max_n_groups = N_GROUPS_INIT;
|
||||
ng = getgrouplist (username, gid, smallbuf, &max_n_groups);
|
||||
|
||||
g = allocate_groupbuf (max_n_groups);
|
||||
g = realloc_groupbuf (NULL, max_n_groups);
|
||||
if (g == NULL)
|
||||
return -1;
|
||||
|
||||
if (max_n_groups <= N_GROUPS_INIT)
|
||||
{
|
||||
/* smallbuf was big enough, so we already have our data */
|
||||
memcpy (g, smallbuf, max_n_groups * sizeof *g);
|
||||
*groups = g;
|
||||
return max_n_groups;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
GETGROUPS_T *h;
|
||||
|
||||
/* getgrouplist updates max_n_groups to num required. */
|
||||
ng = getgrouplist (username, gid, g, &max_n_groups);
|
||||
if (0 <= ng)
|
||||
{
|
||||
*groups = g;
|
||||
return ng;
|
||||
}
|
||||
|
||||
/* When getgrouplist fails, it guarantees that
|
||||
max_n_groups reflects the new number of groups. */
|
||||
|
||||
if (xalloc_oversized (max_n_groups, sizeof *h)
|
||||
|| (h = realloc (g, max_n_groups * sizeof *h)) == NULL)
|
||||
if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
free (g);
|
||||
@@ -111,6 +93,12 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
|
||||
return -1;
|
||||
}
|
||||
g = h;
|
||||
|
||||
if (0 <= ng)
|
||||
{
|
||||
*groups = g;
|
||||
return ng;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else no username, so fall through and use getgroups. */
|
||||
@@ -125,7 +113,7 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
|
||||
if (max_n_groups < 0)
|
||||
max_n_groups = 5;
|
||||
|
||||
g = allocate_groupbuf (max_n_groups);
|
||||
g = realloc_groupbuf (NULL, max_n_groups);
|
||||
if (g == NULL)
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef SELINUX_CONTEXT_H
|
||||
# define SELINUX_CONTEXT_H
|
||||
|
||||
# include <errno.h>
|
||||
/* Some systems don't have ENOTSUP. */
|
||||
# ifndef ENOTSUP
|
||||
# ifdef ENOSYS
|
||||
# define ENOTSUP ENOSYS
|
||||
# else
|
||||
/* Some systems don't have ENOSYS either. */
|
||||
# define ENOTSUP EINVAL
|
||||
# endif
|
||||
# endif
|
||||
|
||||
typedef int context_t;
|
||||
static inline context_t context_new (char const *s)
|
||||
{ errno = ENOTSUP; return 0; }
|
||||
static inline char *context_str (context_t con)
|
||||
{ errno = ENOTSUP; return (void *) 0; }
|
||||
static inline void context_free (context_t c) {}
|
||||
|
||||
static inline int context_user_set (context_t sc, char const *s)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int context_role_set (context_t sc, char const *s)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int context_range_set (context_t sc, char const *s)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int context_type_set (context_t sc, char const *s)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef SELINUX_SELINUX_H
|
||||
# define SELINUX_SELINUX_H
|
||||
|
||||
# include <sys/types.h>
|
||||
# include <errno.h>
|
||||
/* Some systems don't have ENOTSUP. */
|
||||
# ifndef ENOTSUP
|
||||
# ifdef ENOSYS
|
||||
# define ENOTSUP ENOSYS
|
||||
# else
|
||||
/* Some systems don't have ENOSYS either. */
|
||||
# define ENOTSUP EINVAL
|
||||
# endif
|
||||
# endif
|
||||
|
||||
typedef unsigned short security_class_t;
|
||||
# define security_context_t char*
|
||||
# define is_selinux_enabled() 0
|
||||
|
||||
static inline int getcon (security_context_t *con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline void freecon (security_context_t con) {}
|
||||
|
||||
|
||||
static inline int getfscreatecon (security_context_t *con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int setfscreatecon (security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int matchpathcon (char const *s, mode_t m,
|
||||
security_context_t *con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int getfilecon (char const *s, security_context_t *con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int lgetfilecon (char const *s, security_context_t *con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int setfilecon (char const *s, security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int lsetfilecon (char const *s, security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int fsetfilecon (int fd, security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
|
||||
static inline int security_check_context (security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int security_check_context_raw (security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int setexeccon (security_context_t con)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int security_compute_create (security_context_t scon,
|
||||
security_context_t tcon,
|
||||
security_class_t tclass,
|
||||
security_context_t *newcon)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
static inline int matchpathcon_init_prefix (char const *path,
|
||||
char const *prefix)
|
||||
{ errno = ENOTSUP; return -1; }
|
||||
#endif
|
||||
41
gl/lib/xfreopen.c
Normal file
41
gl/lib/xfreopen.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* a wrapper for frepoen
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
#include "xfreopen.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include "error.h"
|
||||
#include "exitfail.h"
|
||||
#include "quote.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
void
|
||||
xfreopen (char const *filename, char const *mode, FILE *fp)
|
||||
{
|
||||
if (!freopen (filename, mode, fp))
|
||||
{
|
||||
char const *f = (filename ? filename
|
||||
: (fp == stdin ? _("stdin")
|
||||
: (fp == stdout ? _("stdout")
|
||||
: (fp == stderr ? _("stderr")
|
||||
: _("unknown stream")))));
|
||||
error (exit_failure, errno, _("failed to reopen %s with mode %s"),
|
||||
quote_n (0, f), quote_n (1, mode));
|
||||
}
|
||||
}
|
||||
2
gl/lib/xfreopen.h
Normal file
2
gl/lib/xfreopen.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <stdio.h>
|
||||
void xfreopen (char const *filename, char const *mode, FILE *fp);
|
||||
@@ -1,4 +1,4 @@
|
||||
#serial 2
|
||||
#serial 3
|
||||
dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
@@ -6,6 +6,6 @@ dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
AC_DEFUN([gl_MGETGROUPS],
|
||||
[
|
||||
AC_CHECK_FUNCS(getgrouplist)
|
||||
AC_CHECK_FUNCS([getgrouplist])
|
||||
AC_LIBOBJ([mgetgroups])
|
||||
])
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# serial 1 -*- Autoconf -*-
|
||||
# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# From Jim Meyering
|
||||
# Provide <selinux/context.h>, if necessary.
|
||||
|
||||
AC_DEFUN([gl_HEADERS_SELINUX_CONTEXT_H],
|
||||
[
|
||||
# Check for <selinux/context.h>,
|
||||
AC_CHECK_HEADERS([selinux/context.h],
|
||||
[SELINUX_CONTEXT_H=],
|
||||
[SELINUX_CONTEXT_H=selinux/context.h])
|
||||
AC_SUBST([SELINUX_CONTEXT_H])
|
||||
])
|
||||
@@ -1,17 +0,0 @@
|
||||
# serial 1 -*- Autoconf -*-
|
||||
# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# From Jim Meyering
|
||||
# Provide <selinux/selinux.h>, if necessary.
|
||||
|
||||
AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H],
|
||||
[
|
||||
# Check for <selinux/selinux.h>,
|
||||
AC_CHECK_HEADERS([selinux/selinux.h],
|
||||
[SELINUX_SELINUX_H=],
|
||||
[SELINUX_SELINUX_H=selinux/selinux.h])
|
||||
AC_SUBST([SELINUX_SELINUX_H])
|
||||
])
|
||||
24
gl/modules/argv-iter
Normal file
24
gl/modules/argv-iter
Normal file
@@ -0,0 +1,24 @@
|
||||
Description:
|
||||
iterate through argv or a --files0-from=-specified file
|
||||
|
||||
Files:
|
||||
lib/argv-iter.c
|
||||
lib/argv-iter.h
|
||||
|
||||
Depends-on:
|
||||
getdelim
|
||||
stdbool
|
||||
|
||||
configure.ac:
|
||||
|
||||
Makefile.am:
|
||||
lib_SOURCES += argv-iter.c argv-iter.h
|
||||
|
||||
Include:
|
||||
"argv-iter.h"
|
||||
|
||||
License
|
||||
GPL
|
||||
|
||||
Maintainer:
|
||||
Jim Meyering
|
||||
10
gl/modules/argv-iter-tests
Normal file
10
gl/modules/argv-iter-tests
Normal file
@@ -0,0 +1,10 @@
|
||||
Files:
|
||||
tests/test-argv-iter.c
|
||||
|
||||
Depends-on:
|
||||
|
||||
configure.ac:
|
||||
|
||||
Makefile.am:
|
||||
TESTS += test-argv-iter
|
||||
check_PROGRAMS += test-argv-iter
|
||||
@@ -1,16 +1,13 @@
|
||||
Index: modules/getloadavg
|
||||
===================================================================
|
||||
RCS file: /sources/gnulib/gnulib/modules/getloadavg,v
|
||||
retrieving revision 1.13
|
||||
diff -u -p -r1.13 getloadavg
|
||||
--- modules/getloadavg 22 Sep 2006 12:47:55 -0000 1.13
|
||||
+++ modules/getloadavg 23 Sep 2006 16:41:36 -0000
|
||||
@@ -14,7 +14,7 @@ stdbool
|
||||
diff --git a/modules/getloadavg b/modules/getloadavg
|
||||
index 2fbeb40..b79aaca 100644
|
||||
--- a/modules/getloadavg
|
||||
+++ b/modules/getloadavg
|
||||
@@ -16,7 +16,7 @@ stdbool
|
||||
fcntl-safer
|
||||
|
||||
configure.ac:
|
||||
-gl_GETLOADAVG([$gl_source_base])
|
||||
+gl_GETLOADAVG([lib])
|
||||
gl_STDLIB_MODULE_INDICATOR([getloadavg])
|
||||
|
||||
Makefile.am:
|
||||
|
||||
|
||||
@@ -13,12 +13,13 @@ configure.ac:
|
||||
# For runcon.
|
||||
AC_CHECK_HEADERS([selinux/flask.h])
|
||||
AC_LIBOBJ([selinux-at])
|
||||
ac_save_LIBS="$LIBS"
|
||||
AC_SEARCH_LIBS(setfilecon, selinux,
|
||||
gl_save_LIBS=$LIBS
|
||||
LIB_SELINUX=
|
||||
AC_SEARCH_LIBS([setfilecon], [selinux],
|
||||
[test "$ac_cv_search_setfilecon" = "none required" ||
|
||||
LIB_SELINUX=$ac_cv_search_setfilecon])
|
||||
AC_SUBST(LIB_SELINUX)
|
||||
LIBS="$ac_save_LIBS"
|
||||
LIBS=$gl_save_LIBS
|
||||
|
||||
Makefile.am:
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
Description:
|
||||
SELinux-related headers for systems that lack them.
|
||||
|
||||
Files:
|
||||
lib/se-context.in.h
|
||||
lib/se-selinux.in.h
|
||||
m4/selinux-context-h.m4
|
||||
m4/selinux-selinux-h.m4
|
||||
|
||||
Depends-on:
|
||||
|
||||
configure.ac:
|
||||
gl_HEADERS_SELINUX_SELINUX_H
|
||||
gl_HEADERS_SELINUX_CONTEXT_H
|
||||
|
||||
Makefile.am:
|
||||
lib_SOURCES += se-context.in.h se-selinux.in.h
|
||||
|
||||
BUILT_SOURCES += $(SELINUX_SELINUX_H)
|
||||
selinux/selinux.h: se-selinux.in.h
|
||||
mkdir -p selinux
|
||||
cp $(srcdir)/se-selinux.in.h $@-t
|
||||
chmod a-x $@-t
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += selinux/selinux.h selinux/selinux.h-t
|
||||
|
||||
BUILT_SOURCES += $(SELINUX_CONTEXT_H)
|
||||
selinux/context.h: se-context.in.h
|
||||
mkdir -p selinux
|
||||
cp $(srcdir)/se-context.in.h $@-t
|
||||
chmod a-x $@-t
|
||||
mv $@-t $@
|
||||
MOSTLYCLEANFILES += selinux/context.h selinux/context.h-t
|
||||
MOSTLYCLEANDIRS += selinux
|
||||
|
||||
Include:
|
||||
#include <selinux/selinux.h>
|
||||
#include <selinux/context.h>
|
||||
|
||||
License:
|
||||
LGPL
|
||||
|
||||
Maintainer:
|
||||
Jim Meyering
|
||||
|
||||
# lib/selinux-at.c
|
||||
#
|
||||
# # For runcon.
|
||||
# AC_CHECK_HEADERS([selinux/flask.h])
|
||||
#
|
||||
# ac_save_LIBS="$LIBS"
|
||||
# AC_SEARCH_LIBS(setfilecon, selinux,
|
||||
# [test "$ac_cv_search_setfilecon" = "none required" ||
|
||||
# LIB_SELINUX=$ac_cv_search_setfilecon])
|
||||
# AC_SUBST(LIB_SELINUX)
|
||||
# LIBS="$ac_save_LIBS"
|
||||
25
gl/modules/xfreopen
Normal file
25
gl/modules/xfreopen
Normal file
@@ -0,0 +1,25 @@
|
||||
Description:
|
||||
a wrapper for frepoen
|
||||
|
||||
Files:
|
||||
lib/xfreopen.c
|
||||
lib/xfreopen.h
|
||||
|
||||
Depends-on:
|
||||
error
|
||||
exitfail
|
||||
quote
|
||||
|
||||
configure.ac:
|
||||
|
||||
Makefile.am:
|
||||
lib_SOURCES += xfreopen.c xfreopen.h
|
||||
|
||||
Include:
|
||||
"xfreopen.h"
|
||||
|
||||
License:
|
||||
LGPL
|
||||
|
||||
Maintainer:
|
||||
Jim Meyering
|
||||
120
gl/tests/test-argv-iter.c
Normal file
120
gl/tests/test-argv-iter.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* Test argv iterator
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
|
||||
#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
|
||||
#define ASSERT(expr) \
|
||||
do \
|
||||
{ \
|
||||
if (!(expr)) \
|
||||
{ \
|
||||
fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
|
||||
fflush (stderr); \
|
||||
abort (); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#include "argv-iter.h"
|
||||
|
||||
static FILE *
|
||||
write_nul_delimited_argv (char **argv)
|
||||
{
|
||||
FILE *fp = tmpfile ();
|
||||
ASSERT (fp);
|
||||
while (*argv)
|
||||
{
|
||||
size_t len = strlen (*argv) + 1;
|
||||
ASSERT (fwrite (*argv, len, 1, fp) == 1);
|
||||
argv++;
|
||||
}
|
||||
ASSERT (fflush (fp) == 0);
|
||||
rewind (fp);
|
||||
return fp;
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
/* set_program_name (argv[0]); placate overzealous "syntax-check" test. */
|
||||
static char *av[][4] = {
|
||||
{NULL},
|
||||
{"1", NULL},
|
||||
{"1", "2", NULL},
|
||||
{"1", "2", "3", NULL}
|
||||
};
|
||||
|
||||
int use_stream;
|
||||
for (use_stream = 0; use_stream < 2; use_stream++)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < ARRAY_CARDINALITY (av); i++)
|
||||
{
|
||||
FILE *fp;
|
||||
struct argv_iterator *ai;
|
||||
if (use_stream)
|
||||
{
|
||||
/* Generate an identical list to be read via FP. */
|
||||
ASSERT ((fp = write_nul_delimited_argv (av[i])) != NULL);
|
||||
ai = argv_iter_init_stream (fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = NULL;
|
||||
ai = argv_iter_init_argv (av[i]);
|
||||
}
|
||||
ASSERT (ai);
|
||||
|
||||
size_t n_found = 0;
|
||||
while (1)
|
||||
{
|
||||
enum argv_iter_err ai_err;
|
||||
char *s = argv_iter (ai, &ai_err);
|
||||
ASSERT ((i == n_found) == (ai_err == AI_ERR_EOF));
|
||||
ASSERT ((s == NULL) ^ (ai_err == AI_ERR_OK));
|
||||
ASSERT (ai_err == AI_ERR_OK || ai_err == AI_ERR_EOF);
|
||||
if (ai_err == AI_ERR_OK)
|
||||
++n_found;
|
||||
if (ai_err == AI_ERR_EOF)
|
||||
break;
|
||||
/* In stream mode, the strings are equal, but
|
||||
in argv mode the actual pointers are equal. */
|
||||
ASSERT (use_stream
|
||||
? STREQ (s, av[i][n_found - 1])
|
||||
: s == av[i][n_found - 1]);
|
||||
}
|
||||
ASSERT (argv_iter_n_args (ai) == i);
|
||||
argv_iter_free (ai);
|
||||
if (fp)
|
||||
ASSERT (fclose (fp) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*/
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
include gnulib.mk
|
||||
|
||||
AM_CFLAGS = $(WARNING_CFLAGS) $(WERROR_CFLAGS)
|
||||
AM_CFLAGS = $(WARN_CFLAGS) # $(WERROR_CFLAGS)
|
||||
|
||||
libcoreutils_a_SOURCES += \
|
||||
buffer-lcm.c buffer-lcm.h \
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# boottime.m4 serial 3
|
||||
# boottime.m4 serial 4
|
||||
# Determine whether this system has infrastructure for obtaining the boot time.
|
||||
|
||||
# Copyright (C) 1996, 2000, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996, 2000, 2002-2004, 2006, 2008 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -20,14 +20,14 @@
|
||||
* ----------------------------------------------------------
|
||||
AC_DEFUN([GNULIB_BOOT_TIME],
|
||||
[
|
||||
AC_CHECK_FUNCS(sysctl)
|
||||
AC_CHECK_HEADERS_ONCE(sys/param.h)
|
||||
AC_CHECK_HEADERS(sys/sysctl.h, [], [],
|
||||
AC_CHECK_FUNCS([sysctl])
|
||||
AC_CHECK_HEADERS_ONCE([sys/param.h])
|
||||
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
|
||||
[AC_INCLUDES_DEFAULT
|
||||
[#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif]])
|
||||
AC_CHECK_HEADERS_ONCE(utmp.h utmpx.h OS.h)
|
||||
AC_CHECK_HEADERS_ONCE([utmp.h utmpx.h OS.h])
|
||||
AC_CACHE_CHECK(
|
||||
[whether we can get the system boot time],
|
||||
[gnulib_cv_have_boot_time],
|
||||
@@ -57,8 +57,8 @@ AC_DEFUN([GNULIB_BOOT_TIME],
|
||||
please_tell_us_how_to_determine_boot_time_on_your_system
|
||||
#endif
|
||||
]])],
|
||||
gnulib_cv_have_boot_time=yes,
|
||||
gnulib_cv_have_boot_time=no)
|
||||
[gnulib_cv_have_boot_time=yes],
|
||||
[gnulib_cv_have_boot_time=no])
|
||||
])
|
||||
AS_IF([test $gnulib_cv_have_boot_time = yes], [$1], [$2])
|
||||
])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#serial 23
|
||||
#serial 24
|
||||
# Check declarations for this package.
|
||||
|
||||
dnl Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006
|
||||
dnl Copyright (C) 1997-2001, 2003-2006, 2008
|
||||
dnl Free Software Foundation, Inc.
|
||||
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
@@ -16,7 +16,7 @@ AC_DEFUN([gl_CHECK_DECLS],
|
||||
[
|
||||
AC_REQUIRE([AC_HEADER_TIME])
|
||||
|
||||
AC_CHECK_HEADERS_ONCE(grp.h pwd.h)
|
||||
AC_CHECK_HEADERS_ONCE([grp.h pwd.h])
|
||||
headers='
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ AC_DEFUN([cu_GMP],
|
||||
[test "$ac_cv_search___gmpz_init" = "none required" ||
|
||||
{
|
||||
LIB_GMP=$ac_cv_search___gmpz_init
|
||||
AC_DEFINE([HAVE_GMP], 1,
|
||||
AC_DEFINE([HAVE_GMP], [1],
|
||||
[Define if you have GNU libgmp (or replacement)])
|
||||
}])
|
||||
LIBS=$cu_saved_libs
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#serial 107 -*- autoconf -*-
|
||||
#serial 109 -*- autoconf -*-
|
||||
|
||||
dnl Misc type-related macros for coreutils.
|
||||
|
||||
# Copyright (C) 1998, 2000-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1998, 2000-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -22,7 +22,7 @@ dnl Misc type-related macros for coreutils.
|
||||
AC_DEFUN([coreutils_MACROS],
|
||||
[
|
||||
AM_MISSING_PROG(HELP2MAN, help2man)
|
||||
AC_SUBST(MAN)
|
||||
AC_SUBST([MAN])
|
||||
|
||||
dnl This macro actually runs replacement code. See isc-posix.m4.
|
||||
AC_REQUIRE([AC_ISC_POSIX])dnl
|
||||
@@ -36,15 +36,15 @@ AC_DEFUN([coreutils_MACROS],
|
||||
AC_REQUIRE([AC_FUNC_FSEEKO])
|
||||
|
||||
# By default, argmatch should fail calling usage (1).
|
||||
AC_DEFINE(ARGMATCH_DIE, [usage (1)],
|
||||
AC_DEFINE([ARGMATCH_DIE], [usage (1)],
|
||||
[Define to the function xargmatch calls on failures.])
|
||||
AC_DEFINE(ARGMATCH_DIE_DECL, [void usage ()],
|
||||
AC_DEFINE([ARGMATCH_DIE_DECL], [void usage (int _e)],
|
||||
[Define to the declaration of the xargmatch failure function.])
|
||||
|
||||
# used by ls
|
||||
AC_REQUIRE([gl_CLOCK_TIME])
|
||||
# used by shred
|
||||
AC_CHECK_FUNCS_ONCE(directio)
|
||||
AC_CHECK_FUNCS_ONCE([directio])
|
||||
|
||||
# Used by install.c.
|
||||
AC_CHECK_FUNCS_ONCE([matchpathcon_init_prefix])
|
||||
@@ -79,7 +79,7 @@ AC_DEFUN([coreutils_MACROS],
|
||||
[test "$ac_cv_search_fdatasync" = "none required" ||
|
||||
LIB_FDATASYNC=$ac_cv_search_fdatasync])
|
||||
AC_SUBST([LIB_FDATASYNC])
|
||||
AC_CHECK_FUNCS(fdatasync)
|
||||
AC_CHECK_FUNCS([fdatasync])
|
||||
LIBS=$coreutils_saved_libs
|
||||
|
||||
# Check whether libcap is usable -- for ls --color support
|
||||
@@ -88,8 +88,9 @@ AC_DEFUN([coreutils_MACROS],
|
||||
AC_MSG_WARN([libcap support disabled by user]),
|
||||
[AC_CHECK_LIB([cap], [cap_get_file],
|
||||
[AC_CHECK_HEADER([sys/capability.h],
|
||||
[LIB_CAP=-lcap AC_DEFINE([HAVE_CAP], 1, [libcap usability])],
|
||||
[AC_MSG_WARN([header sys/capability.h was not found, support for libcap will not be built])]
|
||||
[LIB_CAP=-lcap
|
||||
AC_DEFINE([HAVE_CAP], [1], [libcap usability])],
|
||||
[AC_MSG_WARN([header sys/capability.h was not found, support for libcap will not be built])]
|
||||
)],
|
||||
[AC_MSG_WARN([libcap library was not found or not usable, support for libcap will not be built])])
|
||||
])
|
||||
@@ -100,16 +101,16 @@ AC_DEFUN([coreutils_MACROS],
|
||||
# BeOS which has all the math functions in the normal runtime library
|
||||
# and doesn't have a separate math library.
|
||||
|
||||
AC_SUBST(SEQ_LIBM)
|
||||
AC_SUBST([SEQ_LIBM])
|
||||
ac_seq_body='
|
||||
static double x, y;
|
||||
x = floor (x);
|
||||
x = rint (x);
|
||||
x = modf (x, &y);'
|
||||
AC_TRY_LINK([#include <math.h>], $ac_seq_body, ,
|
||||
AC_TRY_LINK([#include <math.h>], [$ac_seq_body], ,
|
||||
[ac_seq_save_LIBS="$LIBS"
|
||||
LIBS="$LIBS -lm"
|
||||
AC_TRY_LINK([#include <math.h>], $ac_seq_body, SEQ_LIBM=-lm)
|
||||
AC_TRY_LINK([#include <math.h>], [$ac_seq_body], [SEQ_LIBM=-lm])
|
||||
LIBS="$ac_seq_save_LIBS"
|
||||
])
|
||||
|
||||
@@ -132,7 +133,7 @@ AC_DEFUN([gl_CHECK_ALL_HEADERS],
|
||||
syslog.h \
|
||||
termios.h \
|
||||
)
|
||||
AC_CHECK_HEADERS(sys/sysctl.h, [], [],
|
||||
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
|
||||
[AC_INCLUDES_DEFAULT
|
||||
[#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
@@ -153,7 +154,7 @@ AC_DEFUN([gl_CHECK_ALL_TYPES],
|
||||
AC_REQUIRE([AM_C_PROTOTYPES])
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_REQUIRE([AC_C_BIGENDIAN])
|
||||
AC_REQUIRE([gl_BIGENDIAN])
|
||||
AC_REQUIRE([AC_C_VOLATILE])
|
||||
AC_REQUIRE([AC_C_INLINE])
|
||||
AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
|
||||
@@ -173,12 +174,12 @@ AC_DEFUN([gl_CHECK_ALL_TYPES],
|
||||
AC_REQUIRE([AC_TYPE_PID_T])
|
||||
AC_REQUIRE([AC_TYPE_SIZE_T])
|
||||
AC_REQUIRE([AC_TYPE_UID_T])
|
||||
AC_CHECK_TYPE(ino_t, unsigned long int)
|
||||
AC_CHECK_TYPE([ino_t], [unsigned long int])
|
||||
|
||||
dnl This relies on the fact that Autoconf's implementation of
|
||||
dnl AC_CHECK_TYPE checks includes unistd.h.
|
||||
AC_CHECK_TYPE(major_t, unsigned int)
|
||||
AC_CHECK_TYPE(minor_t, unsigned int)
|
||||
AC_CHECK_TYPE([major_t], [unsigned int])
|
||||
AC_CHECK_TYPE([minor_t], [unsigned int])
|
||||
|
||||
AC_REQUIRE([AC_HEADER_MAJOR])
|
||||
])
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#serial 10
|
||||
#serial 11
|
||||
|
||||
dnl Misc lib-related macros for coreutils.
|
||||
|
||||
# Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004,
|
||||
# 2005, 2006 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1993-1997, 2000-2001, 2003-2006, 2008
|
||||
# Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -24,20 +24,20 @@ AC_DEFUN([cu_LIB_CHECK],
|
||||
[
|
||||
|
||||
# Check for libypsec.a on Dolphin M88K machines.
|
||||
AC_CHECK_LIB(ypsec, main)
|
||||
AC_CHECK_LIB([ypsec], [main])
|
||||
|
||||
# m88k running dgux 5.4 needs this
|
||||
AC_CHECK_LIB(ldgc, main)
|
||||
AC_CHECK_LIB([ldgc], [main])
|
||||
|
||||
# The -lsun library is required for YP support on Irix-4.0.5 systems.
|
||||
# m88k/svr3 DolphinOS systems using YP need -lypsec for id.
|
||||
AC_SEARCH_LIBS(yp_match, [sun ypsec])
|
||||
AC_SEARCH_LIBS([yp_match], [sun ypsec])
|
||||
|
||||
# SysV needs -lsec, older versions of Linux need -lshadow for
|
||||
# shadow passwords. UnixWare 7 needs -lgen.
|
||||
AC_SEARCH_LIBS(getspnam, [shadow sec gen])
|
||||
AC_SEARCH_LIBS([getspnam], [shadow sec gen])
|
||||
|
||||
AC_CHECK_HEADERS(shadow.h)
|
||||
AC_CHECK_HEADERS([shadow.h])
|
||||
|
||||
# Requirements for su.c.
|
||||
shadow_includes="\
|
||||
@@ -47,14 +47,14 @@ $ac_includes_default
|
||||
#endif
|
||||
"
|
||||
AC_CHECK_MEMBERS([struct spwd.sp_pwdp],,,[$shadow_includes])
|
||||
AC_CHECK_FUNCS(getspnam)
|
||||
AC_CHECK_FUNCS([getspnam])
|
||||
|
||||
# SCO-ODT-3.0 is reported to need -lufc for crypt.
|
||||
# NetBSD needs -lcrypt for crypt.
|
||||
cu_saved_libs="$LIBS"
|
||||
AC_SEARCH_LIBS(crypt, [ufc crypt],
|
||||
AC_SEARCH_LIBS([crypt], [ufc crypt],
|
||||
[test "$ac_cv_search_crypt" = "none required" ||
|
||||
LIB_CRYPT="$ac_cv_search_crypt"])
|
||||
LIBS="$cu_saved_libs"
|
||||
AC_SUBST(LIB_CRYPT)
|
||||
AC_SUBST([LIB_CRYPT])
|
||||
])
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#serial 75
|
||||
#serial 76
|
||||
|
||||
dnl We use gl_ for non Autoconf macros.
|
||||
m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl
|
||||
@@ -7,7 +7,7 @@ m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl
|
||||
# directory of the coreutils package.
|
||||
|
||||
|
||||
# Copyright (C) 1998, 2000, 2001, 2003-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1998, 2000, 2001, 2003-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -38,6 +38,7 @@ AC_DEFUN([gl_PREREQ],
|
||||
# handles that; see ../bootstrap.conf.
|
||||
AC_REQUIRE([gl_EUIDACCESS_STAT])
|
||||
AC_REQUIRE([gl_FD_REOPEN])
|
||||
AC_REQUIRE([gl_FUNC_XATTR])
|
||||
AC_REQUIRE([gl_FUNC_XFTS])
|
||||
AC_REQUIRE([gl_MEMXFRM])
|
||||
AC_REQUIRE([gl_STRINTCMP])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# stat-prog.m4 serial 5
|
||||
# stat-prog.m4 serial 6
|
||||
# Record the prerequisites of src/stat.c from the coreutils package.
|
||||
|
||||
# Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2002-2004, 2006, 2008 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -68,7 +68,7 @@ AC_INCLUDES_DEFAULT
|
||||
[$statvfs_includes],
|
||||
[static statvfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[AC_DEFINE([STRUCT_STATVFS_F_FSID_IS_INTEGER], 1,
|
||||
[AC_DEFINE([STRUCT_STATVFS_F_FSID_IS_INTEGER], [1],
|
||||
[Define to 1 if the f_fsid member of struct statvfs is an integer.])])
|
||||
else
|
||||
AC_CHECK_MEMBERS([struct statfs.f_namelen, struct statfs.f_type],,,
|
||||
@@ -79,7 +79,7 @@ AC_INCLUDES_DEFAULT
|
||||
[$statfs_includes],
|
||||
[static statfs s;
|
||||
return (s.s_fsid ^ 0) == 0;])],
|
||||
[AC_DEFINE([STRUCT_STATFS_F_FSID_IS_INTEGER], 1,
|
||||
[AC_DEFINE([STRUCT_STATFS_F_FSID_IS_INTEGER], [1],
|
||||
[Define to 1 if the f_fsid member of struct statfs is an integer.])])
|
||||
fi
|
||||
fi
|
||||
|
||||
36
m4/xattr.m4
Normal file
36
m4/xattr.m4
Normal file
@@ -0,0 +1,36 @@
|
||||
# xattr.m4 - check for Extended Attributes (Linux)
|
||||
|
||||
# Copyright (C) 2003, 2008-2009 Free Software Foundation, Inc.
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# Originally written by Andreas Gruenbacher.
|
||||
# http://www.suse.de/~agruen/coreutils/5.91/coreutils-xattr.diff
|
||||
|
||||
AC_DEFUN([gl_FUNC_XATTR],
|
||||
[
|
||||
AC_ARG_ENABLE([xattr],
|
||||
AC_HELP_STRING([--disable-xattr],
|
||||
[do not support extended attributes]),
|
||||
[use_xattr=$enableval], [use_xattr=yes])
|
||||
|
||||
if test "$use_xattr" = "yes"; then
|
||||
AC_CHECK_HEADERS([attr/error_context.h attr/libattr.h])
|
||||
if test $ac_cv_header_attr_libattr_h = yes \
|
||||
&& test $ac_cv_header_attr_error_context_h = yes; then
|
||||
use_xattr=1
|
||||
else
|
||||
use_xattr=0
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([USE_XATTR], [$use_xattr],
|
||||
[Define if you want extended attribute support.])
|
||||
xattr_saved_LIBS=$LIBS
|
||||
AC_SEARCH_LIBS([attr_copy_file], [attr],
|
||||
[test "$ac_cv_search_attr_copy_file" = "none required" ||
|
||||
LIB_XATTR=$ac_cv_search_attr_copy_file])
|
||||
AC_CHECK_FUNCS([attr_copy_file])
|
||||
LIBS=$xattr_saved_LIBS
|
||||
AC_SUBST([LIB_XATTR])
|
||||
fi
|
||||
])
|
||||
413
maint.mk
413
maint.mk
@@ -2,7 +2,7 @@
|
||||
# This Makefile fragment tries to be general-purpose enough to be
|
||||
# used by at least coreutils, idutils, CPPI, Bison, and Autoconf.
|
||||
|
||||
## Copyright (C) 2001-2008 Free Software Foundation, Inc.
|
||||
## Copyright (C) 2001-2009 Free Software Foundation, Inc.
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
@@ -62,24 +62,25 @@ release_archive_dir ?= ../release
|
||||
# Doing it here saves us from having to set LC_ALL elsewhere in this file.
|
||||
export LC_ALL = C
|
||||
|
||||
|
||||
|
||||
## --------------- ##
|
||||
## Sanity checks. ##
|
||||
## --------------- ##
|
||||
|
||||
# Collect the names of rules starting with `sc_'.
|
||||
syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
|
||||
$(srcdir)/$(ME))
|
||||
$(srcdir)/$(ME) $(srcdir)/cfg.mk)
|
||||
.PHONY: $(syntax-check-rules)
|
||||
|
||||
local-checks-available = \
|
||||
po-check copyright-check m4-check author_mark_check \
|
||||
patch-check strftime-check $(syntax-check-rules) \
|
||||
makefile_path_separator_check \
|
||||
patch-check $(syntax-check-rules) \
|
||||
makefile-check check-AUTHORS
|
||||
.PHONY: $(local-checks-available)
|
||||
|
||||
# Arrange to print the name of each syntax-checking rule just before running it.
|
||||
$(syntax-check-rules): %: %.m
|
||||
$(patsubst %, %.m, $(syntax-check-rules)):
|
||||
@echo $(patsubst sc_%.m, %, $@)
|
||||
|
||||
local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available))
|
||||
|
||||
syntax-check: $(local-check)
|
||||
@@ -94,6 +95,21 @@ syntax-check: $(local-check)
|
||||
# exit 1; } || :
|
||||
# FIXME: don't allow `#include .strings\.h' anywhere
|
||||
|
||||
# By default, _prohibit_regexp does not ignore case.
|
||||
export ignore_case =
|
||||
_ignore_case = $$(test -n "$$ignore_case" && echo -i || :)
|
||||
|
||||
# There are many rules below that prohibit constructs in this package.
|
||||
# If the offending construct can be matched with a grep-E-style regexp,
|
||||
# use this macro. The shell variables "re" and "msg" must be defined.
|
||||
define _prohibit_regexp
|
||||
dummy=; : so we do not need a semicolon before each use \
|
||||
test "x$$re" != x || { echo '$(ME): re not defined' 1>&2; exit 1; }; \
|
||||
test "x$$msg" != x || { echo '$(ME): msg not defined' 1>&2; exit 1; };\
|
||||
grep $(_ignore_case) -nE "$$re" $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): '"$$msg" 1>&2; exit 1; } || :
|
||||
endef
|
||||
|
||||
sc_avoid_if_before_free:
|
||||
@$(srcdir)/build-aux/useless-if-before-free \
|
||||
$(useless_free_options) \
|
||||
@@ -102,37 +118,35 @@ sc_avoid_if_before_free:
|
||||
exit 1; } || :
|
||||
|
||||
sc_cast_of_argument_to_free:
|
||||
@grep -nE '\<free *\( *\(' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): don'\''t cast free argument' 1>&2; \
|
||||
exit 1; } || :
|
||||
@re='\<free *\( *\(' msg='don'\''t cast free argument' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
sc_cast_of_x_alloc_return_value:
|
||||
@grep -nE '\*\) *x(m|c|re)alloc\>' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
|
||||
exit 1; } || :
|
||||
@re='\*\) *x(m|c|re)alloc\>' \
|
||||
msg='don'\''t cast x*alloc return value' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
sc_cast_of_alloca_return_value:
|
||||
@grep -nE '\*\) *alloca\>' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): don'\''t cast alloca return value' 1>&2; \
|
||||
exit 1; } || :
|
||||
@re='\*\) *alloca\>' msg='don'\''t cast alloca return value' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
sc_space_tab:
|
||||
@grep -n '[ ] ' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
|
||||
1>&2; exit 1; } || :
|
||||
@re='[ ] ' msg='found SPACE-TAB sequence; remove the SPACE' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Don't use *scanf or the old ato* functions in `real' code.
|
||||
# They provide no error checking mechanism.
|
||||
# Instead, use strto* functions.
|
||||
sc_prohibit_atoi_atof:
|
||||
@grep -nE '\<([fs]?scanf|ato([filq]|ll))\>' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf' \
|
||||
1>&2; exit 1; } || :
|
||||
@re='\<([fs]?scanf|ato([filq]|ll)) *\(' \
|
||||
msg='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Use STREQ rather than comparing strcmp == 0, or != 0.
|
||||
sc_prohibit_strcmp:
|
||||
@grep -nE '! *str''cmp *\(|\<str''cmp *\([^)]+\) *==' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
$$($(VC_LIST_EXCEPT)) \
|
||||
| grep -vE ':# *define STREQ\(' && \
|
||||
{ echo '$(ME): use STREQ in place of the above uses of str''cmp' \
|
||||
1>&2; exit 1; } || :
|
||||
|
||||
@@ -168,13 +182,12 @@ sc_error_message_period:
|
||||
exit 1; } || :
|
||||
|
||||
sc_file_system:
|
||||
@grep -ni 'file''system' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found use of "file''system";' \
|
||||
'rewrite to use "file system"' 1>&2; \
|
||||
exit 1; } || :
|
||||
@re=file''system ignore_case=1 \
|
||||
msg='found use of "file''system"; spell it "file system"' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Don't use cpp tests of this symbol. All code assumes config.h is included.
|
||||
sc_no_have_config_h:
|
||||
sc_prohibit_have_config_h:
|
||||
@grep -n '^# *if.*HAVE''_CONFIG_H' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found use of HAVE''_CONFIG_H; remove' \
|
||||
1>&2; exit 1; } || :
|
||||
@@ -190,6 +203,25 @@ sc_require_config_h:
|
||||
else :; \
|
||||
fi
|
||||
|
||||
# You must include <config.h> before including any other header file.
|
||||
sc_require_config_h_first:
|
||||
@if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
|
||||
fail=0; \
|
||||
for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
|
||||
grep '^# *include\>' $$i | sed 1q \
|
||||
| grep '^# *include <config\.h>' > /dev/null \
|
||||
|| { echo $$i; fail=1; }; \
|
||||
done; \
|
||||
test $$fail = 1 && \
|
||||
{ echo '$(ME): the above files include some other header' \
|
||||
'before <config.h>' 1>&2; exit 1; } || :; \
|
||||
else :; \
|
||||
fi
|
||||
|
||||
sc_prohibit_HAVE_MBRTOWC:
|
||||
@re='\bHAVE_MBRTOWC\b' msg="do not use $$re; it is always defined" \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# To use this "command" macro, you must first define two shell variables:
|
||||
# h: the header, enclosed in <> or ""
|
||||
# re: a regular expression that matches IFF something provided by $h is used.
|
||||
@@ -251,11 +283,16 @@ sc_prohibit_root_dev_ino_without_use:
|
||||
re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
|
||||
$(_header_without_use)
|
||||
|
||||
# Prohibit the inclusion of c-ctype.h without an actual use.
|
||||
ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
|
||||
|isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
|
||||
sc_prohibit_c_ctype_without_use:
|
||||
@h='[<"]c-ctype.h[">]' re='\<c_($(ctype_re)) *\(' $(_header_without_use)
|
||||
|
||||
sc_obsolete_symbols:
|
||||
@grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
|
||||
1>&2; exit 1; } || :
|
||||
@re='\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
|
||||
msg='do not use HAVE''_FCNTL_H or O'_NDELAY \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
|
||||
|
||||
@@ -265,105 +302,6 @@ sc_changelog:
|
||||
{ echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
# Ensure that dd's definition of LONGEST_SYMBOL stays in sync
|
||||
# with the strings from the two affected variables.
|
||||
dd_c = $(srcdir)/src/dd.c
|
||||
sc_dd_max_sym_length:
|
||||
ifneq ($(wildcard $(dd_c)),)
|
||||
@len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
|
||||
sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
|
||||
|sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
|
||||
| wc --max-line-length); \
|
||||
max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
|
||||
|tr -d '"' | wc --max-line-length); \
|
||||
if test "$$len" = "$$max"; then :; else \
|
||||
echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
endif
|
||||
|
||||
# Many m4 macros names once began with `jm_'.
|
||||
# On 2004-04-13, they were all changed to start with gl_ instead.
|
||||
# Make sure that none are inadvertently reintroduced.
|
||||
sc_prohibit_jm_in_m4:
|
||||
@grep -nE 'jm_[A-Z]' \
|
||||
$$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
|
||||
{ echo '$(ME): do not use jm_ in m4 macro names' \
|
||||
1>&2; exit 1; } || :
|
||||
|
||||
# Ensure that each root-requiring test is run via the "check-root" rule.
|
||||
sc_root_tests:
|
||||
@if test -d tests \
|
||||
&& grep check-root tests/Makefile.am>/dev/null 2>&1; then \
|
||||
t1=sc-root.expected; t2=sc-root.actual; \
|
||||
grep -nl '^require_root_$$' \
|
||||
$$($(VC_LIST) tests) |sed s,tests/,, |sort > $$t1; \
|
||||
sed -n '/^root_tests =[ ]*\\$$/,/[^\]$$/p' \
|
||||
$(srcdir)/tests/Makefile.am \
|
||||
| sed 's/^ *//;/^root_tests =/d' \
|
||||
| tr -s '\012\\' ' ' | fmt -1 | sort > $$t2; \
|
||||
diff -u $$t1 $$t2 || diff=1; \
|
||||
rm -f $$t1 $$t2; \
|
||||
test "$$diff" \
|
||||
&& { echo 'tests/Makefile.am: missing check-root action'>&2; \
|
||||
exit 1; } || :; \
|
||||
fi
|
||||
|
||||
headers_with_interesting_macro_defs = \
|
||||
exit.h \
|
||||
fcntl_.h \
|
||||
fnmatch_.h \
|
||||
intprops.h \
|
||||
inttypes_.h \
|
||||
lchown.h \
|
||||
openat.h \
|
||||
stat-macros.h \
|
||||
stdint_.h
|
||||
|
||||
# Create a list of regular expressions matching the names
|
||||
# of macros that are guaranteed by parts of gnulib to be defined.
|
||||
.re-defmac:
|
||||
@(cd $(srcdir)/lib; \
|
||||
for f in $(headers_with_interesting_macro_defs); do \
|
||||
test -f $$f && \
|
||||
sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f; \
|
||||
done; \
|
||||
) | sort -u \
|
||||
| grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX' \
|
||||
| sed 's/^/^# *define /' \
|
||||
> $@-t
|
||||
@mv $@-t $@
|
||||
|
||||
# Don't define macros that we already get from gnulib header files.
|
||||
sc_always_defined_macros: .re-defmac
|
||||
@if test -f $(srcdir)/src/system.h; then \
|
||||
trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \
|
||||
grep -f .re-defmac $$($(VC_LIST)) \
|
||||
&& { echo '$(ME): define the above via some gnulib .h file' \
|
||||
1>&2; exit 1; } || :; \
|
||||
fi
|
||||
|
||||
# Create a list of regular expressions matching the names
|
||||
# of files included from system.h. Exclude a couple.
|
||||
.re-list:
|
||||
@sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
|
||||
| grep -Ev 'sys/(param|file)\.h' \
|
||||
| sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
|
||||
> $@-t
|
||||
@mv $@-t $@
|
||||
|
||||
# Files in src/ should not include directly any of
|
||||
# the headers already included via system.h.
|
||||
sc_system_h_headers: .re-list
|
||||
@if test -f $(srcdir)/src/system.h; then \
|
||||
trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
|
||||
grep -nE -f .re-list \
|
||||
$$($(VC_LIST) src | \
|
||||
grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
|
||||
&& { echo '$(ME): the above are already included via system.h'\
|
||||
1>&2; exit 1; } || :; \
|
||||
fi
|
||||
|
||||
# Ensure that each .c file containing a "main" function also
|
||||
# calls set_program_name.
|
||||
sc_program_name:
|
||||
@@ -383,34 +321,24 @@ sc_require_test_exit_idiom:
|
||||
@if test -f $(srcdir)/tests/test-lib.sh; then \
|
||||
die=0; \
|
||||
for i in $$(grep -l -F /../test-lib.sh $$($(VC_LIST) tests)); do \
|
||||
tail -n1 $$i | grep '^Exit \$$fail$$' > /dev/null \
|
||||
tail -n1 $$i | grep '^Exit \$$fail$$' > /dev/null \
|
||||
&& : || { die=1; echo $$i; } \
|
||||
done; \
|
||||
test $$die = 1 && \
|
||||
{ echo 1>&2 '$(ME): the final line in each of the above is not:'; \
|
||||
echo 1>&2 'Exit $$fail'; \
|
||||
echo 1>&2 'Exit $$fail'; \
|
||||
exit 1; } || :; \
|
||||
fi
|
||||
|
||||
sc_sun_os_names:
|
||||
@grep -nEi \
|
||||
'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
sc_the_the:
|
||||
@grep -ni '\<the ''the\>' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found use of "the ''the";' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
sc_tight_scope:
|
||||
$(MAKE) -C src $@
|
||||
@re='\<the ''the\>' \
|
||||
ignore_case=1 msg='found use of "the ''the";' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
sc_trailing_blank:
|
||||
@grep -n '[ ]$$' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): found trailing blank(s)' \
|
||||
1>&2; exit 1; } || :
|
||||
@re='[ ]$$' \
|
||||
ignore_case=1 msg='found trailing blank(s)' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Match lines like the following, but where there is only one space
|
||||
# between the options and the description:
|
||||
@@ -420,7 +348,7 @@ sc_two_space_separator_in_usage:
|
||||
@grep -nE '^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo "$(ME): help2man requires at least two spaces between"; \
|
||||
echo "$(ME): an option and its description"; \
|
||||
echo "$(ME): an option and its description"; \
|
||||
1>&2; exit 1; } || :
|
||||
|
||||
# Look for diagnostics that aren't marked for translation.
|
||||
@@ -441,30 +369,30 @@ sc_useless_cpp_parens:
|
||||
|
||||
# Require the latest GPL.
|
||||
sc_GPL_version:
|
||||
@grep -n 'either ''version [^3]' $$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo '$(ME): GPL vN, N!=3' 1>&2; exit 1; } || :
|
||||
@re='either ''version [^3]' msg='GPL vN, N!=3' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Perl-based tests used to exec perl from a #!/bin/sh script.
|
||||
# Now they all start with #!/usr/bin/perl and the portability
|
||||
# infrastructure is in tests/Makefile.am. Make sure no old-style
|
||||
# script sneaks back in.
|
||||
sc_no_exec_perl_coreutils:
|
||||
@if test -f $(srcdir)/tests/Coreutils.pm; then \
|
||||
grep '^exec *\$$PERL.*MCoreutils' $$($(VC_LIST) tests) && \
|
||||
{ echo 1>&2 '$(ME): found anachronistic Perl-based tests'; \
|
||||
exit 1; } || :; \
|
||||
fi
|
||||
cvs_keywords = \
|
||||
Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State
|
||||
|
||||
NEWS_hash = \
|
||||
$$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
|
||||
$(srcdir)/NEWS | md5sum -)
|
||||
sc_prohibit_cvs_keyword:
|
||||
@re='\$$($(cvs_keywords))\$$' \
|
||||
msg='do not use CVS keyword expansion' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Ensure that we don't accidentally insert an entry into an old NEWS block.
|
||||
sc_immutable_NEWS:
|
||||
@if test -f $(srcdir)/NEWS; then \
|
||||
test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \
|
||||
{ echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \
|
||||
fi
|
||||
# Make sure we don't use st_blocks. Use ST_NBLOCKS instead.
|
||||
# This is a bit of a kludge, since it prevents use of the string
|
||||
# even in comments, but for now it does the job with no false positives.
|
||||
sc_prohibit_stat_st_blocks:
|
||||
@re='[.>]st_blocks' msg='do not use st_blocks; use ST_NBLOCKS' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Make sure we don't define any S_IS* macros in src/*.c files.
|
||||
# They're already defined via gnulib's sys/stat.h replacement.
|
||||
sc_prohibit_S_IS_definition:
|
||||
@re='^ *# *define *S_IS' \
|
||||
msg='do not define S_IS* macros; include <sys/stat.h>' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Each program that uses proper_name_utf8 must link with
|
||||
# one of the ICONV libraries.
|
||||
@@ -486,10 +414,9 @@ sc_proper_name_utf8_requires_ICONV:
|
||||
# Warn about "c0nst struct Foo const foo[]",
|
||||
# but not about "char const *const foo" or "#define const const".
|
||||
sc_redundant_const:
|
||||
@grep -E '\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
|
||||
$$($(VC_LIST_EXCEPT)) && \
|
||||
{ echo 1>&2 '$(ME): redundant "const" in declarations'; \
|
||||
exit 1; } || :
|
||||
@re='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
|
||||
msg='redundant "const" in declarations' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
sc_const_long_option:
|
||||
@grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \
|
||||
@@ -497,6 +424,17 @@ sc_const_long_option:
|
||||
echo 1>&2 '$(ME): add "const" to the above declarations'; \
|
||||
exit 1; } || :
|
||||
|
||||
NEWS_hash = \
|
||||
$$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
|
||||
$(srcdir)/NEWS | grep -v '^Copyright .*Free Software' | md5sum -)
|
||||
|
||||
# Ensure that we don't accidentally insert an entry into an old NEWS block.
|
||||
sc_immutable_NEWS:
|
||||
@if test -f $(srcdir)/NEWS; then \
|
||||
test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \
|
||||
{ echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \
|
||||
fi
|
||||
|
||||
# Update the hash stored above. Do this after each release and
|
||||
# for any corrections to old entries.
|
||||
update-NEWS-hash: NEWS
|
||||
@@ -529,21 +467,6 @@ patch-check:
|
||||
test "$$msg" = ok && rm -rf src-c89 $@.1 $@.2 || echo "$$msg" 1>&2; \
|
||||
test "$$msg" = ok
|
||||
|
||||
# Ensure that date's --help output stays in sync with the info
|
||||
# documentation for GNU strftime. The only exception is %N,
|
||||
# which date accepts but GNU strftime does not.
|
||||
extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
|
||||
strftime-check:
|
||||
if test -f $(srcdir)/src/date.c; then \
|
||||
grep '^ %. ' $(srcdir)/src/date.c | sort \
|
||||
| $(extract_char) > $@-src; \
|
||||
{ echo N; \
|
||||
info libc date calendar format | grep '^ `%.'\' \
|
||||
| $(extract_char); } | sort > $@-info; \
|
||||
diff -u $@-src $@-info || exit 1; \
|
||||
rm -f $@-src $@-info; \
|
||||
fi
|
||||
|
||||
check-AUTHORS:
|
||||
$(MAKE) -C src $@
|
||||
|
||||
@@ -577,15 +500,21 @@ changelog-check:
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
m4-check:
|
||||
@grep -n 'AC_DEFUN([^[]' m4/*.m4 \
|
||||
&& { echo '$(ME): quote the first arg to AC_DEFUN' 1>&2; \
|
||||
sc_m4_quote_check:
|
||||
@grep -nE '(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \
|
||||
$$($(VC_LIST_EXCEPT) | grep -E '(^configure\.ac|\.m4)$$') \
|
||||
&& { echo '$(ME): quote the first arg to AC_DEF*' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
fix_po_file_diag = \
|
||||
'you have changed the set of files with translatable diagnostics;\n\
|
||||
apply the above patch\n'
|
||||
|
||||
# Verify that all source files using _() are listed in po/POTFILES.in.
|
||||
po-check:
|
||||
@if test -f po/POTFILES.in; then \
|
||||
grep -E -v '^(#|$$)' po/POTFILES.in \
|
||||
po_file = po/POTFILES.in
|
||||
sc_po_check:
|
||||
@if test -f $(po_file); then \
|
||||
grep -E -v '^(#|$$)' $(po_file) \
|
||||
| grep -v '^src/false\.c$$' | sort > $@-1; \
|
||||
files=; \
|
||||
for file in $$($(VC_LIST_EXCEPT)) lib/*.[ch]; do \
|
||||
@@ -602,18 +531,11 @@ po-check:
|
||||
done; \
|
||||
grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files \
|
||||
| sort -u > $@-2; \
|
||||
diff -u $@-1 $@-2 || exit 1; \
|
||||
diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
|
||||
|| { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
|
||||
rm -f $@-1 $@-2; \
|
||||
fi
|
||||
|
||||
# In a definition of #define AUTHORS "... and ..." where the RHS contains
|
||||
# the English word `and', the string must be marked with `N_ (...)' so that
|
||||
# gettext recognizes it as a string requiring translation.
|
||||
author_mark_check:
|
||||
@grep -n '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
|
||||
{ echo '$(ME): enclose the above strings in N_ (...)' 1>&2; \
|
||||
exit 1; } || :
|
||||
|
||||
# Sometimes it is useful to change the PATH environment variable
|
||||
# in Makefiles. When doing so, it's better not to use the Unix-centric
|
||||
# path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
|
||||
@@ -621,7 +543,7 @@ author_mark_check:
|
||||
# and there probably aren't many projects with so many Makefile.am files
|
||||
# that we'd have to worry about limits on command line length.
|
||||
msg = '$(ME): Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
|
||||
makefile_path_separator_check:
|
||||
sc_makefile_path_separator_check:
|
||||
@grep -n 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
|
||||
&& { echo $(msg) 1>&2; exit 1; } || :
|
||||
|
||||
@@ -642,24 +564,24 @@ sample-test = tests/sample-test
|
||||
texi = doc/$(PACKAGE).texi
|
||||
# Make sure that the copyright date in $(v_etc_file) is up to date.
|
||||
# Do the same for the $(sample-test) and the main doc/.texi file.
|
||||
copyright-check:
|
||||
@if test -f $(v_etc_file); then \
|
||||
sc_copyright_check:
|
||||
@if test -f $(v_etc_file); then \
|
||||
grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \
|
||||
>/dev/null \
|
||||
>/dev/null \
|
||||
|| { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
|
||||
exit 1; }; \
|
||||
exit 1; }; \
|
||||
fi
|
||||
@if test -f $(sample-test); then \
|
||||
grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \
|
||||
>/dev/null \
|
||||
@if test -f $(sample-test); then \
|
||||
grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \
|
||||
>/dev/null \
|
||||
|| { echo 'out of date copyright in $(sample-test); update it' 1>&2; \
|
||||
exit 1; }; \
|
||||
exit 1; }; \
|
||||
fi
|
||||
@if test -f $(texi); then \
|
||||
grep 'Copyright @copyright{} .*'$$(date +%Y)' Free' $(texi) \
|
||||
>/dev/null \
|
||||
|| { echo 'out of date copyright in $(texi); update it' 1>&2; \
|
||||
exit 1; }; \
|
||||
@if test -f $(texi); then \
|
||||
grep 'Copyright @copyright{} .*'$$(date +%Y)' Free' $(texi) \
|
||||
>/dev/null \
|
||||
|| { echo 'out of date copyright in $(texi); update it' 1>&2; \
|
||||
exit 1; }; \
|
||||
fi
|
||||
|
||||
vc-diff-check:
|
||||
@@ -737,12 +659,12 @@ taint-distcheck: $(DIST_ARCHIVES)
|
||||
|
||||
# Verify that a twisted use of --program-transform-name=PROGRAM works.
|
||||
define install-transform-check
|
||||
rm -rf $(pfx); \
|
||||
$(MAKE) program_transform_name='s/.*/zyx/' \
|
||||
echo running install-transform-check \
|
||||
&& rm -rf $(pfx) \
|
||||
&& $(MAKE) program_transform_name='s/.*/zyx/' \
|
||||
prefix=$(pfx) install \
|
||||
&& test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx" \
|
||||
&& test "$$(echo $(pfx)/share/man/man1/*)" = \
|
||||
"$(pfx)/share/man/man1/zyx.1"
|
||||
&& test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
|
||||
endef
|
||||
|
||||
# Install, then verify that all binaries and man pages are in place.
|
||||
@@ -764,6 +686,34 @@ define my-instcheck
|
||||
}
|
||||
endef
|
||||
|
||||
define coreutils-path-check
|
||||
{ \
|
||||
if test -f $(srcdir)/src/true.c; then \
|
||||
fail=1; \
|
||||
mkdir $(bin) \
|
||||
&& ($(write_loser)) > $(bin)/loser \
|
||||
&& chmod a+x $(bin)/loser \
|
||||
&& for i in $(built_programs); do \
|
||||
case $$i in \
|
||||
rm|expr|basename|echo|sort|ls|tr);; \
|
||||
cat|dirname|mv|wc);; \
|
||||
*) ln $(bin)/loser $(bin)/$$i;; \
|
||||
esac; \
|
||||
done \
|
||||
&& ln -sf ../src/true $(bin)/false \
|
||||
&& PATH=`pwd`/$(bin):$$PATH $(MAKE) -C tests check \
|
||||
&& { test -d gnulib-tests \
|
||||
&& $(MAKE) -C gnulib-tests check \
|
||||
|| :; } \
|
||||
&& rm -rf $(bin) \
|
||||
&& fail=0; \
|
||||
else \
|
||||
fail=0; \
|
||||
fi; \
|
||||
test $$fail = 1 && exit 1 || :; \
|
||||
}
|
||||
endef
|
||||
|
||||
# Use -Wformat -Werror to detect format-string/arg-list mismatches.
|
||||
# Also, check for shadowing problems with -Wshadow, and for pointer
|
||||
# arithmetic problems with -Wpointer-arith.
|
||||
@@ -789,22 +739,7 @@ my-distcheck: $(DIST_ARCHIVES) $(local-check)
|
||||
&& $(MAKE) dvi \
|
||||
&& $(install-transform-check) \
|
||||
&& $(my-instcheck) \
|
||||
&& mkdir $(bin) \
|
||||
&& ($(write_loser)) > $(bin)/loser \
|
||||
&& chmod a+x $(bin)/loser \
|
||||
&& for i in $(built_programs); do \
|
||||
case $$i in \
|
||||
rm|expr|basename|echo|sort|ls|tr);; \
|
||||
cat|dirname|mv|wc);; \
|
||||
*) ln $(bin)/loser $(bin)/$$i;; \
|
||||
esac; \
|
||||
done \
|
||||
&& ln -sf ../src/true $(bin)/false \
|
||||
&& PATH=`pwd`/$(bin):$$PATH $(MAKE) -C tests check \
|
||||
&& { test -d gnulib-tests \
|
||||
&& $(MAKE) -C gnulib-tests check \
|
||||
|| :; } \
|
||||
&& rm -rf $(bin) \
|
||||
&& $(coreutils-path-check) \
|
||||
&& $(MAKE) distclean
|
||||
(cd $(t) && mv $(distdir) $(distdir).old \
|
||||
&& $(AMTAR) -zxf - ) < $(distdir).tar.gz
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Make coreutils man pages. -*-Makefile-*-
|
||||
|
||||
# Copyright (C) 2002-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2002-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -132,6 +132,10 @@ who.1: $(common_dep) $(srcdir)/who.x ../src/who.c
|
||||
whoami.1: $(common_dep) $(srcdir)/whoami.x ../src/whoami.c
|
||||
yes.1: $(common_dep) $(srcdir)/yes.x ../src/yes.c
|
||||
|
||||
# This is required so that changes to e.g., emit_bug_reporting_address
|
||||
# provoke regeneration of all $(MAN) files.
|
||||
$(MAN): $(top_srcdir)/src/system.h
|
||||
|
||||
SUFFIXES = .x .1
|
||||
|
||||
# Ensure that help2man runs the ../src/ginstall binary as
|
||||
|
||||
2
man/du.x
2
man/du.x
@@ -19,7 +19,7 @@ will match any files whose names end in
|
||||
.BR .o .
|
||||
Therefore, the command
|
||||
.IP
|
||||
.B du --exclude='*.o'
|
||||
.B du --exclude=\(aq*.o\(aq
|
||||
.PP
|
||||
will skip all files and subdirectories ending in
|
||||
.BR .o
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
# Generate a short man page from --help and --version output.
|
||||
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008
|
||||
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008, 2009
|
||||
# Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -368,7 +368,7 @@ s/^\./\x80/mg;
|
||||
s/^'/\x81/mg;
|
||||
s/\\/\x82/g;
|
||||
|
||||
my $PAT_BUGS = _('Report +bugs|Email +bug +reports +to');
|
||||
my $PAT_BUGS = _('Report +(?:\w+ +)?bugs|Email +bug +reports +to');
|
||||
my $PAT_AUTHOR = _('Written +by');
|
||||
my $PAT_OPTIONS = _('Options');
|
||||
my $PAT_EXAMPLES = _('Examples');
|
||||
@@ -567,7 +567,7 @@ and
|
||||
.B %s
|
||||
programs are properly installed at your site, the command
|
||||
.IP
|
||||
.B info coreutils '%s invocation'
|
||||
.B info coreutils \(aq%s invocation\(aq
|
||||
.PP
|
||||
should give you access to the complete manual.
|
||||
EOT
|
||||
@@ -607,6 +607,9 @@ for my $sect (@pre, (grep ! /^($filter)$/o, @include), @post)
|
||||
# Convert some latin1 chars to troff equivalents
|
||||
s/\xa0/\\ /g; # non-breaking space
|
||||
|
||||
$sect eq 'REPORTING BUGS'
|
||||
and s/\n(.)/\n.br\n$1/g;
|
||||
|
||||
print;
|
||||
}
|
||||
}
|
||||
|
||||
2
man/id.x
2
man/id.x
@@ -1,4 +1,4 @@
|
||||
[NAME]
|
||||
id \- print user identity
|
||||
id \- print real and effective user and group IDs
|
||||
[DESCRIPTION]
|
||||
.\" Add any additional description here
|
||||
|
||||
@@ -753,7 +753,7 @@ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
|
||||
2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
any later version published by the Free Software Foundation; with no
|
||||
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||
Texts. A copy of the license is included in the ``GNU Free
|
||||
|
||||
@@ -277,7 +277,7 @@ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
|
||||
2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
any later version published by the Free Software Foundation; with no
|
||||
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||
Texts. A copy of the license is included in the ``GNU Free
|
||||
|
||||
@@ -465,7 +465,7 @@ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
|
||||
2001, 2002, 2006 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2 or
|
||||
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
any later version published by the Free Software Foundation; with no
|
||||
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||
Texts. A copy of the license is included in the ``GNU Free
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# List of files which contain translatable strings.
|
||||
# Copyright (C) 1996-2008 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2009 Free Software Foundation, Inc.
|
||||
|
||||
# These are nominally temporary...
|
||||
lib/argmatch.c
|
||||
@@ -22,8 +22,10 @@ lib/rpmatch.c
|
||||
lib/set-mode-acl.c
|
||||
lib/unicodeio.c
|
||||
lib/userspec.c
|
||||
lib/verror.c
|
||||
lib/version-etc.c
|
||||
lib/xalloc-die.c
|
||||
lib/xfreopen.c
|
||||
lib/xfts.c
|
||||
lib/xmemcoll.c
|
||||
lib/xmemxfrm.c
|
||||
@@ -61,6 +63,7 @@ src/factor.c
|
||||
src/false.c
|
||||
src/fmt.c
|
||||
src/fold.c
|
||||
src/getlimits.c
|
||||
src/group-list.c
|
||||
src/groups.c
|
||||
src/head.c
|
||||
|
||||
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@@ -31,6 +31,7 @@ false
|
||||
fmt
|
||||
fold
|
||||
fs.h
|
||||
getlimits
|
||||
ginstall
|
||||
groups
|
||||
head
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## Process this file with automake to produce Makefile.in -*-Makefile-*-
|
||||
|
||||
## Copyright (C) 1990, 1991, 1993-2008 Free Software Foundation, Inc.
|
||||
## Copyright (C) 1990, 1991, 1993-2009 Free Software Foundation, Inc.
|
||||
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,8 @@ no_install__progs = \
|
||||
build_if_possible__progs = \
|
||||
chroot df hostid nice pinky stty su uname uptime users who
|
||||
|
||||
AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
|
||||
|
||||
EXTRA_PROGRAMS = \
|
||||
$(no_install__progs) \
|
||||
$(build_if_possible__progs) \
|
||||
@@ -44,7 +46,7 @@ EXTRA_PROGRAMS = \
|
||||
|
||||
bin_PROGRAMS = $(OPTIONAL_BIN_PROGS)
|
||||
|
||||
noinst_PROGRAMS = setuidgid
|
||||
noinst_PROGRAMS = setuidgid getlimits
|
||||
|
||||
noinst_HEADERS = \
|
||||
chown-core.h \
|
||||
@@ -82,6 +84,7 @@ LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
|
||||
cat_LDADD = $(LDADD)
|
||||
df_LDADD = $(LDADD)
|
||||
du_LDADD = $(LDADD)
|
||||
getlimits_LDADD = $(LDADD)
|
||||
ptx_LDADD = $(LDADD)
|
||||
split_LDADD = $(LDADD)
|
||||
timeout_LDADD = $(LDADD)
|
||||
@@ -149,9 +152,9 @@ su_LDADD = $(LDADD) $(LIB_CRYPT)
|
||||
dir_LDADD += $(LIB_ACL)
|
||||
ls_LDADD += $(LIB_ACL)
|
||||
vdir_LDADD += $(LIB_ACL)
|
||||
cp_LDADD += $(LIB_ACL)
|
||||
mv_LDADD += $(LIB_ACL)
|
||||
ginstall_LDADD += $(LIB_ACL)
|
||||
cp_LDADD += $(LIB_ACL) $(LIB_XATTR)
|
||||
mv_LDADD += $(LIB_ACL) $(LIB_XATTR)
|
||||
ginstall_LDADD += $(LIB_ACL) $(LIB_XATTR)
|
||||
|
||||
stat_LDADD = $(LDADD) $(LIB_SELINUX)
|
||||
|
||||
@@ -160,11 +163,16 @@ cat_LDADD += $(LIBICONV)
|
||||
cp_LDADD += $(LIBICONV)
|
||||
df_LDADD += $(LIBICONV)
|
||||
du_LDADD += $(LIBICONV)
|
||||
getlimits_LDADD += $(LIBICONV)
|
||||
ptx_LDADD += $(LIBICONV)
|
||||
split_LDADD += $(LIBICONV)
|
||||
timeout_LDADD += $(LIBICONV)
|
||||
truncate_LDADD += $(LIBICONV)
|
||||
|
||||
# programs that use getaddrinfo (e.g., via canon_host)
|
||||
pinky_LDADD = $(LDADD) $(GETADDRINFO_LIB)
|
||||
who_LDADD = $(LDADD) $(GETADDRINFO_LIB)
|
||||
|
||||
$(PROGRAMS): ../lib/libcoreutils.a
|
||||
|
||||
# Get the release year from ../lib/version-etc.c.
|
||||
@@ -351,7 +359,7 @@ pm = progs-makefile
|
||||
pr = progs-readme
|
||||
# Ensure that the list of programs in README matches the list
|
||||
# of programs we can build.
|
||||
check: check-README check-misc check-duplicate-no-install
|
||||
check: check-README check-duplicate-no-install
|
||||
.PHONY: check-README
|
||||
check-README:
|
||||
rm -rf $(pr) $(pm)
|
||||
@@ -374,8 +382,8 @@ au_dotdot = authors-dotdot
|
||||
au_actual = authors-actual
|
||||
.PHONY: check-AUTHORS
|
||||
check-AUTHORS: $(all_programs)
|
||||
rm -f $(au_actual) $(au_dotdot)
|
||||
for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
|
||||
@rm -f $(au_actual) $(au_dotdot)
|
||||
@for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
|
||||
| $(ASSORT) -u`; do \
|
||||
test "$$i" = '[' && continue; \
|
||||
exe=$$i; \
|
||||
@@ -384,24 +392,12 @@ check-AUTHORS: $(all_programs)
|
||||
elif test "$$i" = test; then \
|
||||
exe='['; \
|
||||
fi; \
|
||||
LC_ALL=en_US.UTF-8 ./$$exe --version \
|
||||
LC_ALL=en_US.UTF-8 ./$$exe --version \
|
||||
| perl -0 -pi -e 's/,\n/, /gm' \
|
||||
|sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
|
||||
done > $(au_actual)
|
||||
sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
|
||||
diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
|
||||
|
||||
# Make sure we don't define any S_IS* macros in src/*.c files.
|
||||
# Not a big deal, but they're already defined via system.h.
|
||||
#
|
||||
# Also make sure we don't use st_blocks. Use ST_NBLOCKS instead.
|
||||
# This is a bit of a kludge, since it prevents use of the string
|
||||
# even in comments, but for now it does the job with no false positives.
|
||||
.PHONY: check-misc
|
||||
check-misc:
|
||||
cd $(srcdir); grep '^# *define *S_IS' $(SOURCES) && exit 1 || :
|
||||
cd $(srcdir); grep st_blocks $(SOURCES) && exit 1 || :
|
||||
cd $(srcdir); grep '^# *define .*defined' $(SOURCES) && exit 1 || :
|
||||
@sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
|
||||
@diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
|
||||
|
||||
# Extract the list of authors from each file.
|
||||
sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
|
||||
|
||||
@@ -48,7 +48,7 @@ static struct option const long_options[] =
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
static void
|
||||
void
|
||||
usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "full-write.h"
|
||||
#include "quote.h"
|
||||
#include "safe-read.h"
|
||||
#include "xfreopen.h"
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "cat"
|
||||
@@ -664,7 +665,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
file_open_mode |= O_BINARY;
|
||||
if (O_BINARY && ! isatty (STDOUT_FILENO))
|
||||
freopen (NULL, "wb", stdout);
|
||||
xfreopen (NULL, "wb", stdout);
|
||||
}
|
||||
|
||||
/* Check if any of the input files are the same as the output file. */
|
||||
@@ -684,7 +685,7 @@ main (int argc, char **argv)
|
||||
have_read_stdin = true;
|
||||
input_desc = STDIN_FILENO;
|
||||
if ((file_open_mode & O_BINARY) && ! isatty (STDIN_FILENO))
|
||||
freopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
23
src/chcon.c
23
src/chcon.c
@@ -35,26 +35,6 @@
|
||||
proper_name ("Russell Coker"), \
|
||||
proper_name ("Jim Meyering")
|
||||
|
||||
enum Change_status
|
||||
{
|
||||
CH_NOT_APPLIED,
|
||||
CH_SUCCEEDED,
|
||||
CH_FAILED,
|
||||
CH_NO_CHANGE_REQUESTED
|
||||
};
|
||||
|
||||
enum Verbosity
|
||||
{
|
||||
/* Print a message for each file that is processed. */
|
||||
V_high,
|
||||
|
||||
/* Print a message for each file whose attributes we change. */
|
||||
V_changes_only,
|
||||
|
||||
/* Do not be verbose. This is the default. */
|
||||
V_off
|
||||
};
|
||||
|
||||
/* If nonzero, and the systems has support for it, change the context
|
||||
of symbolic links rather than any files they point to. */
|
||||
static bool affect_symlink_referent;
|
||||
@@ -369,7 +349,6 @@ Usage: %s [OPTION]... CONTEXT FILE...\n\
|
||||
Change the security context of each FILE to CONTEXT.\n\
|
||||
With --reference, change the security context of each FILE to that of RFILE.\n\
|
||||
\n\
|
||||
-c, --changes like verbose but report only when a change is made\n\
|
||||
-h, --no-dereference affect symbolic links instead of any referenced file\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
@@ -430,7 +409,7 @@ main (int argc, char **argv)
|
||||
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "HLPRchvu:r:t:l:", long_options, NULL))
|
||||
while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:", long_options, NULL))
|
||||
!= -1)
|
||||
{
|
||||
switch (optc)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* chgrp -- change group ownership of files
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -302,6 +302,7 @@ main (int argc, char **argv)
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
bit_flags |= FTS_DEFER_STAT;
|
||||
ok = chown_files (argv + optind, bit_flags,
|
||||
(uid_t) -1, gid,
|
||||
(uid_t) -1, (gid_t) -1, &chopt);
|
||||
|
||||
29
src/chmod.c
29
src/chmod.c
@@ -1,5 +1,5 @@
|
||||
/* chmod -- change permission modes of files
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -67,7 +67,7 @@ static mode_t umask_value;
|
||||
/* If true, change the modes of directories recursively. */
|
||||
static bool recurse;
|
||||
|
||||
/* If true, force silence (no error messages). */
|
||||
/* If true, force silence (suppress most of error messages). */
|
||||
static bool force_silent;
|
||||
|
||||
/* If true, diagnose surprises from naive misuses like "chmod -r file".
|
||||
@@ -121,7 +121,7 @@ mode_changed (char const *file, mode_t old_mode, mode_t new_mode)
|
||||
|
||||
if (stat (file, &new_stats) != 0)
|
||||
{
|
||||
if (!force_silent)
|
||||
if (! force_silent)
|
||||
error (0, errno, _("getting new attributes of %s"), quote (file));
|
||||
return false;
|
||||
}
|
||||
@@ -203,24 +203,29 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
error (0, ent->fts_errno, _("cannot access %s"), quote (file_full_name));
|
||||
if (! force_silent)
|
||||
error (0, ent->fts_errno, _("cannot access %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_ERR:
|
||||
error (0, ent->fts_errno, _("%s"), quote (file_full_name));
|
||||
if (! force_silent)
|
||||
error (0, ent->fts_errno, _("%s"), quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_DNR:
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
if (! force_silent)
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_SLNONE:
|
||||
error (0, 0, _("cannot operate on dangling symlink %s"),
|
||||
quote (file_full_name));
|
||||
if (! force_silent)
|
||||
error (0, 0, _("cannot operate on dangling symlink %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
|
||||
default:
|
||||
@@ -319,7 +324,8 @@ process_files (char **files, int bit_flags)
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
if (! force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
@@ -528,7 +534,8 @@ main (int argc, char **argv)
|
||||
root_dev_ino = NULL;
|
||||
}
|
||||
|
||||
ok = process_files (argv + optind, FTS_COMFOLLOW | FTS_PHYSICAL);
|
||||
ok = process_files (argv + optind,
|
||||
FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
|
||||
|
||||
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -296,18 +296,22 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
fts_set (fts, ent, FTS_AGAIN);
|
||||
return true;
|
||||
}
|
||||
error (0, ent->fts_errno, _("cannot access %s"), quote (file_full_name));
|
||||
if (! chopt->force_silent)
|
||||
error (0, ent->fts_errno, _("cannot access %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_ERR:
|
||||
error (0, ent->fts_errno, _("%s"), quote (file_full_name));
|
||||
if (! chopt->force_silent)
|
||||
error (0, ent->fts_errno, _("%s"), quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
case FTS_DNR:
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
if (! chopt->force_silent)
|
||||
error (0, ent->fts_errno, _("cannot read directory %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
break;
|
||||
|
||||
@@ -338,8 +342,9 @@ change_file_owner (FTS *fts, FTSENT *ent,
|
||||
{
|
||||
if (fstatat (fts->fts_cwd_fd, file, &stat_buf, 0) != 0)
|
||||
{
|
||||
error (0, errno, _("cannot dereference %s"),
|
||||
quote (file_full_name));
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("cannot dereference %s"),
|
||||
quote (file_full_name));
|
||||
ok = false;
|
||||
}
|
||||
|
||||
@@ -492,7 +497,8 @@ chown_files (char **files, int bit_flags,
|
||||
if (errno != 0)
|
||||
{
|
||||
/* FIXME: try to give a better message */
|
||||
error (0, errno, _("fts_read failed"));
|
||||
if (! chopt->force_silent)
|
||||
error (0, errno, _("fts_read failed"));
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* chown -- change user and group ownership of files
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -312,7 +312,7 @@ main (int argc, char **argv)
|
||||
empty string so that diagnostics say "ownership :GROUP"
|
||||
rather than "group GROUP". */
|
||||
if (!chopt.user_name && chopt.group_name)
|
||||
chopt.user_name = "";
|
||||
chopt.user_name = bad_cast ("");
|
||||
|
||||
optind++;
|
||||
}
|
||||
@@ -326,6 +326,7 @@ main (int argc, char **argv)
|
||||
quote ("/"));
|
||||
}
|
||||
|
||||
bit_flags |= FTS_DEFER_STAT;
|
||||
ok = chown_files (argv + optind, bit_flags,
|
||||
uid, gid,
|
||||
required_uid, required_gid, &chopt);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* chroot -- run command or shell with special root directory
|
||||
Copyright (C) 95, 96, 1997, 1999-2004, 2007-2008
|
||||
Copyright (C) 95, 96, 1997, 1999-2004, 2007-2009
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -83,7 +83,8 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (chroot (argv[optind]) != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot change root directory to %s"), argv[1]);
|
||||
error (EXIT_FAILURE, errno, _("cannot change root directory to %s"),
|
||||
argv[optind]);
|
||||
|
||||
if (chdir ("/"))
|
||||
error (EXIT_FAILURE, errno, _("cannot chdir to root directory"));
|
||||
@@ -93,9 +94,9 @@ main (int argc, char **argv)
|
||||
/* No command. Run an interactive shell. */
|
||||
char *shell = getenv ("SHELL");
|
||||
if (shell == NULL)
|
||||
shell = "/bin/sh";
|
||||
shell = bad_cast ("/bin/sh");
|
||||
argv[0] = shell;
|
||||
argv[1] = "-i";
|
||||
argv[1] = bad_cast ("-i");
|
||||
argv[2] = NULL;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include "system.h"
|
||||
#include "xfreopen.h"
|
||||
|
||||
#ifdef CRCTAB
|
||||
|
||||
@@ -192,7 +193,7 @@ cksum (const char *file, bool print_name)
|
||||
fp = stdin;
|
||||
have_read_stdin = true;
|
||||
if (O_BINARY && ! isatty (STDIN_FILENO))
|
||||
freopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "system.h"
|
||||
#include "linebuffer.h"
|
||||
#include "error.h"
|
||||
#include "hard-locale.h"
|
||||
#include "quote.h"
|
||||
#include "stdio--.h"
|
||||
#include "xmemcoll.h"
|
||||
|
||||
157
src/copy.c
157
src/copy.c
@@ -1,5 +1,5 @@
|
||||
/* copy.c -- core functions for copying files and directories
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "buffer-lcm.h"
|
||||
#include "copy.h"
|
||||
#include "cp-hash.h"
|
||||
#include "euidaccess.h"
|
||||
#include "error.h"
|
||||
#include "fcntl--.h"
|
||||
#include "file-set.h"
|
||||
@@ -44,7 +43,7 @@
|
||||
#include "full-write.h"
|
||||
#include "hash.h"
|
||||
#include "hash-triple.h"
|
||||
#include "lchmod.h"
|
||||
#include "ignore-value.h"
|
||||
#include "quote.h"
|
||||
#include "same.h"
|
||||
#include "savedir.h"
|
||||
@@ -55,6 +54,13 @@
|
||||
#include "areadlink.h"
|
||||
#include "yesno.h"
|
||||
|
||||
#if USE_XATTR
|
||||
# include <attr/error_context.h>
|
||||
# include <attr/libattr.h>
|
||||
# include <stdarg.h>
|
||||
# include "verror.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FCHOWN
|
||||
# define HAVE_FCHOWN false
|
||||
# define fchown(fd, uid, gid) (-1)
|
||||
@@ -124,6 +130,72 @@ is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
|
||||
return false;
|
||||
}
|
||||
|
||||
#if USE_XATTR
|
||||
static void
|
||||
copy_attr_error (struct error_context *ctx ATTRIBUTE_UNUSED,
|
||||
char const *fmt, ...)
|
||||
{
|
||||
int err = errno;
|
||||
va_list ap;
|
||||
|
||||
/* use verror module to print error message */
|
||||
va_start (ap, fmt);
|
||||
verror (0, err, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
static char const *
|
||||
copy_attr_quote (struct error_context *ctx ATTRIBUTE_UNUSED, char const *str)
|
||||
{
|
||||
return quote (str);
|
||||
}
|
||||
|
||||
static void
|
||||
copy_attr_free (struct error_context *ctx ATTRIBUTE_UNUSED,
|
||||
char const *str ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
static bool
|
||||
copy_attr_by_fd (char const *src_path, int src_fd,
|
||||
char const *dst_path, int dst_fd)
|
||||
{
|
||||
struct error_context ctx =
|
||||
{
|
||||
.error = copy_attr_error,
|
||||
.quote = copy_attr_quote,
|
||||
.quote_free = copy_attr_free
|
||||
};
|
||||
return 0 == attr_copy_fd (src_path, src_fd, dst_path, dst_fd, 0, &ctx);
|
||||
}
|
||||
|
||||
static bool
|
||||
copy_attr_by_name (char const *src_path, char const *dst_path)
|
||||
{
|
||||
struct error_context ctx =
|
||||
{
|
||||
.error = copy_attr_error,
|
||||
.quote = copy_attr_quote,
|
||||
.quote_free = copy_attr_free
|
||||
};
|
||||
return 0 == attr_copy_file (src_path, dst_path, 0, &ctx);
|
||||
}
|
||||
#else /* USE_XATTR */
|
||||
|
||||
static bool
|
||||
copy_attr_by_fd (char const *src_path, int src_fd,
|
||||
char const *dst_path, int dst_fd)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
copy_attr_by_name (char const *src_path, char const *dst_path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif /* USE_XATTR */
|
||||
|
||||
/* Read the contents of the directory SRC_NAME_IN, and recursively
|
||||
copy the contents to DST_NAME_IN. NEW_DST is true if
|
||||
DST_NAME_IN is a directory that was created previously in the
|
||||
@@ -203,7 +275,7 @@ set_owner (const struct cp_options *x, char const *dst_name, int dest_desc,
|
||||
group. Avoid the window by first changing to a restrictive
|
||||
temporary mode if necessary. */
|
||||
|
||||
if (!new_dst & (x->preserve_mode | x->move_mode | x->set_mode))
|
||||
if (!new_dst && (x->preserve_mode | x->move_mode | x->set_mode))
|
||||
{
|
||||
mode_t old_mode = dst_sb->st_mode;
|
||||
mode_t new_mode =
|
||||
@@ -230,7 +302,7 @@ set_owner (const struct cp_options *x, char const *dst_name, int dest_desc,
|
||||
/* We've failed to set *both*. Now, try to set just the group
|
||||
ID, but ignore any failure here, and don't change errno. */
|
||||
int saved_errno = errno;
|
||||
(void) fchown (dest_desc, -1, gid);
|
||||
ignore_value (fchown (dest_desc, -1, gid));
|
||||
errno = saved_errno;
|
||||
}
|
||||
}
|
||||
@@ -243,7 +315,7 @@ set_owner (const struct cp_options *x, char const *dst_name, int dest_desc,
|
||||
/* We've failed to set *both*. Now, try to set just the group
|
||||
ID, but ignore any failure here, and don't change errno. */
|
||||
int saved_errno = errno;
|
||||
(void) lchown (dst_name, -1, gid);
|
||||
ignore_value (lchown (dst_name, -1, gid));
|
||||
errno = saved_errno;
|
||||
}
|
||||
}
|
||||
@@ -378,7 +450,8 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
security_context_t con = NULL;
|
||||
if (getfscreatecon (&con) < 0)
|
||||
{
|
||||
error (0, errno, _("failed to get file system create context"));
|
||||
if (!x->reduce_diagnostics)
|
||||
error (0, errno, _("failed to get file system create context"));
|
||||
if (x->require_preserve_context)
|
||||
{
|
||||
return_val = false;
|
||||
@@ -390,9 +463,10 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
{
|
||||
if (fsetfilecon (dest_desc, con) < 0)
|
||||
{
|
||||
error (0, errno,
|
||||
_("failed to set the security context of %s to %s"),
|
||||
quote_n (0, dst_name), quote_n (1, con));
|
||||
if (!x->reduce_diagnostics)
|
||||
error (0, errno,
|
||||
_("failed to set the security context of %s to %s"),
|
||||
quote_n (0, dst_name), quote_n (1, con));
|
||||
if (x->require_preserve_context)
|
||||
{
|
||||
return_val = false;
|
||||
@@ -400,7 +474,7 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
goto close_src_and_dst_desc;
|
||||
}
|
||||
}
|
||||
freecon(con);
|
||||
freecon (con);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +497,7 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
if (*new_dst)
|
||||
{
|
||||
int open_flags = O_WRONLY | O_CREAT | O_BINARY;
|
||||
dest_desc = open (dst_name, open_flags | O_EXCL ,
|
||||
dest_desc = open (dst_name, open_flags | O_EXCL,
|
||||
dst_mode & ~omitted_permissions);
|
||||
dest_errno = errno;
|
||||
|
||||
@@ -682,6 +756,11 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
|
||||
set_author (dst_name, dest_desc, src_sb);
|
||||
|
||||
if (x->preserve_xattr && ! copy_attr_by_fd (src_name, source_desc,
|
||||
dst_name, dest_desc)
|
||||
&& x->require_preserve_xattr)
|
||||
return false;
|
||||
|
||||
if (x->preserve_mode || x->move_mode)
|
||||
{
|
||||
if (copy_acl (src_name, source_desc, dst_name, dest_desc, src_mode) != 0
|
||||
@@ -1412,6 +1491,10 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
we can arrange to create a hard link between the corresponding names
|
||||
in the destination tree.
|
||||
|
||||
When using the --link (-l) option, there is no need to take special
|
||||
measures, because (barring race conditions) files that are hard-linked
|
||||
in the source tree will also be hard-linked in the destination tree.
|
||||
|
||||
Sometimes, when preserving links, we have to record dev/ino even
|
||||
though st_nlink == 1:
|
||||
- when in move_mode, since we may be moving a group of N hard-linked
|
||||
@@ -1430,27 +1513,29 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
- likewise for -L except that it applies to all files, not just
|
||||
command line arguments.
|
||||
|
||||
Also record directory dev/ino when using --recursive. We'll use that
|
||||
info to detect this problem: cp -R dir dir. FIXME-maybe: ideally,
|
||||
directory info would be recorded in a separate hash table, since
|
||||
such entries are useful only while a single command line hierarchy
|
||||
is being copied -- so that separate table could be cleared between
|
||||
command line args. Using the same hash table to preserve hard
|
||||
links means that it may not be cleared. */
|
||||
Also, with --recursive, record dev/ino of each command-line directory.
|
||||
We'll use that info to detect this problem: cp -R dir dir. */
|
||||
|
||||
if (x->move_mode && src_sb.st_nlink == 1)
|
||||
{
|
||||
earlier_file = src_to_dest_lookup (src_sb.st_ino, src_sb.st_dev);
|
||||
}
|
||||
else if ((x->preserve_links
|
||||
&& (1 < src_sb.st_nlink
|
||||
|| (command_line_arg
|
||||
&& x->dereference == DEREF_COMMAND_LINE_ARGUMENTS)
|
||||
|| x->dereference == DEREF_ALWAYS))
|
||||
|| (x->recursive && S_ISDIR (src_mode)))
|
||||
else if (x->preserve_links
|
||||
&& !x->hard_link
|
||||
&& (1 < src_sb.st_nlink
|
||||
|| (command_line_arg
|
||||
&& x->dereference == DEREF_COMMAND_LINE_ARGUMENTS)
|
||||
|| x->dereference == DEREF_ALWAYS))
|
||||
{
|
||||
earlier_file = remember_copied (dst_name, src_sb.st_ino, src_sb.st_dev);
|
||||
}
|
||||
else if (x->recursive && S_ISDIR (src_mode))
|
||||
{
|
||||
if (command_line_arg)
|
||||
earlier_file = remember_copied (dst_name, src_sb.st_ino, src_sb.st_dev);
|
||||
else
|
||||
earlier_file = src_to_dest_lookup (src_sb.st_ino, src_sb.st_dev);
|
||||
}
|
||||
|
||||
/* Did we copy this inode somewhere else (in this command line argument)
|
||||
and therefore this is a second hard link to the inode? */
|
||||
@@ -1638,9 +1723,10 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
{
|
||||
if (setfscreatecon (con) < 0)
|
||||
{
|
||||
error (0, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (con));
|
||||
if (!x->reduce_diagnostics)
|
||||
error (0, errno,
|
||||
_("failed to set default file creation context to %s"),
|
||||
quote (con));
|
||||
if (x->require_preserve_context)
|
||||
{
|
||||
freecon (con);
|
||||
@@ -1653,9 +1739,10 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
{
|
||||
if (errno != ENOTSUP && errno != ENODATA)
|
||||
{
|
||||
error (0, errno,
|
||||
_("failed to get security context of %s"),
|
||||
quote (src_name));
|
||||
if (!x->reduce_diagnostics)
|
||||
error (0, errno,
|
||||
_("failed to get security context of %s"),
|
||||
quote (src_name));
|
||||
if (x->require_preserve_context)
|
||||
return false;
|
||||
}
|
||||
@@ -1731,8 +1818,8 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
/* Insert the created directory's inode and device
|
||||
numbers into the search structure, so that we can
|
||||
avoid copying it again. */
|
||||
|
||||
remember_copied (dst_name, dst_sb.st_ino, dst_sb.st_dev);
|
||||
if (!x->hard_link)
|
||||
remember_copied (dst_name, dst_sb.st_ino, dst_sb.st_dev);
|
||||
|
||||
if (x->verbose)
|
||||
emit_verbose (src_name, dst_name, NULL);
|
||||
@@ -1980,6 +2067,10 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
|
||||
set_author (dst_name, -1, &src_sb);
|
||||
|
||||
if (x->preserve_xattr && ! copy_attr_by_name (src_name, dst_name)
|
||||
&& x->require_preserve_xattr)
|
||||
return false;
|
||||
|
||||
if (x->preserve_mode || x->move_mode)
|
||||
{
|
||||
if (copy_acl (src_name, -1, dst_name, -1, src_mode) != 0
|
||||
|
||||
22
src/copy.h
22
src/copy.h
@@ -1,5 +1,5 @@
|
||||
/* core functions for copying files and directories
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
# include <stdbool.h>
|
||||
# include "hash.h"
|
||||
# include "lstat.h"
|
||||
|
||||
/* Control creation of sparse files (files with holes). */
|
||||
enum Sparse_type
|
||||
@@ -174,6 +173,25 @@ struct cp_options
|
||||
fail if it is unable to do so. */
|
||||
bool require_preserve_context;
|
||||
|
||||
/* If true, attempt to preserve extended attributes using libattr.
|
||||
Ignored if coreutils are compiled without xattr support. */
|
||||
bool preserve_xattr;
|
||||
|
||||
/* Useful only when preserve_xattr is true.
|
||||
If true, a failed attempt to preserve file's extended attributes
|
||||
propagates failure "out" to the caller. If false, a failure to
|
||||
preserve file's extended attributes does not change the invoking
|
||||
application's exit status. Give diagnostics for failed syscalls
|
||||
regardless of this setting. For example, with "cp --preserve=xattr"
|
||||
this flag is "true", while with "cp --preserve=all", it is false. */
|
||||
bool require_preserve_xattr;
|
||||
|
||||
/* Used as difference boolean between cp -a and cp -dR --preserve=all.
|
||||
If true, non-mandatory failure diagnostics are not displayed. This
|
||||
should prevent poluting cp -a output.
|
||||
*/
|
||||
bool reduce_diagnostics;
|
||||
|
||||
/* If true, copy directories recursively and copy special files
|
||||
as themselves rather than copying their contents. */
|
||||
bool recursive;
|
||||
|
||||
@@ -19,14 +19,11 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
|
||||
#include "same.h"
|
||||
#include "quote.h"
|
||||
#include "hash.h"
|
||||
#include "error.h"
|
||||
#include "cp-hash.h"
|
||||
|
||||
/* Use ST_DEV and ST_INO as the key, FILENAME as the value.
|
||||
@@ -97,24 +94,6 @@ forget_created (ino_t ino, dev_t dev)
|
||||
src_to_dest_free (ent);
|
||||
}
|
||||
|
||||
/* Add FILE to the list of files that we have created.
|
||||
Return true if successful. */
|
||||
|
||||
extern bool
|
||||
remember_created (char const *file)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat (file, &sb) < 0)
|
||||
{
|
||||
error (0, errno, "%s", quote (file));
|
||||
return false;
|
||||
}
|
||||
|
||||
remember_copied (file, sb.st_ino, sb.st_dev);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* If INO/DEV correspond to an already-copied source file, return the
|
||||
name of the corresponding destination file. Otherwise, return NULL. */
|
||||
|
||||
|
||||
@@ -2,5 +2,4 @@ void hash_init (void);
|
||||
void forget_all (void);
|
||||
void forget_created (ino_t ino, dev_t dev);
|
||||
char *remember_copied (const char *node, ino_t ino, dev_t dev);
|
||||
bool remember_created (char const *file);
|
||||
char *src_to_dest_lookup (ino_t ino, dev_t dev);
|
||||
|
||||
81
src/cp.c
81
src/cp.c
@@ -1,5 +1,5 @@
|
||||
/* cp.c -- file copying (main routines)
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "cp-hash.h"
|
||||
#include "error.h"
|
||||
#include "filenamecat.h"
|
||||
#include "lchmod.h"
|
||||
#include "ignore-value.h"
|
||||
#include "quote.h"
|
||||
#include "stat-time.h"
|
||||
#include "utimens.h"
|
||||
@@ -76,7 +76,6 @@ enum
|
||||
NO_PRESERVE_ATTRIBUTES_OPTION,
|
||||
PARENTS_OPTION,
|
||||
PRESERVE_ATTRIBUTES_OPTION,
|
||||
REPLY_OPTION,
|
||||
SPARSE_OPTION,
|
||||
STRIP_TRAILING_SLASHES_OPTION,
|
||||
UNLINK_DEST_BEFORE_OPENING
|
||||
@@ -108,18 +107,6 @@ static enum Sparse_type const sparse_type[] =
|
||||
};
|
||||
ARGMATCH_VERIFY (sparse_type_string, sparse_type);
|
||||
|
||||
/* Valid arguments to the `--reply' option. */
|
||||
static char const* const reply_args[] =
|
||||
{
|
||||
"yes", "no", "query", NULL
|
||||
};
|
||||
/* The values that correspond to the above strings. */
|
||||
static int const reply_vals[] =
|
||||
{
|
||||
I_ALWAYS_YES, I_ALWAYS_NO, I_ASK_USER
|
||||
};
|
||||
ARGMATCH_VERIFY (reply_args, reply_vals);
|
||||
|
||||
static struct option const long_opts[] =
|
||||
{
|
||||
{"archive", no_argument, NULL, 'a'},
|
||||
@@ -129,6 +116,7 @@ static struct option const long_opts[] =
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"interactive", no_argument, NULL, 'i'},
|
||||
{"link", no_argument, NULL, 'l'},
|
||||
{"no-clobber", no_argument, NULL, 'n'},
|
||||
{"no-dereference", no_argument, NULL, 'P'},
|
||||
{"no-preserve", required_argument, NULL, NO_PRESERVE_ATTRIBUTES_OPTION},
|
||||
{"no-target-directory", no_argument, NULL, 'T'},
|
||||
@@ -138,8 +126,6 @@ static struct option const long_opts[] =
|
||||
{"preserve", optional_argument, NULL, PRESERVE_ATTRIBUTES_OPTION},
|
||||
{"recursive", no_argument, NULL, 'R'},
|
||||
{"remove-destination", no_argument, NULL, UNLINK_DEST_BEFORE_OPENING},
|
||||
{"reply", required_argument, NULL, REPLY_OPTION}, /* Deprecated 2005-07-03,
|
||||
remove in 2008. */
|
||||
{"sparse", required_argument, NULL, SPARSE_OPTION},
|
||||
{"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
|
||||
{"suffix", required_argument, NULL, 'S'},
|
||||
@@ -174,7 +160,7 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\
|
||||
Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
-a, --archive same as -dpR\n\
|
||||
-a, --archive same as -dR --preserve=all\n\
|
||||
--backup[=CONTROL] make a backup of each existing destination file\n\
|
||||
-b like --backup but does not accept an argument\n\
|
||||
--copy-contents copy contents of special files when recursive\n\
|
||||
@@ -182,8 +168,10 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
-f, --force if an existing destination file cannot be\n\
|
||||
opened, remove it and try again\n\
|
||||
-i, --interactive prompt before overwrite\n\
|
||||
opened, remove it and try again (redundant if\n\
|
||||
the -n option is used)\n\
|
||||
-i, --interactive prompt before overwrite (overrides a previous -n\n\
|
||||
option)\n\
|
||||
-H follow command-line symbolic links in SOURCE\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
@@ -191,13 +179,16 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
-L, --dereference always follow symbolic links in SOURCE\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
-n, --no-clobber do not overwrite an existing file (overrides\n\
|
||||
a previous -i option)\n\
|
||||
-P, --no-dereference never follow symbolic links in SOURCE\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
-p same as --preserve=mode,ownership,timestamps\n\
|
||||
--preserve[=ATTR_LIST] preserve the specified attributes (default:\n\
|
||||
mode,ownership,timestamps), if possible\n\
|
||||
additional attributes: context, links, all\n\
|
||||
additional attributes: context, links, xattr,\n\
|
||||
all\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
--no-preserve=ATTR_LIST don't preserve the specified attributes\n\
|
||||
@@ -326,7 +317,7 @@ re_protect (char const *const_dst_name, size_t src_offset,
|
||||
}
|
||||
/* Failing to preserve ownership is OK. Still, try to preserve
|
||||
the group, but ignore the possible error. */
|
||||
(void) lchown (dst_name, -1, p->st.st_gid);
|
||||
ignore_value (lchown (dst_name, -1, p->st.st_gid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,6 +765,9 @@ cp_option_init (struct cp_options *x)
|
||||
x->preserve_timestamps = false;
|
||||
x->preserve_security_context = false;
|
||||
x->require_preserve_context = false;
|
||||
x->preserve_xattr = false;
|
||||
x->reduce_diagnostics = false;
|
||||
x->require_preserve_xattr = false;
|
||||
|
||||
x->require_preserve = false;
|
||||
x->recursive = false;
|
||||
@@ -810,18 +804,20 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
|
||||
PRESERVE_OWNERSHIP,
|
||||
PRESERVE_LINK,
|
||||
PRESERVE_CONTEXT,
|
||||
PRESERVE_XATTR,
|
||||
PRESERVE_ALL
|
||||
};
|
||||
static enum File_attribute const preserve_vals[] =
|
||||
{
|
||||
PRESERVE_MODE, PRESERVE_TIMESTAMPS,
|
||||
PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_ALL
|
||||
PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_XATTR,
|
||||
PRESERVE_ALL
|
||||
};
|
||||
/* Valid arguments to the `--preserve' option. */
|
||||
static char const* const preserve_args[] =
|
||||
{
|
||||
"mode", "timestamps",
|
||||
"ownership", "links", "context", "all", NULL
|
||||
"ownership", "links", "context", "xattr", "all", NULL
|
||||
};
|
||||
ARGMATCH_VERIFY (preserve_args, preserve_vals);
|
||||
|
||||
@@ -862,6 +858,11 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
|
||||
x->require_preserve_context = on_off;
|
||||
break;
|
||||
|
||||
case PRESERVE_XATTR:
|
||||
x->preserve_xattr = on_off;
|
||||
x->require_preserve_xattr = on_off;
|
||||
break;
|
||||
|
||||
case PRESERVE_ALL:
|
||||
x->preserve_mode = on_off;
|
||||
x->preserve_timestamps = on_off;
|
||||
@@ -869,6 +870,7 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
|
||||
x->preserve_links = on_off;
|
||||
if (selinux_enabled)
|
||||
x->preserve_security_context = on_off;
|
||||
x->preserve_xattr = on_off;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -909,7 +911,7 @@ main (int argc, char **argv)
|
||||
we'll actually use backup_suffix_string. */
|
||||
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
|
||||
|
||||
while ((c = getopt_long (argc, argv, "abdfHilLprst:uvxPRS:T",
|
||||
while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:T",
|
||||
long_opts, NULL))
|
||||
!= -1)
|
||||
{
|
||||
@@ -920,13 +922,16 @@ main (int argc, char **argv)
|
||||
sparse_type_string, sparse_type);
|
||||
break;
|
||||
|
||||
case 'a': /* Like -dpR. */
|
||||
case 'a': /* Like -dR --preserve=all with reduced failure diagnostics. */
|
||||
x.dereference = DEREF_NEVER;
|
||||
x.preserve_links = true;
|
||||
x.preserve_ownership = true;
|
||||
x.preserve_mode = true;
|
||||
x.preserve_timestamps = true;
|
||||
x.require_preserve = true;
|
||||
if (selinux_enabled)
|
||||
x.preserve_security_context = true;
|
||||
x.reduce_diagnostics = true;
|
||||
x.recursive = true;
|
||||
break;
|
||||
|
||||
@@ -965,6 +970,10 @@ main (int argc, char **argv)
|
||||
x.dereference = DEREF_ALWAYS;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
x.interactive = I_ALWAYS_NO;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
x.dereference = DEREF_NEVER;
|
||||
break;
|
||||
@@ -1001,13 +1010,6 @@ main (int argc, char **argv)
|
||||
x.recursive = true;
|
||||
break;
|
||||
|
||||
case REPLY_OPTION: /* Deprecated */
|
||||
x.interactive = XARGMATCH ("--reply", optarg,
|
||||
reply_args, reply_vals);
|
||||
error (0, 0,
|
||||
_("the --reply option is deprecated; use -i or -f instead"));
|
||||
break;
|
||||
|
||||
case UNLINK_DEST_BEFORE_OPENING:
|
||||
x.unlink_dest_before_opening = true;
|
||||
break;
|
||||
@@ -1072,6 +1074,13 @@ main (int argc, char **argv)
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (make_backups && x.interactive == I_ALWAYS_NO)
|
||||
{
|
||||
error (0, 0,
|
||||
_("options --backup and --no-clobber are mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (backup_suffix_string)
|
||||
simple_backup_suffix = xstrdup (backup_suffix_string);
|
||||
|
||||
@@ -1105,6 +1114,12 @@ main (int argc, char **argv)
|
||||
"without an SELinux-enabled kernel"));
|
||||
}
|
||||
|
||||
#if !USE_XATTR
|
||||
if (x.require_preserve_xattr)
|
||||
error (EXIT_FAILURE, 0, _("cannot preserve extended attributes, cp is "
|
||||
"built without xattr support"));
|
||||
#endif
|
||||
|
||||
/* Allocate space for remembering copied and created files. */
|
||||
|
||||
hash_init ();
|
||||
|
||||
30
src/csplit.c
30
src/csplit.c
@@ -34,17 +34,6 @@
|
||||
#include "stdio--.h"
|
||||
#include "xstrtol.h"
|
||||
|
||||
/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
|
||||
present. */
|
||||
#ifndef SA_NOCLDSTOP
|
||||
# define SA_NOCLDSTOP 0
|
||||
# define sigprocmask(How, Set, Oset) /* empty */
|
||||
# define sigset_t int
|
||||
# if ! HAVE_SIGINTERRUPT
|
||||
# define siginterrupt(sig, flag) /* empty */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "csplit"
|
||||
|
||||
@@ -238,12 +227,10 @@ xalloc_die (void)
|
||||
static void
|
||||
interrupt_handler (int sig)
|
||||
{
|
||||
if (! SA_NOCLDSTOP)
|
||||
signal (sig, SIG_IGN);
|
||||
|
||||
delete_all_files (true);
|
||||
|
||||
signal (sig, SIG_DFL);
|
||||
/* The signal has been reset to SIG_DFL, but blocked during this
|
||||
handler. Force the default action of this signal once the
|
||||
handler returns and the block is removed. */
|
||||
raise (sig);
|
||||
}
|
||||
|
||||
@@ -1421,7 +1408,6 @@ main (int argc, char **argv)
|
||||
};
|
||||
enum { nsigs = sizeof sig / sizeof sig[0] };
|
||||
|
||||
#if SA_NOCLDSTOP
|
||||
struct sigaction act;
|
||||
|
||||
sigemptyset (&caught_signals);
|
||||
@@ -1434,19 +1420,11 @@ main (int argc, char **argv)
|
||||
|
||||
act.sa_handler = interrupt_handler;
|
||||
act.sa_mask = caught_signals;
|
||||
act.sa_flags = 0;
|
||||
act.sa_flags = SA_NODEFER | SA_RESETHAND;
|
||||
|
||||
for (i = 0; i < nsigs; i++)
|
||||
if (sigismember (&caught_signals, sig[i]))
|
||||
sigaction (sig[i], &act, NULL);
|
||||
#else
|
||||
for (i = 0; i < nsigs; i++)
|
||||
if (signal (sig[i], SIG_IGN) != SIG_IGN)
|
||||
{
|
||||
signal (sig[i], interrupt_handler);
|
||||
siginterrupt (sig[i], 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
split_file ();
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
|
||||
#define AUTHORS proper_name ("David MacKenzie")
|
||||
|
||||
int putenv ();
|
||||
|
||||
static bool show_date (const char *format, struct timespec when);
|
||||
|
||||
enum Time_spec
|
||||
@@ -385,7 +383,7 @@ main (int argc, char **argv)
|
||||
/* POSIX says that `date -u' is equivalent to setting the TZ
|
||||
environment variable, so this option should do nothing other
|
||||
than setting TZ. */
|
||||
if (putenv ("TZ=UTC0") != 0)
|
||||
if (putenv (bad_cast ("TZ=UTC0")) != 0)
|
||||
xalloc_die ();
|
||||
TZSET;
|
||||
break;
|
||||
|
||||
111
src/dd.c
111
src/dd.c
@@ -1,5 +1,5 @@
|
||||
/* dd -- convert a file while copying it.
|
||||
Copyright (C) 85, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 85, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -66,6 +66,12 @@ static void process_signals (void);
|
||||
# define SIGINFO SIGUSR1
|
||||
#endif
|
||||
|
||||
/* This may belong in GNULIB's fcntl module instead.
|
||||
Define O_CIO to 0 if it is not supported by this OS. */
|
||||
#ifndef O_CIO
|
||||
# define O_CIO 0
|
||||
#endif
|
||||
|
||||
#if ! HAVE_FDATASYNC
|
||||
# define fdatasync(fd) (errno = ENOSYS, -1)
|
||||
#endif
|
||||
@@ -194,8 +200,7 @@ static bool input_seekable;
|
||||
static int input_seek_errno;
|
||||
|
||||
/* File offset of the input, in bytes, along with a flag recording
|
||||
whether it overflowed. The offset is valid only if the input is
|
||||
seekable and if the offset has not overflowed. */
|
||||
whether it overflowed. */
|
||||
static uintmax_t input_offset;
|
||||
static bool input_offset_overflow;
|
||||
|
||||
@@ -264,6 +269,7 @@ enum
|
||||
/* Use a value that is larger than that of any other O_ symbol. */
|
||||
O_FULLBLOCK = ((MAX (O_APPEND,
|
||||
MAX (O_BINARY,
|
||||
MAX (O_CIO,
|
||||
MAX (O_DIRECT,
|
||||
MAX (O_DIRECTORY,
|
||||
MAX (O_DSYNC,
|
||||
@@ -272,7 +278,8 @@ enum
|
||||
MAX (O_NOFOLLOW,
|
||||
MAX (O_NOLINKS,
|
||||
MAX (O_NONBLOCK,
|
||||
MAX (O_SYNC, O_TEXT)))))))))))) << 1)
|
||||
MAX (O_SYNC,
|
||||
MAX (O_TEXT, 0)))))))))))))) << 1)
|
||||
};
|
||||
|
||||
/* Ensure that we didn't shift it off the end. */
|
||||
@@ -288,6 +295,7 @@ static struct symbol_value const flags[] =
|
||||
{
|
||||
{"append", O_APPEND},
|
||||
{"binary", O_BINARY},
|
||||
{"cio", O_CIO},
|
||||
{"direct", O_DIRECT},
|
||||
{"directory", O_DIRECTORY},
|
||||
{"dsync", O_DSYNC},
|
||||
@@ -455,16 +463,16 @@ Usage: %s [OPERAND]...\n\
|
||||
fputs (_("\
|
||||
Copy a file, converting and formatting according to the operands.\n\
|
||||
\n\
|
||||
bs=BYTES force ibs=BYTES and obs=BYTES\n\
|
||||
bs=BYTES read and write BYTES bytes at a time (also see ibs=,obs=)\n\
|
||||
cbs=BYTES convert BYTES bytes at a time\n\
|
||||
conv=CONVS convert the file as per the comma separated symbol list\n\
|
||||
count=BLOCKS copy only BLOCKS input blocks\n\
|
||||
ibs=BYTES read BYTES bytes at a time\n\
|
||||
ibs=BYTES read BYTES bytes at a time (default: 512)\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
if=FILE read from FILE instead of stdin\n\
|
||||
iflag=FLAGS read as per the comma separated symbol list\n\
|
||||
obs=BYTES write BYTES bytes at a time\n\
|
||||
obs=BYTES write BYTES bytes at a time (default: 512)\n\
|
||||
of=FILE write to FILE instead of stdout\n\
|
||||
oflag=FLAGS write as per the comma separated symbol list\n\
|
||||
seek=BLOCKS skip BLOCKS obs-sized blocks at start of output\n\
|
||||
@@ -508,6 +516,8 @@ Each FLAG symbol may be:\n\
|
||||
\n\
|
||||
append append mode (makes sense only for output; conv=notrunc suggested)\n\
|
||||
"), stdout);
|
||||
if (O_CIO)
|
||||
fputs (_(" cio use concurrent I/O for data\n"), stdout);
|
||||
if (O_DIRECT)
|
||||
fputs (_(" direct use direct I/O for data\n"), stdout);
|
||||
if (O_DIRECTORY)
|
||||
@@ -998,13 +1008,11 @@ scanargs (int argc, char *const *argv)
|
||||
{
|
||||
invalid |= ! (0 < n && n <= MAX_BLOCKSIZE (INPUT_BLOCK_SLOP));
|
||||
input_blocksize = n;
|
||||
conversions_mask |= C_TWOBUFS;
|
||||
}
|
||||
else if (operand_is (name, "obs"))
|
||||
{
|
||||
invalid |= ! (0 < n && n <= MAX_BLOCKSIZE (OUTPUT_BLOCK_SLOP));
|
||||
output_blocksize = n;
|
||||
conversions_mask |= C_TWOBUFS;
|
||||
}
|
||||
else if (operand_is (name, "bs"))
|
||||
{
|
||||
@@ -1035,12 +1043,13 @@ scanargs (int argc, char *const *argv)
|
||||
|
||||
if (blocksize)
|
||||
input_blocksize = output_blocksize = blocksize;
|
||||
else
|
||||
{
|
||||
/* POSIX says dd aggregates short reads into
|
||||
output_blocksize if bs= is not specified. */
|
||||
conversions_mask |= C_TWOBUFS;
|
||||
}
|
||||
|
||||
/* If bs= was given, both `input_blocksize' and `output_blocksize' will
|
||||
have been set to positive values. If either has not been set,
|
||||
bs= was not given, so make sure two buffers are used. */
|
||||
if (input_blocksize == 0 || output_blocksize == 0)
|
||||
conversions_mask |= C_TWOBUFS;
|
||||
if (input_blocksize == 0)
|
||||
input_blocksize = DEFAULT_BLOCKSIZE;
|
||||
if (output_blocksize == 0)
|
||||
@@ -1249,12 +1258,62 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize,
|
||||
&& 0 <= skip_via_lseek (file, fdesc, offset, SEEK_CUR))
|
||||
{
|
||||
if (fdesc == STDIN_FILENO)
|
||||
advance_input_offset (offset);
|
||||
return 0;
|
||||
{
|
||||
struct stat st;
|
||||
if (fstat (STDIN_FILENO, &st) != 0)
|
||||
error (EXIT_FAILURE, errno, _("cannot fstat %s"), quote (file));
|
||||
if (S_ISREG (st.st_mode) && st.st_size < (input_offset + offset))
|
||||
{
|
||||
/* When skipping past EOF, return the number of _full_ blocks
|
||||
* that are not skipped, and set offset to EOF, so the caller
|
||||
* can determine the requested skip was not satisfied. */
|
||||
records = ( offset - st.st_size ) / blocksize;
|
||||
offset = st.st_size - input_offset;
|
||||
}
|
||||
else
|
||||
records = 0;
|
||||
advance_input_offset (offset);
|
||||
}
|
||||
else
|
||||
records = 0;
|
||||
return records;
|
||||
}
|
||||
else
|
||||
{
|
||||
int lseek_errno = errno;
|
||||
off_t soffset;
|
||||
|
||||
/* The seek request may have failed above if it was too big
|
||||
(> device size, > max file size, etc.)
|
||||
Or it may not have been done at all (> OFF_T_MAX).
|
||||
Therefore try to seek to the end of the file,
|
||||
to avoid redundant reading. */
|
||||
if ((soffset = skip_via_lseek (file, fdesc, 0, SEEK_END)) >= 0)
|
||||
{
|
||||
/* File is seekable, and we're at the end of it, and
|
||||
size <= OFF_T_MAX. So there's no point using read to advance. */
|
||||
|
||||
if (!lseek_errno)
|
||||
{
|
||||
/* The original seek was not attempted as offset > OFF_T_MAX.
|
||||
We should error for write as can't get to the desired
|
||||
location, even if OFF_T_MAX < max file size.
|
||||
For read we're not going to read any data anyway,
|
||||
so we should error for consistency.
|
||||
It would be nice to not error for /dev/{zero,null}
|
||||
for any offset, but that's not a significant issue. */
|
||||
lseek_errno = EOVERFLOW;
|
||||
}
|
||||
|
||||
if (fdesc == STDIN_FILENO)
|
||||
error (0, lseek_errno, _("%s: cannot skip"), quote (file));
|
||||
else
|
||||
error (0, lseek_errno, _("%s: cannot seek"), quote (file));
|
||||
/* If the file has a specific size and we've asked
|
||||
to skip/seek beyond the max allowable, then quit. */
|
||||
quit (EXIT_FAILURE);
|
||||
}
|
||||
/* else file_size && offset > OFF_T_MAX or file ! seekable */
|
||||
|
||||
do
|
||||
{
|
||||
@@ -1527,10 +1586,22 @@ dd_copy (void)
|
||||
|
||||
if (skip_records != 0)
|
||||
{
|
||||
skip (STDIN_FILENO, input_file, skip_records, input_blocksize, ibuf);
|
||||
uintmax_t us_bytes = input_offset + (skip_records * input_blocksize);
|
||||
uintmax_t us_blocks = skip (STDIN_FILENO, input_file,
|
||||
skip_records, input_blocksize, ibuf);
|
||||
us_bytes -= input_offset;
|
||||
|
||||
/* POSIX doesn't say what to do when dd detects it has been
|
||||
asked to skip past EOF, so I assume it's non-fatal if the
|
||||
call to 'skip' returns nonzero. FIXME: maybe give a warning. */
|
||||
asked to skip past EOF, so I assume it's non-fatal.
|
||||
There are 3 reasons why there might be unskipped blocks/bytes:
|
||||
1. file is too small
|
||||
2. pipe has not enough data
|
||||
3. short reads */
|
||||
if (us_blocks || (!input_offset_overflow && us_bytes))
|
||||
{
|
||||
error (0, 0,
|
||||
_("%s: cannot skip to specified offset"), quote (input_file));
|
||||
}
|
||||
}
|
||||
|
||||
if (seek_records != 0)
|
||||
@@ -1768,7 +1839,7 @@ main (int argc, char **argv)
|
||||
|
||||
offset = lseek (STDIN_FILENO, 0, SEEK_CUR);
|
||||
input_seekable = (0 <= offset);
|
||||
input_offset = offset;
|
||||
input_offset = MAX(0, offset);
|
||||
input_seek_errno = errno;
|
||||
|
||||
if (output_file == NULL)
|
||||
|
||||
@@ -63,14 +63,15 @@ static const char *const slack_codes[] =
|
||||
"SYMLINK", "ORPHAN", "MISSING", "FIFO", "PIPE", "SOCK", "BLK", "BLOCK",
|
||||
"CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
|
||||
"END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
|
||||
"OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY", NULL
|
||||
"OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",
|
||||
"HARDLINK", "CLRTOEOL", NULL
|
||||
};
|
||||
|
||||
static const char *const ls_codes[] =
|
||||
{
|
||||
"no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi",
|
||||
"so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",
|
||||
"su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", NULL
|
||||
"su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", "cl", NULL
|
||||
};
|
||||
#define array_len(Array) (sizeof (Array) / sizeof *(Array))
|
||||
verify (array_len (slack_codes) == array_len (ls_codes));
|
||||
|
||||
@@ -69,6 +69,7 @@ RESET 0 # reset to "normal" color
|
||||
DIR 01;34 # directory
|
||||
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
|
||||
# numerical value, the color is as for the file pointed to.)
|
||||
HARDLINK 44;37 # regular file with more than one link
|
||||
FIFO 40;33 # pipe
|
||||
SOCK 01;35 # socket
|
||||
DOOR 01;35 # door
|
||||
|
||||
172
src/du.c
172
src/du.c
@@ -1,5 +1,5 @@
|
||||
/* du -- summarize disk usage
|
||||
Copyright (C) 1988-1991, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1988-1991, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <assert.h>
|
||||
#include "system.h"
|
||||
#include "argmatch.h"
|
||||
#include "argv-iter.h"
|
||||
#include "error.h"
|
||||
#include "exclude.h"
|
||||
#include "fprintftime.h"
|
||||
@@ -37,7 +38,6 @@
|
||||
#include "human.h"
|
||||
#include "quote.h"
|
||||
#include "quotearg.h"
|
||||
#include "readtokens0.h"
|
||||
#include "same.h"
|
||||
#include "stat-time.h"
|
||||
#include "xfts.h"
|
||||
@@ -292,9 +292,9 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
--files0-from=F summarize disk usage of the NUL-terminated file\n\
|
||||
names specified in file F\n\
|
||||
-H like --si, but also evokes a warning; will soon\n\
|
||||
change to be equivalent to --dereference-args (-D)\n\
|
||||
names specified in file F;\n\
|
||||
If F is - then read names from standard input\n\
|
||||
-H equivalent to --dereference-args (-D)\n\
|
||||
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)\n\
|
||||
--si like -h, but use powers of 1000 not 1024\n\
|
||||
"), stdout);
|
||||
@@ -648,9 +648,6 @@ du_files (char **files, int bit_flags)
|
||||
fts_close (fts);
|
||||
}
|
||||
|
||||
if (print_grand_total)
|
||||
print_size (&tot_dui, _("total"));
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -659,13 +656,11 @@ main (int argc, char **argv)
|
||||
{
|
||||
char *cwd_only[2];
|
||||
bool max_depth_specified = false;
|
||||
char **files;
|
||||
bool ok = true;
|
||||
char *files_from = NULL;
|
||||
struct Tokens tok;
|
||||
|
||||
/* Bit flags that control how fts works. */
|
||||
int bit_flags = FTS_TIGHT_CYCLE_CHECK;
|
||||
int bit_flags = FTS_TIGHT_CYCLE_CHECK | FTS_DEFER_STAT;
|
||||
|
||||
/* Select one of the three FTS_ options that control if/when
|
||||
to follow a symlink. */
|
||||
@@ -674,7 +669,7 @@ main (int argc, char **argv)
|
||||
/* If true, display only a total for each argument. */
|
||||
bool opt_summarize_only = false;
|
||||
|
||||
cwd_only[0] = ".";
|
||||
cwd_only[0] = bad_cast (".");
|
||||
cwd_only[1] = NULL;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
@@ -733,11 +728,6 @@ main (int argc, char **argv)
|
||||
output_block_size = 1;
|
||||
break;
|
||||
|
||||
case 'H': /* FIXME: remove warning and move this "case 'H'" to
|
||||
precede --dereference-args in late 2006. */
|
||||
error (0, 0, _("WARNING: use --si, not -H; the meaning of the -H\
|
||||
option will soon\nchange to be the same as that of --dereference-args (-D)"));
|
||||
/* fall through */
|
||||
case HUMAN_SI_OPTION:
|
||||
human_output_opts = human_autoscale | human_SI;
|
||||
output_block_size = 1;
|
||||
@@ -766,7 +756,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
|
||||
case MEGABYTES_LONG_OPTION:
|
||||
case MEGABYTES_LONG_OPTION: /* FIXME: remove in 2009 */
|
||||
error (0, 0,
|
||||
_("the --megabytes option is deprecated; use -m instead"));
|
||||
/* fall through */
|
||||
@@ -796,7 +786,8 @@ main (int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
|
||||
case 'D': /* This will eventually be 'H' (-H), too. */
|
||||
case 'H': /* NOTE: before 2008-12, -H was equivalent to --si. */
|
||||
case 'D':
|
||||
symlink_deref_bits = FTS_COMFOLLOW | FTS_PHYSICAL;
|
||||
break;
|
||||
|
||||
@@ -925,6 +916,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
struct argv_iterator *ai;
|
||||
if (files_from)
|
||||
{
|
||||
/* When using --files0-from=F, you may not specify any files
|
||||
@@ -941,78 +933,96 @@ main (int argc, char **argv)
|
||||
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
|
||||
quote (files_from));
|
||||
|
||||
readtokens0_init (&tok);
|
||||
|
||||
if (! readtokens0 (stdin, &tok) || fclose (stdin) != 0)
|
||||
error (EXIT_FAILURE, 0, _("cannot read file names from %s"),
|
||||
quote (files_from));
|
||||
|
||||
files = tok.tok;
|
||||
ai = argv_iter_init_stream (stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
files = (optind < argc ? argv + optind : cwd_only);
|
||||
char **files = (optind < argc ? argv + optind : cwd_only);
|
||||
ai = argv_iter_init_argv (files);
|
||||
}
|
||||
|
||||
if (!ai)
|
||||
xalloc_die ();
|
||||
|
||||
/* Initialize the hash structure for inode numbers. */
|
||||
hash_init ();
|
||||
|
||||
/* Report and filter out any empty file names before invoking fts.
|
||||
This works around a glitch in fts, which fails immediately
|
||||
(without looking at the other file names) when given an empty
|
||||
file name. */
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t j;
|
||||
|
||||
for (j = 0; ; j++)
|
||||
{
|
||||
if (i != j)
|
||||
files[i] = files[j];
|
||||
|
||||
if ( ! files[i])
|
||||
break;
|
||||
|
||||
if (files_from && STREQ (files_from, "-") && STREQ (files[i], "-"))
|
||||
{
|
||||
/* Give a better diagnostic in an unusual case:
|
||||
printf - | du --files0-from=- */
|
||||
error (0, 0, _("when reading file names from stdin, "
|
||||
"no file name of %s allowed"),
|
||||
quote ("-"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (files[i][0])
|
||||
i++;
|
||||
else
|
||||
{
|
||||
/* Diagnose a zero-length file name. When it's one
|
||||
among many, knowing the record number may help. */
|
||||
if (files_from)
|
||||
{
|
||||
/* Using the standard `filename:line-number:' prefix here is
|
||||
not totally appropriate, since NUL is the separator, not NL,
|
||||
but it might be better than nothing. */
|
||||
unsigned long int file_number = j + 1;
|
||||
error (0, 0, "%s:%lu: %s", quotearg_colon (files_from),
|
||||
file_number, _("invalid zero-length file name"));
|
||||
}
|
||||
else
|
||||
error (0, 0, "%s", _("invalid zero-length file name"));
|
||||
}
|
||||
}
|
||||
|
||||
ok = (i == j);
|
||||
}
|
||||
|
||||
bit_flags |= symlink_deref_bits;
|
||||
ok &= du_files (files, bit_flags);
|
||||
static char *temp_argv[] = { NULL, NULL };
|
||||
|
||||
/* This isn't really necessary, but it does ensure we
|
||||
exercise this function. */
|
||||
if (files_from)
|
||||
readtokens0_free (&tok);
|
||||
while (true)
|
||||
{
|
||||
bool skip_file = false;
|
||||
enum argv_iter_err ai_err;
|
||||
char *file_name = argv_iter (ai, &ai_err);
|
||||
if (ai_err == AI_ERR_EOF)
|
||||
break;
|
||||
if (!file_name)
|
||||
{
|
||||
switch (ai_err)
|
||||
{
|
||||
case AI_ERR_READ:
|
||||
error (0, errno, _("%s: read error"), quote (files_from));
|
||||
skip_file = true;
|
||||
continue;
|
||||
|
||||
case AI_ERR_MEM:
|
||||
xalloc_die ();
|
||||
|
||||
default:
|
||||
assert (!"unexpected error code from argv_iter");
|
||||
}
|
||||
}
|
||||
if (files_from && STREQ (files_from, "-") && STREQ (file_name, "-"))
|
||||
{
|
||||
/* Give a better diagnostic in an unusual case:
|
||||
printf - | du --files0-from=- */
|
||||
error (0, 0, _("when reading file names from stdin, "
|
||||
"no file name of %s allowed"),
|
||||
quote (file_name));
|
||||
skip_file = true;
|
||||
}
|
||||
|
||||
/* Report and skip any empty file names before invoking fts.
|
||||
This works around a glitch in fts, which fails immediately
|
||||
(without looking at the other file names) when given an empty
|
||||
file name. */
|
||||
if (!file_name[0])
|
||||
{
|
||||
/* Diagnose a zero-length file name. When it's one
|
||||
among many, knowing the record number may help.
|
||||
FIXME: currently print the record number only with
|
||||
--files0-from=FILE. Maybe do it for argv, too? */
|
||||
if (files_from == NULL)
|
||||
error (0, 0, "%s", _("invalid zero-length file name"));
|
||||
else
|
||||
{
|
||||
/* Using the standard `filename:line-number:' prefix here is
|
||||
not totally appropriate, since NUL is the separator, not NL,
|
||||
but it might be better than nothing. */
|
||||
unsigned long int file_number = argv_iter_n_args (ai);
|
||||
error (0, 0, "%s:%lu: %s", quotearg_colon (files_from),
|
||||
file_number, _("invalid zero-length file name"));
|
||||
}
|
||||
skip_file = true;
|
||||
}
|
||||
|
||||
if (skip_file)
|
||||
ok = false;
|
||||
else
|
||||
{
|
||||
temp_argv[0] = file_name;
|
||||
ok &= du_files (temp_argv, bit_flags);
|
||||
}
|
||||
}
|
||||
|
||||
argv_iter_free (ai);
|
||||
|
||||
if (files_from && (ferror (stdin) || fclose (stdin) != 0))
|
||||
error (EXIT_FAILURE, 0, _("error reading %s"), quote (files_from));
|
||||
|
||||
if (print_grand_total)
|
||||
print_size (&tot_dui, _("total"));
|
||||
|
||||
hash_free (htab);
|
||||
|
||||
|
||||
25
src/echo.c
25
src/echo.c
@@ -1,5 +1,5 @@
|
||||
/* echo.c, derived from code echo.c in Bash.
|
||||
Copyright (C) 87,89, 1991-1997, 1999-2005, 2007-2008 Free Software
|
||||
Copyright (C) 87,89, 1991-1997, 1999-2005, 2007-2009 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
#include "long-options.h"
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "echo"
|
||||
@@ -41,7 +40,10 @@ usage (int status)
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... [STRING]...\n"), program_name);
|
||||
printf (_("\
|
||||
Usage: %s [SHORT-OPTION]... [STRING]...\n\
|
||||
or: %s LONG-OPTION\n\
|
||||
"), program_name, program_name);
|
||||
fputs (_("\
|
||||
Echo the STRING(s) to standard output.\n\
|
||||
\n\
|
||||
@@ -121,9 +123,20 @@ main (int argc, char **argv)
|
||||
|
||||
atexit (close_stdout);
|
||||
|
||||
if (allow_options)
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
/* We directly parse options, rather than use parse_long_options, in
|
||||
order to avoid accepting abbreviations. */
|
||||
if (allow_options && argc == 2)
|
||||
{
|
||||
if (STREQ (argv[1], "--help"))
|
||||
usage (EXIT_SUCCESS);
|
||||
|
||||
if (STREQ (argv[1], "--version"))
|
||||
{
|
||||
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
|
||||
(char *) NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
--argc;
|
||||
++argv;
|
||||
|
||||
@@ -91,8 +91,6 @@
|
||||
proper_name ("Richard Mlynarik"), \
|
||||
proper_name ("David MacKenzie")
|
||||
|
||||
int putenv ();
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static struct option const longopts[] =
|
||||
|
||||
@@ -76,7 +76,7 @@ static char **file_list;
|
||||
/* Default for `file_list' if no files are given on the command line. */
|
||||
static char *stdin_argv[] =
|
||||
{
|
||||
"-", NULL
|
||||
(char *) "-", NULL
|
||||
};
|
||||
|
||||
/* True if we have ever read standard input. */
|
||||
|
||||
715
src/expr.c
715
src/expr.c
@@ -33,20 +33,122 @@
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <regex.h>
|
||||
#if HAVE_GMP
|
||||
#include <gmp.h>
|
||||
#endif
|
||||
#include "error.h"
|
||||
#include "long-options.h"
|
||||
#include "quotearg.h"
|
||||
#include "strnumcmp.h"
|
||||
#include "xstrtol.h"
|
||||
|
||||
/* Various parts of this code assume size_t fits into unsigned long
|
||||
int, the widest unsigned type that GMP supports. */
|
||||
verify (SIZE_MAX <= ULONG_MAX);
|
||||
|
||||
static void integer_overflow (char) ATTRIBUTE_NORETURN;
|
||||
|
||||
#ifndef HAVE_GMP
|
||||
# define HAVE_GMP 0
|
||||
#endif
|
||||
|
||||
#if HAVE_GMP
|
||||
# include <gmp.h>
|
||||
#else
|
||||
/* Approximate gmp.h well enough for expr.c's purposes. */
|
||||
typedef intmax_t mpz_t[1];
|
||||
static void mpz_clear (mpz_t z) {}
|
||||
static void mpz_init_set_ui (mpz_t z, unsigned long int i) { z[0] = i; }
|
||||
static int
|
||||
mpz_init_set_str (mpz_t z, char *s, int base)
|
||||
{
|
||||
return xstrtoimax (s, NULL, base, z, NULL) == LONGINT_OK ? 0 : -1;
|
||||
}
|
||||
static void
|
||||
mpz_add (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
{
|
||||
intmax_t a = a0[0];
|
||||
intmax_t b = b0[0];
|
||||
intmax_t val = a + b;
|
||||
if ((val < a) != (b < 0))
|
||||
integer_overflow ('+');
|
||||
r[0] = val;
|
||||
}
|
||||
static void
|
||||
mpz_sub (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
{
|
||||
intmax_t a = a0[0];
|
||||
intmax_t b = b0[0];
|
||||
intmax_t val = a - b;
|
||||
if ((a < val) != (b < 0))
|
||||
integer_overflow ('-');
|
||||
r[0] = val;
|
||||
}
|
||||
static void
|
||||
mpz_mul (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
{
|
||||
intmax_t a = a0[0];
|
||||
intmax_t b = b0[0];
|
||||
intmax_t val = a * b;
|
||||
if (! (a == 0 || b == 0
|
||||
|| ((val < 0) == ((a < 0) ^ (b < 0)) && val / a == b)))
|
||||
integer_overflow ('*');
|
||||
r[0] = val;
|
||||
}
|
||||
static void
|
||||
mpz_tdiv_q (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
{
|
||||
intmax_t a = a0[0];
|
||||
intmax_t b = b0[0];
|
||||
|
||||
/* Some x86-style hosts raise an exception for INT_MIN / -1. */
|
||||
if (a < - INTMAX_MAX && b == -1)
|
||||
integer_overflow ('/');
|
||||
r[0] = a / b;
|
||||
}
|
||||
static void
|
||||
mpz_tdiv_r (mpz_t r, mpz_t a0, mpz_t b0)
|
||||
{
|
||||
intmax_t a = a0[0];
|
||||
intmax_t b = b0[0];
|
||||
|
||||
/* Some x86-style hosts raise an exception for INT_MIN % -1. */
|
||||
r[0] = a < - INTMAX_MAX && b == -1 ? 0 : a % b;
|
||||
}
|
||||
static char *
|
||||
mpz_get_str (char const *str, int base, mpz_t z)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (intmax_t)];
|
||||
return xstrdup (imaxtostr (z[0], buf));
|
||||
}
|
||||
static int
|
||||
mpz_sgn (mpz_t z)
|
||||
{
|
||||
return z[0] < 0 ? -1 : 0 < z[0];
|
||||
}
|
||||
static int
|
||||
mpz_fits_ulong_p (mpz_t z)
|
||||
{
|
||||
return 0 <= z[0] && z[0] <= ULONG_MAX;
|
||||
}
|
||||
static unsigned long int
|
||||
mpz_get_ui (mpz_t z)
|
||||
{
|
||||
return z[0];
|
||||
}
|
||||
static int
|
||||
mpz_out_str (FILE *stream, int base, mpz_t z)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (intmax_t)];
|
||||
return fputs (imaxtostr (z[0], buf), stream) != EOF;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "expr"
|
||||
|
||||
#define AUTHORS proper_name ("Mike Parker"), proper_name ("James Youngman")
|
||||
#define AUTHORS \
|
||||
proper_name ("Mike Parker"), \
|
||||
proper_name ("James Youngman"), \
|
||||
proper_name ("Paul Eggert")
|
||||
|
||||
/* Exit statuses. */
|
||||
enum
|
||||
@@ -61,14 +163,10 @@ enum
|
||||
EXPR_FAILURE
|
||||
};
|
||||
|
||||
/* The kinds of value we can have.
|
||||
In the comments below, a variable is described as "arithmetic" if
|
||||
it is either integer or mp_integer. Variables are of type mp_integer
|
||||
only if GNU MP is available, but the type designator is always defined. */
|
||||
/* The kinds of value we can have. */
|
||||
enum valtype
|
||||
{
|
||||
integer,
|
||||
mp_integer,
|
||||
string
|
||||
};
|
||||
typedef enum valtype TYPE;
|
||||
@@ -79,12 +177,7 @@ struct valinfo
|
||||
TYPE type; /* Which kind. */
|
||||
union
|
||||
{ /* The value itself. */
|
||||
/* We could use intmax_t but that would integrate less well with GMP,
|
||||
since GMP has mpz_set_si but no intmax_t equivalent. */
|
||||
signed long int i;
|
||||
#if HAVE_GMP
|
||||
mpz_t z;
|
||||
#endif
|
||||
mpz_t i;
|
||||
char *s;
|
||||
} u;
|
||||
};
|
||||
@@ -98,34 +191,6 @@ static bool nomoreargs (void);
|
||||
static bool null (VALUE *v);
|
||||
static void printv (VALUE *v);
|
||||
|
||||
/* Arithmetic is done in one of three modes.
|
||||
|
||||
The --bignum option forces all arithmetic to use bignums other than
|
||||
string indexing (mode==MP_ALWAYS). The --no-bignum option forces
|
||||
all arithmetic to use native types rather than bignums
|
||||
(mode==MP_NEVER).
|
||||
|
||||
The default mode is MP_AUTO if GMP is available and MP_NEVER if
|
||||
not. Most functions will process a bignum if one is found, but
|
||||
will not convert a native integer to a string if the mode is
|
||||
MP_NEVER. */
|
||||
enum arithmetic_mode
|
||||
{
|
||||
MP_NEVER, /* Never use bignums */
|
||||
#if HAVE_GMP
|
||||
MP_ALWAYS, /* Always use bignums. */
|
||||
MP_AUTO, /* Switch if result would otherwise overflow */
|
||||
#endif
|
||||
};
|
||||
static enum arithmetic_mode mode =
|
||||
#if HAVE_GMP
|
||||
MP_AUTO
|
||||
#else
|
||||
MP_NEVER
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
void
|
||||
usage (int status)
|
||||
{
|
||||
@@ -140,10 +205,6 @@ Usage: %s EXPRESSION\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
putchar ('\n');
|
||||
fputs (_("\
|
||||
--bignum always use arbitrary-precision arithmetic\n\
|
||||
--no-bignum always use single-precision arithmetic\n"),
|
||||
stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
fputs (_("\
|
||||
@@ -220,47 +281,23 @@ syntax_error (void)
|
||||
static void
|
||||
integer_overflow (char op)
|
||||
{
|
||||
error (EXPR_FAILURE, 0,
|
||||
_("arithmetic operation %c produced an out of range value, "
|
||||
"but arbitrary-precision arithmetic is not available"), op);
|
||||
}
|
||||
|
||||
static void die (int exit_status, int errno_val, char const *msg)
|
||||
ATTRIBUTE_NORETURN;
|
||||
static void
|
||||
die (int exit_status, int errno_val, char const *msg)
|
||||
{
|
||||
assert (exit_status != 0);
|
||||
error (exit_status, errno_val, "%s", msg);
|
||||
error (EXPR_FAILURE, ERANGE, "%c", op);
|
||||
abort (); /* notreached */
|
||||
}
|
||||
|
||||
static void die (int errno_val, char const *msg)
|
||||
ATTRIBUTE_NORETURN;
|
||||
static void
|
||||
string_too_long (void)
|
||||
die (int errno_val, char const *msg)
|
||||
{
|
||||
die (EXPR_FAILURE, ERANGE, _("string too long"));
|
||||
error (EXPR_FAILURE, errno_val, "%s", msg);
|
||||
abort (); /* notreached */
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
USE_BIGNUM = CHAR_MAX + 1,
|
||||
NO_USE_BIGNUM
|
||||
};
|
||||
|
||||
static struct option const long_options[] =
|
||||
{
|
||||
{"bignum", no_argument, NULL, USE_BIGNUM},
|
||||
{"no-bignum", no_argument, NULL, NO_USE_BIGNUM},
|
||||
{GETOPT_HELP_OPTION_DECL},
|
||||
{GETOPT_VERSION_OPTION_DECL},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
int c;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
set_program_name (argv[0]);
|
||||
@@ -271,49 +308,23 @@ main (int argc, char **argv)
|
||||
initialize_exit_failure (EXPR_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
/* The argument -0 should not result in an error message. */
|
||||
opterr = 0;
|
||||
|
||||
while ((c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
/* The above handles --help and --version.
|
||||
Since there is no other invocation of getopt, handle `--' here. */
|
||||
if (argc > 1 && STREQ (argv[1], "--"))
|
||||
{
|
||||
/* "expr -0" should interpret the -0 as an integer argument.
|
||||
arguments like --foo should also be interpreted as a string
|
||||
argument to be "evaluated".
|
||||
*/
|
||||
if ('?' == c)
|
||||
{
|
||||
--optind;
|
||||
break;
|
||||
}
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case USE_BIGNUM:
|
||||
#if HAVE_GMP
|
||||
mode = MP_ALWAYS;
|
||||
#else
|
||||
error (EXPR_FAILURE, 0,
|
||||
_("arbitrary-precision support is not available"));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NO_USE_BIGNUM:
|
||||
mode = MP_NEVER;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
}
|
||||
--argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
if (argc <= optind)
|
||||
if (argc <= 1)
|
||||
{
|
||||
error (0, 0, _("missing operand"));
|
||||
usage (EXPR_INVALID);
|
||||
}
|
||||
|
||||
args = argv + optind;
|
||||
args = argv + 1;
|
||||
|
||||
v = eval (true);
|
||||
if (!nomoreargs ())
|
||||
@@ -326,21 +337,11 @@ main (int argc, char **argv)
|
||||
/* Return a VALUE for I. */
|
||||
|
||||
static VALUE *
|
||||
int_value (long int i)
|
||||
int_value (unsigned long int i)
|
||||
{
|
||||
VALUE *v = xmalloc (sizeof *v);
|
||||
#if HAVE_GMP
|
||||
if (mode == MP_ALWAYS)
|
||||
{
|
||||
/* all integer values are handled as bignums. */
|
||||
mpz_init_set_si (v->u.z, i);
|
||||
v->type = mp_integer;
|
||||
return v;
|
||||
}
|
||||
#endif
|
||||
|
||||
v->type = integer;
|
||||
v->u.i = i;
|
||||
mpz_init_set_ui (v->u.i, i);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -355,42 +356,15 @@ str_value (char const *s)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
static VALUE *
|
||||
substr_value (char const *s, size_t len, size_t pos, size_t nchars_wanted)
|
||||
{
|
||||
if (pos >= len)
|
||||
return str_value ("");
|
||||
else
|
||||
{
|
||||
VALUE *v = xmalloc (sizeof *v);
|
||||
size_t vlen = MIN (nchars_wanted, len - pos + 1);
|
||||
char *vlim;
|
||||
v->type = string;
|
||||
v->u.s = xmalloc (vlen + 1);
|
||||
vlim = mempcpy (v->u.s, s + pos, vlen);
|
||||
*vlim = '\0';
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Free VALUE V, including structure components. */
|
||||
|
||||
static void
|
||||
freev (VALUE *v)
|
||||
{
|
||||
if (v->type == string)
|
||||
{
|
||||
free (v->u.s);
|
||||
}
|
||||
else if (v->type == mp_integer)
|
||||
{
|
||||
assert (mode != MP_NEVER);
|
||||
#if HAVE_GMP
|
||||
mpz_clear (v->u.z);
|
||||
#endif
|
||||
}
|
||||
free (v->u.s);
|
||||
else
|
||||
mpz_clear (v->u.i);
|
||||
free (v);
|
||||
}
|
||||
|
||||
@@ -402,21 +376,15 @@ printv (VALUE *v)
|
||||
switch (v->type)
|
||||
{
|
||||
case integer:
|
||||
printf ("%ld\n", v->u.i);
|
||||
mpz_out_str (stdout, 10, v->u.i);
|
||||
putchar ('\n');
|
||||
break;
|
||||
case string:
|
||||
puts (v->u.s);
|
||||
break;
|
||||
#if HAVE_GMP
|
||||
case mp_integer:
|
||||
mpz_out_str (stdout, 10, v->u.z);
|
||||
putchar ('\n');
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Return true if V is a null-string or zero-number. */
|
||||
@@ -427,11 +395,7 @@ null (VALUE *v)
|
||||
switch (v->type)
|
||||
{
|
||||
case integer:
|
||||
return v->u.i == 0;
|
||||
#if HAVE_GMP
|
||||
case mp_integer:
|
||||
return mpz_sgn (v->u.z) == 0;
|
||||
#endif
|
||||
return mpz_sgn (v->u.i) == 0;
|
||||
case string:
|
||||
{
|
||||
char const *cp = v->u.s;
|
||||
@@ -474,29 +438,16 @@ looks_like_integer (char const *cp)
|
||||
static void
|
||||
tostring (VALUE *v)
|
||||
{
|
||||
char buf[INT_BUFSIZE_BOUND (long int)];
|
||||
|
||||
switch (v->type)
|
||||
{
|
||||
case integer:
|
||||
snprintf (buf, sizeof buf, "%ld", v->u.i);
|
||||
v->u.s = xstrdup (buf);
|
||||
v->type = string;
|
||||
break;
|
||||
#if HAVE_GMP
|
||||
case mp_integer:
|
||||
{
|
||||
char *s = mpz_get_str (NULL, 10, v->u.z);
|
||||
if (!s)
|
||||
{
|
||||
xalloc_die ();
|
||||
}
|
||||
mpz_clear (v->u.z);
|
||||
char *s = mpz_get_str (NULL, 10, v->u.i);
|
||||
mpz_clear (v->u.i);
|
||||
v->u.s = s;
|
||||
v->type = string;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case string:
|
||||
break;
|
||||
default:
|
||||
@@ -504,8 +455,7 @@ tostring (VALUE *v)
|
||||
}
|
||||
}
|
||||
|
||||
/* Coerce V to an arithmetic value.
|
||||
Return true on success, false on failure. */
|
||||
/* Coerce V to an integer value. Return true on success, false on failure. */
|
||||
|
||||
static bool
|
||||
toarith (VALUE *v)
|
||||
@@ -513,40 +463,17 @@ toarith (VALUE *v)
|
||||
switch (v->type)
|
||||
{
|
||||
case integer:
|
||||
case mp_integer:
|
||||
return true;
|
||||
|
||||
case string:
|
||||
{
|
||||
long int value;
|
||||
char *s = v->u.s;
|
||||
|
||||
if (! looks_like_integer (v->u.s))
|
||||
if (! looks_like_integer (s))
|
||||
return false;
|
||||
if (xstrtol (v->u.s, NULL, 10, &value, NULL) != LONGINT_OK)
|
||||
{
|
||||
#if HAVE_GMP
|
||||
if (mode != MP_NEVER)
|
||||
{
|
||||
char *s = v->u.s;
|
||||
if (mpz_init_set_str (v->u.z, s, 10))
|
||||
abort (); /* Bug in looks_like_integer, perhaps. */
|
||||
v->type = mp_integer;
|
||||
free (s);
|
||||
}
|
||||
else
|
||||
{
|
||||
error (EXPR_FAILURE, ERANGE, "%s", v->u.s);
|
||||
}
|
||||
#else
|
||||
error (EXPR_FAILURE, ERANGE, "%s", v->u.s);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
free (v->u.s);
|
||||
v->u.i = value;
|
||||
v->type = integer;
|
||||
}
|
||||
if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
|
||||
error (EXPR_FAILURE, ERANGE, "%s", s);
|
||||
free (s);
|
||||
v->type = integer;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -554,58 +481,23 @@ toarith (VALUE *v)
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract a size_t value from a positive arithmetic value, V.
|
||||
The extracted value is stored in *VAL. */
|
||||
static bool
|
||||
getsize (const VALUE *v, size_t *val, bool *negative)
|
||||
/* Extract a size_t value from a integer value I.
|
||||
If the value is negative, return SIZE_MAX.
|
||||
If the value is too large, return SIZE_MAX - 1. */
|
||||
static size_t
|
||||
getsize (mpz_t i)
|
||||
{
|
||||
if (v->type == integer)
|
||||
if (mpz_sgn (i) < 0)
|
||||
return SIZE_MAX;
|
||||
if (mpz_fits_ulong_p (i))
|
||||
{
|
||||
if (v->u.i < 0)
|
||||
{
|
||||
*negative = true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*negative = false;
|
||||
*val = v->u.i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (v->type == mp_integer)
|
||||
{
|
||||
#if HAVE_GMP
|
||||
if (mpz_sgn (v->u.z) < 0)
|
||||
{
|
||||
*negative = true;
|
||||
return false;
|
||||
}
|
||||
else if (mpz_fits_ulong_p (v->u.z))
|
||||
{
|
||||
unsigned long ul;
|
||||
ul = mpz_get_ui (v->u.z);
|
||||
*val = ul;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*negative = false;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
abort ();
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
abort (); /* should not pass a string. */
|
||||
unsigned long int ul = mpz_get_ui (i);
|
||||
if (ul < SIZE_MAX)
|
||||
return ul;
|
||||
}
|
||||
return SIZE_MAX - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Return true and advance if the next token matches STR exactly.
|
||||
STR must not be NULL. */
|
||||
|
||||
@@ -784,41 +676,14 @@ eval6 (bool evaluate)
|
||||
}
|
||||
else if (nextarg ("index"))
|
||||
{
|
||||
size_t pos, len;
|
||||
size_t pos;
|
||||
|
||||
l = eval6 (evaluate);
|
||||
r = eval6 (evaluate);
|
||||
tostring (l);
|
||||
tostring (r);
|
||||
pos = strcspn (l->u.s, r->u.s);
|
||||
len = strlen (l->u.s);
|
||||
if (pos == len)
|
||||
{
|
||||
v = int_value (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos < LONG_MAX)
|
||||
{
|
||||
v = int_value (pos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if HAVE_GMP
|
||||
if (mode != MP_NEVER
|
||||
&& pos < ULONG_MAX)
|
||||
{
|
||||
v = xmalloc (sizeof *v);
|
||||
mpz_init_set_ui (v->u.z, pos+1);
|
||||
v->type = mp_integer;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
string_too_long ();
|
||||
}
|
||||
}
|
||||
}
|
||||
v = int_value (l->u.s[pos] ? pos + 1 : 0);
|
||||
freev (l);
|
||||
freev (r);
|
||||
return v;
|
||||
@@ -836,25 +701,21 @@ eval6 (bool evaluate)
|
||||
v = str_value ("");
|
||||
else
|
||||
{
|
||||
size_t pos, len;
|
||||
bool negative = false;
|
||||
size_t pos = getsize (i1->u.i);
|
||||
size_t len = getsize (i2->u.i);
|
||||
|
||||
if (getsize (i1, &pos, &negative))
|
||||
if (getsize (i2, &len, &negative))
|
||||
if (pos == 0 || len == 0)
|
||||
v = str_value ("");
|
||||
else
|
||||
v = substr_value (l->u.s, llen, pos-1, len);
|
||||
else
|
||||
if (negative)
|
||||
v = str_value ("");
|
||||
else
|
||||
die (EXPR_FAILURE, ERANGE, _("string offset is too large"));
|
||||
if (llen < pos || pos == 0 || len == 0 || len == SIZE_MAX)
|
||||
v = str_value ("");
|
||||
else
|
||||
if (negative)
|
||||
v = str_value ("");
|
||||
else
|
||||
die (EXPR_FAILURE, ERANGE, _("substring length too large"));
|
||||
{
|
||||
size_t vlen = MIN (len, llen - pos + 1);
|
||||
char *vlim;
|
||||
v = xmalloc (sizeof *v);
|
||||
v->type = string;
|
||||
v->u.s = xmalloc (vlen + 1);
|
||||
vlim = mempcpy (v->u.s, l->u.s + pos - 1, vlen);
|
||||
*vlim = '\0';
|
||||
}
|
||||
}
|
||||
freev (l);
|
||||
freev (i1);
|
||||
@@ -897,170 +758,6 @@ eval5 (bool evaluate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if HAVE_GMP
|
||||
static void
|
||||
promote (VALUE *x)
|
||||
{
|
||||
if (x->type == integer)
|
||||
mpz_init_set_si (x->u.z, x->u.i);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* L = L * R. Both L and R are arithmetic. */
|
||||
static void
|
||||
domult (VALUE *l, VALUE *r)
|
||||
{
|
||||
if (l->type == integer && r->type == integer)
|
||||
{
|
||||
long int val = 0;
|
||||
val = l->u.i * r->u.i;
|
||||
if (! (l->u.i == 0 || r->u.i == 0
|
||||
|| ((val < 0) == ((l->u.i < 0) ^ (r->u.i < 0))
|
||||
&& val / l->u.i == r->u.i)))
|
||||
{
|
||||
/* Result would (did) overflow. Handle with MP if available. */
|
||||
if (mode != MP_NEVER)
|
||||
{
|
||||
#if HAVE_GMP
|
||||
mpz_init_set_si (l->u.z, l->u.i);
|
||||
mpz_mul_si (l->u.z, l->u.z, r->u.i); /* L*=R */
|
||||
l->type = mp_integer;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
integer_overflow ('*');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
l->u.i = val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* At least one operand is already mp_integer, so promote the other. */
|
||||
#if HAVE_GMP
|
||||
/* We could use mpz_mul_si here if R is not already mp_integer,
|
||||
but for the moment we'll try to minimise code paths. */
|
||||
if (l->type == integer)
|
||||
mpz_init_set_si (l->u.z, l->u.i);
|
||||
if (r->type == integer)
|
||||
mpz_init_set_si (r->u.z, r->u.i);
|
||||
l->type = r->type = mp_integer;
|
||||
mpz_mul (l->u.z, l->u.z, r->u.z); /* L*=R */
|
||||
#else
|
||||
abort ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* L = L / R or (if WANT_MODULUS) L = L % R */
|
||||
static void
|
||||
dodivide (VALUE *l, VALUE *r, bool want_modulus)
|
||||
{
|
||||
if (r->type == integer && r->u.i == 0)
|
||||
error (EXPR_INVALID, 0, _("division by zero"));
|
||||
#if HAVE_GMP
|
||||
if (r->type == mp_integer && mpz_sgn (r->u.z) == 0)
|
||||
error (EXPR_INVALID, 0, _("division by zero"));
|
||||
#endif
|
||||
if (l->type == integer && r->type == integer)
|
||||
{
|
||||
if (l->u.i < - INT_MAX && r->u.i == -1)
|
||||
{
|
||||
/* Some x86-style hosts raise an exception for
|
||||
INT_MIN / -1 and INT_MIN % -1, so handle these
|
||||
problematic cases specially. */
|
||||
if (want_modulus)
|
||||
{
|
||||
/* X mod -1 is zero for all negative X.
|
||||
Although strictly this is implementation-defined,
|
||||
we don't want to coredump, so we avoid the calculation. */
|
||||
l->u.i = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mode != MP_NEVER)
|
||||
{
|
||||
#if HAVE_GMP
|
||||
/* Handle the case by promoting. */
|
||||
mpz_init_set_si (l->u.z, l->u.i);
|
||||
l->type = mp_integer;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
integer_overflow ('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
l->u.i = want_modulus ? l->u.i % r->u.i : l->u.i / r->u.i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* If we get to here, at least one operand is mp_integer
|
||||
and R is not 0. */
|
||||
#if HAVE_GMP
|
||||
{
|
||||
int sign_l, sign_r;
|
||||
promote (l);
|
||||
promote (r);
|
||||
sign_l = mpz_sgn (l->u.z);
|
||||
sign_r = mpz_sgn (r->u.z);
|
||||
|
||||
if (!want_modulus)
|
||||
{
|
||||
if (!sign_l)
|
||||
{
|
||||
mpz_set_si (l->u.z, 0);
|
||||
}
|
||||
else if (sign_l < 0 || sign_r < 0)
|
||||
{
|
||||
/* At least one operand is negative. For integer arithmetic,
|
||||
it's platform-dependent if the operation rounds up or down.
|
||||
We mirror what the implementation does. */
|
||||
switch ((3*sign_l) / (2*sign_r))
|
||||
{
|
||||
case 2: /* round toward +inf. */
|
||||
case -1: /* round toward +inf. */
|
||||
mpz_cdiv_q (l->u.z, l->u.z, r->u.z);
|
||||
break;
|
||||
case -2: /* round toward -inf. */
|
||||
case 1: /* round toward -inf */
|
||||
mpz_fdiv_q (l->u.z, l->u.z, r->u.z);
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Both operands positive. Round toward -inf. */
|
||||
mpz_fdiv_q (l->u.z, l->u.z, r->u.z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mpz_mod (l->u.z, l->u.z, r->u.z); /* L = L % R */
|
||||
|
||||
/* If either operand is negative, it's platform-dependent if
|
||||
the remainer is positive or negative. We mirror what the
|
||||
implementation does. */
|
||||
if (sign_l % sign_r < 0)
|
||||
mpz_neg (l->u.z, l->u.z); /* L = (-L) */
|
||||
}
|
||||
}
|
||||
#else
|
||||
abort ();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Handle *, /, % operators. */
|
||||
|
||||
static VALUE *
|
||||
@@ -1089,71 +786,17 @@ eval4 (bool evaluate)
|
||||
{
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
switch (fxn)
|
||||
{
|
||||
case multiply:
|
||||
domult (l, r);
|
||||
break;
|
||||
case divide:
|
||||
case mod:
|
||||
dodivide (l, r, fxn==mod);
|
||||
break;
|
||||
}
|
||||
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
|
||||
error (EXPR_INVALID, 0, _("division by zero"));
|
||||
((fxn == multiply ? mpz_mul
|
||||
: fxn == divide ? mpz_tdiv_q
|
||||
: mpz_tdiv_r)
|
||||
(l->u.i, l->u.i, r->u.i));
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
}
|
||||
|
||||
/* L = L + R, or L = L - R */
|
||||
static void
|
||||
doadd (VALUE *l, VALUE *r, bool add)
|
||||
{
|
||||
long int val = 0;
|
||||
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
if (l->type == integer && r->type == integer)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
val = l->u.i + r->u.i;
|
||||
if ((val < l->u.i) == (r->u.i < 0))
|
||||
{
|
||||
l->u.i = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val = l->u.i - r->u.i;
|
||||
if ((l->u.i < val) == (r->u.i < 0))
|
||||
{
|
||||
l->u.i = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If we get to here, either the operation overflowed or at least
|
||||
one operand is an mp_integer. */
|
||||
if (mode != MP_NEVER)
|
||||
{
|
||||
#if HAVE_GMP
|
||||
promote (l);
|
||||
promote (r);
|
||||
if (add)
|
||||
mpz_add (l->u.z, l->u.z, r->u.z);
|
||||
else
|
||||
mpz_sub (l->u.z, l->u.z, r->u.z);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
integer_overflow ('-');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Handle +, - operators. */
|
||||
|
||||
static VALUE *
|
||||
@@ -1161,7 +804,7 @@ eval3 (bool evaluate)
|
||||
{
|
||||
VALUE *l;
|
||||
VALUE *r;
|
||||
bool add;
|
||||
enum { plus, minus } fxn;
|
||||
|
||||
#ifdef EVAL_TRACE
|
||||
trace ("eval3");
|
||||
@@ -1170,15 +813,17 @@ eval3 (bool evaluate)
|
||||
while (1)
|
||||
{
|
||||
if (nextarg ("+"))
|
||||
add = true;
|
||||
fxn = plus;
|
||||
else if (nextarg ("-"))
|
||||
add = false;
|
||||
fxn = minus;
|
||||
else
|
||||
return l;
|
||||
r = eval4 (evaluate);
|
||||
if (evaluate)
|
||||
{
|
||||
doadd (l, r, add);
|
||||
if (!toarith (l) || !toarith (r))
|
||||
error (EXPR_INVALID, 0, _("non-numeric argument"));
|
||||
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
|
||||
}
|
||||
freev (r);
|
||||
}
|
||||
|
||||
186
src/factor.c
186
src/factor.c
@@ -49,15 +49,6 @@
|
||||
|
||||
static bool verbose = false;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ALGO_AUTOSELECT, /* default */
|
||||
ALGO_GMP, /* --bignum */
|
||||
ALGO_SINGLE /* --no-bignum */
|
||||
} ALGORITHM_CHOICE;
|
||||
static ALGORITHM_CHOICE algorithm = ALGO_AUTOSELECT;
|
||||
|
||||
|
||||
#if HAVE_GMP
|
||||
static mpz_t *factor = NULL;
|
||||
static size_t nfactors_found = 0;
|
||||
@@ -91,6 +82,7 @@ emit_ul_factor (unsigned long int i)
|
||||
mpz_init (t);
|
||||
mpz_set_ui (t, i);
|
||||
emit_factor (t);
|
||||
mpz_clear (t);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -267,51 +259,13 @@ S4:
|
||||
mpz_clear (y);
|
||||
}
|
||||
|
||||
/* Arbitrary-precision factoring */
|
||||
static bool
|
||||
extract_factors_multi (char const *s)
|
||||
#else
|
||||
|
||||
static void
|
||||
debug (char const *fmt ATTRIBUTE_UNUSED, ...)
|
||||
{
|
||||
unsigned int division_limit;
|
||||
size_t n_bits;
|
||||
mpz_t t;
|
||||
|
||||
mpz_init (t);
|
||||
if (1 != gmp_sscanf (s, "%Zd", t))
|
||||
{
|
||||
error (0, 0, _("%s is not a valid positive integer"), quote (s));
|
||||
return false;
|
||||
}
|
||||
|
||||
printf ("%s:", s);
|
||||
|
||||
if (mpz_sgn (t) == 0)
|
||||
{
|
||||
mpz_clear (t);
|
||||
return true; /* 0; no factors */
|
||||
}
|
||||
|
||||
/* Set the trial division limit according to the size of t. */
|
||||
n_bits = mpz_sizeinbase (t, 2);
|
||||
division_limit = MIN (n_bits, 1000);
|
||||
division_limit *= division_limit;
|
||||
|
||||
factor_using_division (t, division_limit);
|
||||
|
||||
if (mpz_cmp_ui (t, 1) != 0)
|
||||
{
|
||||
debug ("[is number prime?] ");
|
||||
if (mpz_probab_prime_p (t, 3))
|
||||
{
|
||||
emit_factor (t);
|
||||
}
|
||||
else
|
||||
{
|
||||
factor_using_pollard_rho (t, 1);
|
||||
}
|
||||
}
|
||||
mpz_clear (t);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* The maximum number of factors, including -1, for negative numbers. */
|
||||
@@ -379,30 +333,18 @@ factor_wheel (uintmax_t n0, size_t max_n_factors, uintmax_t *factors)
|
||||
}
|
||||
|
||||
/* Single-precision factoring */
|
||||
static bool
|
||||
print_factors_single (char const *s)
|
||||
static void
|
||||
print_factors_single (uintmax_t n)
|
||||
{
|
||||
uintmax_t factors[MAX_N_FACTORS];
|
||||
uintmax_t n;
|
||||
size_t n_factors;
|
||||
size_t n_factors = factor_wheel (n, MAX_N_FACTORS, factors);
|
||||
size_t i;
|
||||
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
strtol_error err;
|
||||
|
||||
if ((err = xstrtoumax (s, NULL, 10, &n, "")) != LONGINT_OK)
|
||||
{
|
||||
if (err == LONGINT_OVERFLOW)
|
||||
error (0, 0, _("%s is too large"), quote (s));
|
||||
else
|
||||
error (0, 0, _("%s is not a valid positive integer"), quote (s));
|
||||
return false;
|
||||
}
|
||||
n_factors = factor_wheel (n, MAX_N_FACTORS, factors);
|
||||
printf ("%s:", umaxtostr (n, buf));
|
||||
for (i = 0; i < n_factors; i++)
|
||||
printf (" %s", umaxtostr (factors[i], buf));
|
||||
putchar ('\n');
|
||||
return true;
|
||||
}
|
||||
|
||||
#if HAVE_GMP
|
||||
@@ -450,67 +392,93 @@ free_factors (void)
|
||||
nfactors_found = 0;
|
||||
}
|
||||
|
||||
/* Arbitrary-precision factoring */
|
||||
static void
|
||||
print_factors_multi (mpz_t t)
|
||||
{
|
||||
mpz_out_str (stdout, 10, t);
|
||||
putchar (':');
|
||||
|
||||
if (mpz_sgn (t) != 0)
|
||||
{
|
||||
/* Set the trial division limit according to the size of t. */
|
||||
size_t n_bits = mpz_sizeinbase (t, 2);
|
||||
unsigned int division_limit = MIN (n_bits, 1000);
|
||||
division_limit *= division_limit;
|
||||
|
||||
factor_using_division (t, division_limit);
|
||||
|
||||
if (mpz_cmp_ui (t, 1) != 0)
|
||||
{
|
||||
debug ("[is number prime?] ");
|
||||
if (mpz_probab_prime_p (t, 3))
|
||||
emit_factor (t);
|
||||
else
|
||||
factor_using_pollard_rho (t, 1);
|
||||
}
|
||||
}
|
||||
|
||||
mpz_clear (t);
|
||||
sort_and_print_factors ();
|
||||
free_factors ();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Emit the factors of the indicated number. If we have the option of using
|
||||
either algorithm, we select on the basis of the length of the number.
|
||||
For longer numbers, we prefer the MP algorithm even if the native algorithm
|
||||
has enough digits, because the algorithm is better. The turnover point
|
||||
depends on the value as well as the length, but since we don't already know
|
||||
if the number presented has small factors, we just switch over at 6 digits.
|
||||
*/
|
||||
has enough digits, because the algorithm is better. The turnover point
|
||||
depends on the value. */
|
||||
static bool
|
||||
print_factors (char const *s)
|
||||
{
|
||||
if (ALGO_AUTOSELECT == algorithm)
|
||||
uintmax_t n;
|
||||
strtol_error err = xstrtoumax (s, NULL, 10, &n, "");
|
||||
|
||||
#if HAVE_GMP
|
||||
enum { GMP_TURNOVER_POINT = 100000 };
|
||||
|
||||
if (err == LONGINT_OVERFLOW
|
||||
|| (err == LONGINT_OK && GMP_TURNOVER_POINT <= n))
|
||||
{
|
||||
const size_t digits = strlen (s); /* upper limit on number of digits */
|
||||
algorithm = digits < 6 ? ALGO_SINGLE : ALGO_GMP;
|
||||
}
|
||||
if (ALGO_GMP == algorithm)
|
||||
{
|
||||
debug ("[%s]", _("using arbitrary-precision arithmetic"));
|
||||
if (extract_factors_multi (s))
|
||||
mpz_t t;
|
||||
mpz_init (t);
|
||||
if (gmp_sscanf (s, "%Zd", t) == 1)
|
||||
{
|
||||
sort_and_print_factors ();
|
||||
free_factors ();
|
||||
debug ("[%s]", _("using arbitrary-precision arithmetic"));
|
||||
print_factors_multi (t);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
err = LONGINT_INVALID;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case LONGINT_OK:
|
||||
debug ("[%s]", _("using single-precision arithmetic"));
|
||||
return print_factors_single (s);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static bool
|
||||
print_factors (const char *s) /* Single-precision only. */
|
||||
{
|
||||
if (ALGO_GMP == algorithm)
|
||||
{
|
||||
error (0, 0, _("arbitrary-precision arithmetic is not available"));
|
||||
print_factors_single (n);
|
||||
return true;
|
||||
|
||||
case LONGINT_OVERFLOW:
|
||||
error (0, 0, _("%s is too large"), quote (s));
|
||||
return false;
|
||||
|
||||
default:
|
||||
error (0, 0, _("%s is not a valid positive integer"), quote (s));
|
||||
return false;
|
||||
}
|
||||
return print_factors_single (s);
|
||||
}
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
VERBOSE_OPTION = CHAR_MAX + 1,
|
||||
USE_BIGNUM,
|
||||
NO_USE_BIGNUM
|
||||
VERBOSE_OPTION = CHAR_MAX + 1
|
||||
};
|
||||
|
||||
static struct option const long_options[] =
|
||||
{
|
||||
{"verbose", no_argument, NULL, VERBOSE_OPTION},
|
||||
{"bignum", no_argument, NULL, USE_BIGNUM},
|
||||
{"no-bignum", no_argument, NULL, NO_USE_BIGNUM},
|
||||
{GETOPT_HELP_OPTION_DECL},
|
||||
{GETOPT_VERSION_OPTION_DECL},
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -534,10 +502,6 @@ Print the prime factors of each specified integer NUMBER. If none\n\
|
||||
are specified on the command line, read them from standard input.\n\
|
||||
\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
--bignum always use arbitrary-precision arithmetic\n\
|
||||
--no-bignum always use single-precision arithmetic\n"),
|
||||
stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
emit_bug_reporting_address ();
|
||||
@@ -588,14 +552,6 @@ main (int argc, char **argv)
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case USE_BIGNUM:
|
||||
algorithm = ALGO_GMP;
|
||||
break;
|
||||
|
||||
case NO_USE_BIGNUM:
|
||||
algorithm = ALGO_SINGLE;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
180
src/getlimits.c
Normal file
180
src/getlimits.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/* getlimits - print various platform dependent limits.
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Pádraig Brady */
|
||||
|
||||
#include <config.h> /* sets _FILE_OFFSET_BITS=64 etc. */
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "c-ctype.h"
|
||||
#include "long-options.h"
|
||||
|
||||
#define PROGRAM_NAME "getlimits"
|
||||
|
||||
#define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
|
||||
|
||||
#ifndef TIME_T_MAX
|
||||
# define TIME_T_MAX TYPE_MAXIMUM (time_t)
|
||||
#endif
|
||||
|
||||
#ifndef TIME_T_MIN
|
||||
# define TIME_T_MIN TYPE_MINIMUM (time_t)
|
||||
#endif
|
||||
|
||||
#ifndef SSIZE_MIN
|
||||
# define SSIZE_MIN TYPE_MINIMUM (ssize_t)
|
||||
#endif
|
||||
|
||||
#ifndef PID_T_MIN
|
||||
# define PID_T_MIN TYPE_MINIMUM (pid_t)
|
||||
#endif
|
||||
|
||||
/* These are not interesting to print.
|
||||
* Instead of these defines it would be nice to be able to do
|
||||
* #ifdef (TYPE##_MIN) in function macro below. */
|
||||
#define SIZE_MIN 0
|
||||
#define UCHAR_MIN 0
|
||||
#define UINT_MIN 0
|
||||
#define ULONG_MIN 0
|
||||
#define UINTMAX_MIN 0
|
||||
#define UID_T_MIN 0
|
||||
#define GID_T_MIN 0
|
||||
|
||||
void
|
||||
usage (int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS)
|
||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
||||
program_name);
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s\n\
|
||||
"), program_name);
|
||||
|
||||
fputs (_("\
|
||||
Output platform dependent limits in a format useful for shell scripts.\n\
|
||||
\n\
|
||||
"), stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
exit (status);
|
||||
}
|
||||
|
||||
/* Add absolute values of ascii decimal strings.
|
||||
* Strings can have leading spaces.
|
||||
* If any string has a '-' it's preserved in the output:
|
||||
* I.E.
|
||||
* 1 + 1 -> 2
|
||||
* -1 + -1 -> -2
|
||||
* -1 + 1 -> -2
|
||||
* 1 + -1 -> -2
|
||||
*/
|
||||
static char *
|
||||
decimal_ascii_add (const char *str1, const char *str2)
|
||||
{
|
||||
int len1 = strlen (str1);
|
||||
int len2 = strlen (str2);
|
||||
int rlen = MAX (len1, len2) + 3; /* space for extra digit or sign + NUL */
|
||||
char *result = xmalloc (rlen);
|
||||
char *rp = result + rlen - 1;
|
||||
const char *d1 = str1 + len1 - 1;
|
||||
const char *d2 = str2 + len2 - 1;
|
||||
int carry = 0;
|
||||
*rp = '\0';
|
||||
|
||||
while (1)
|
||||
{
|
||||
char c1 = (d1 < str1 ? ' ' : (*d1 == '-' ? ' ' : *d1--));
|
||||
char c2 = (d2 < str2 ? ' ' : (*d2 == '-' ? ' ' : *d2--));
|
||||
char t1 = c1 + c2 + carry; /* ASCII digits are BCD */
|
||||
if (!c_isdigit (c1) && !c_isdigit (c2) && !carry)
|
||||
break;
|
||||
carry = t1 > '0' + '9' || t1 == ' ' + '9' + 1;
|
||||
t1 += 6 * carry;
|
||||
*--rp = (t1 & 0x0F) | 0x30; /* top nibble to ASCII */
|
||||
}
|
||||
if ((d1 >= str1 && *d1 == '-') || (d2 >= str2 && (*d2 == '-')))
|
||||
*--rp = '-';
|
||||
|
||||
if (rp != result)
|
||||
memmove (result, rp, rlen - (rp - result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char limit[64]; /* big enough for 128 bit at least */
|
||||
char *oflow;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
set_program_name (argv[0]);
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
initialize_exit_failure (EXIT_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
|
||||
usage, AUTHORS, (char const *) NULL);
|
||||
|
||||
#define print_int(TYPE) \
|
||||
snprintf (limit, sizeof(limit), "%"PRIuMAX, (uintmax_t)TYPE##_MAX); \
|
||||
printf (#TYPE"_MAX=%s\n", limit); \
|
||||
oflow = decimal_ascii_add (limit, "1"); \
|
||||
printf (#TYPE"_OFLOW=%s\n", oflow); \
|
||||
free (oflow); \
|
||||
if (TYPE##_MIN) \
|
||||
{ \
|
||||
snprintf (limit, sizeof(limit), "%"PRIdMAX, (intmax_t)TYPE##_MIN); \
|
||||
printf (#TYPE"_MIN=%s\n", limit); \
|
||||
oflow = decimal_ascii_add (limit, "-1"); \
|
||||
printf (#TYPE"_UFLOW=%s\n", oflow); \
|
||||
free (oflow); \
|
||||
}
|
||||
|
||||
/* Variable sized ints */
|
||||
print_int (CHAR);
|
||||
print_int (SCHAR);
|
||||
print_int (UCHAR);
|
||||
print_int (SHRT);
|
||||
print_int (INT);
|
||||
print_int (UINT);
|
||||
print_int (LONG);
|
||||
print_int (ULONG);
|
||||
print_int (SIZE);
|
||||
print_int (SSIZE);
|
||||
print_int (TIME_T);
|
||||
print_int (UID_T);
|
||||
print_int (GID_T);
|
||||
print_int (PID_T);
|
||||
print_int (OFF_T);
|
||||
print_int (INTMAX);
|
||||
print_int (UINTMAX);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*/
|
||||
@@ -1,5 +1,5 @@
|
||||
/* group-list.c --Print a list of group IDs or names.
|
||||
Copyright (C) 1989-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1989-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -57,7 +57,7 @@ print_group_list (const char *username,
|
||||
#if HAVE_GETGROUPS
|
||||
{
|
||||
GETGROUPS_T *groups;
|
||||
size_t i;
|
||||
int i;
|
||||
|
||||
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
|
||||
&groups);
|
||||
@@ -83,9 +83,9 @@ print_group_list (const char *username,
|
||||
ok = false;
|
||||
}
|
||||
free (groups);
|
||||
return ok;
|
||||
}
|
||||
#endif /* HAVE_GETGROUPS */
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "full-read.h"
|
||||
#include "quote.h"
|
||||
#include "safe-read.h"
|
||||
#include "xfreopen.h"
|
||||
#include "xstrtol.h"
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
@@ -838,7 +839,7 @@ head_file (const char *filename, uintmax_t n_units, bool count_lines,
|
||||
fd = STDIN_FILENO;
|
||||
filename = _("standard input");
|
||||
if (O_BINARY && ! isatty (STDIN_FILENO))
|
||||
freopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1051,7 +1052,7 @@ main (int argc, char **argv)
|
||||
: default_file_list);
|
||||
|
||||
if (O_BINARY && ! isatty (STDOUT_FILENO))
|
||||
freopen (NULL, "wb", stdout);
|
||||
xfreopen (NULL, "wb", stdout);
|
||||
|
||||
for (i = 0; file_list[i]; ++i)
|
||||
ok &= head_file (file_list[i], n_units, count_lines, elide_from_end);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* print the hexadecimal identifier for the current host
|
||||
|
||||
Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2007-2008 Free
|
||||
Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2007-2009 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -42,12 +42,10 @@ usage (int status)
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s\n\
|
||||
or: %s OPTION\n\
|
||||
Usage: %s [OPTION]\n\
|
||||
Print the numeric identifier (in hexadecimal) for the current host.\n\
|
||||
\n\
|
||||
"),
|
||||
program_name, program_name);
|
||||
"), program_name);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
emit_bug_reporting_address ();
|
||||
|
||||
@@ -32,15 +32,11 @@
|
||||
|
||||
#define AUTHORS proper_name ("Jim Meyering")
|
||||
|
||||
#if HAVE_SETHOSTNAME && !defined sethostname
|
||||
int sethostname ();
|
||||
#endif
|
||||
|
||||
#if !defined HAVE_SETHOSTNAME && defined HAVE_SYSINFO && \
|
||||
defined HAVE_SYS_SYSTEMINFO_H
|
||||
# include <sys/systeminfo.h>
|
||||
|
||||
int
|
||||
static int
|
||||
sethostname (char *name, size_t namelen)
|
||||
{
|
||||
/* Using sysinfo() is the SVR4 mechanism to set a hostname. */
|
||||
|
||||
7
src/id.c
7
src/id.c
@@ -1,5 +1,5 @@
|
||||
/* id -- print real and effective UIDs and GIDs
|
||||
Copyright (C) 1989-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1989-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -81,7 +81,8 @@ usage (int status)
|
||||
{
|
||||
printf (_("Usage: %s [OPTION]... [USERNAME]\n"), program_name);
|
||||
fputs (_("\
|
||||
Print information for USERNAME, or the current user.\n\
|
||||
Print user and group information for the specified USERNAME,\n\
|
||||
or (when USERNAME omitted) for the current user.\n\
|
||||
\n\
|
||||
-a ignore, for compatibility with other versions\n\
|
||||
-Z, --context print only the security context of the current user\n\
|
||||
@@ -294,7 +295,7 @@ print_full_info (const char *username)
|
||||
#if HAVE_GETGROUPS
|
||||
{
|
||||
GETGROUPS_T *groups;
|
||||
size_t i;
|
||||
int i;
|
||||
|
||||
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
|
||||
&groups);
|
||||
|
||||
147
src/install.c
147
src/install.c
@@ -1,5 +1,5 @@
|
||||
/* install - copy files and set attributes
|
||||
Copyright (C) 89, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 89, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "cp-hash.h"
|
||||
#include "copy.h"
|
||||
#include "filenamecat.h"
|
||||
#include "full-read.h"
|
||||
#include "mkancesdirs.h"
|
||||
#include "mkdir-p.h"
|
||||
#include "modechange.h"
|
||||
@@ -125,6 +126,9 @@ static mode_t dir_mode = DEFAULT_MODE;
|
||||
or S_ISGID bits. */
|
||||
static mode_t dir_mode_bits = CHMOD_MODE_BITS;
|
||||
|
||||
/* Compare files before installing (-C) */
|
||||
static bool copy_only_if_needed;
|
||||
|
||||
/* If true, strip executable files after copying them. */
|
||||
static bool strip_files;
|
||||
|
||||
@@ -132,7 +136,7 @@ static bool strip_files;
|
||||
static bool dir_arg;
|
||||
|
||||
/* Program used to strip binaries, "strip" is default */
|
||||
static char *strip_program = "strip";
|
||||
static char const *strip_program = "strip";
|
||||
|
||||
/* For long options that have no equivalent short option, use a
|
||||
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
|
||||
@@ -145,6 +149,7 @@ enum
|
||||
static struct option const long_options[] =
|
||||
{
|
||||
{"backup", optional_argument, NULL, 'b'},
|
||||
{"compare", no_argument, NULL, 'C'},
|
||||
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
|
||||
{"directory", no_argument, NULL, 'd'},
|
||||
{"group", required_argument, NULL, 'g'},
|
||||
@@ -167,6 +172,107 @@ static struct option const long_options[] =
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* Compare content of opened files using file descriptors A_FD and B_FD. Return
|
||||
true if files are equal. */
|
||||
static bool
|
||||
have_same_content (int a_fd, int b_fd)
|
||||
{
|
||||
enum { CMP_BLOCK_SIZE = 4096 };
|
||||
static char a_buff[CMP_BLOCK_SIZE];
|
||||
static char b_buff[CMP_BLOCK_SIZE];
|
||||
|
||||
size_t size;
|
||||
while (0 < (size = full_read (a_fd, a_buff, sizeof a_buff))) {
|
||||
if (size != full_read (b_fd, b_buff, sizeof b_buff))
|
||||
return false;
|
||||
|
||||
if (memcmp (a_buff, b_buff, size) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
/* Return true for mode with non-permission bits. */
|
||||
static bool
|
||||
extra_mode (mode_t input)
|
||||
{
|
||||
const mode_t mask = ~S_IRWXUGO & ~S_IFMT;
|
||||
return input & mask;
|
||||
}
|
||||
|
||||
/* Return true if copy of file SRC_NAME to file DEST_NAME is necessary. */
|
||||
static bool
|
||||
need_copy (const char *src_name, const char *dest_name,
|
||||
const struct cp_options *x)
|
||||
{
|
||||
struct stat src_sb, dest_sb;
|
||||
int src_fd, dest_fd;
|
||||
bool content_match;
|
||||
|
||||
if (extra_mode (mode))
|
||||
return true;
|
||||
|
||||
/* compare files using stat */
|
||||
if (lstat (src_name, &src_sb) != 0)
|
||||
return true;
|
||||
|
||||
if (lstat (dest_name, &dest_sb) != 0)
|
||||
return true;
|
||||
|
||||
if (!S_ISREG (src_sb.st_mode) || !S_ISREG (dest_sb.st_mode)
|
||||
|| extra_mode (src_sb.st_mode) || extra_mode (dest_sb.st_mode))
|
||||
return true;
|
||||
|
||||
if (src_sb.st_size != dest_sb.st_size
|
||||
|| (dest_sb.st_mode & CHMOD_MODE_BITS) != mode
|
||||
|| dest_sb.st_uid != (owner_id == (uid_t) -1 ? getuid () : owner_id)
|
||||
|| dest_sb.st_gid != (group_id == (gid_t) -1 ? getgid () : group_id))
|
||||
return true;
|
||||
|
||||
/* compare SELinux context if preserving */
|
||||
if (selinux_enabled && x->preserve_security_context)
|
||||
{
|
||||
security_context_t file_scontext = NULL;
|
||||
security_context_t to_scontext = NULL;
|
||||
bool scontext_match;
|
||||
|
||||
if (getfilecon (src_name, &file_scontext) == -1)
|
||||
return true;
|
||||
|
||||
if (getfilecon (dest_name, &to_scontext) == -1)
|
||||
{
|
||||
freecon (file_scontext);
|
||||
return true;
|
||||
}
|
||||
|
||||
scontext_match = STREQ (file_scontext, to_scontext);
|
||||
|
||||
freecon (file_scontext);
|
||||
freecon (to_scontext);
|
||||
if (!scontext_match)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* compare files content */
|
||||
src_fd = open (src_name, O_RDONLY | O_BINARY);
|
||||
if (src_fd < 0)
|
||||
return true;
|
||||
|
||||
dest_fd = open (dest_name, O_RDONLY | O_BINARY);
|
||||
if (dest_fd < 0)
|
||||
{
|
||||
close (src_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
content_match = have_same_content (src_fd, dest_fd);
|
||||
|
||||
close (src_fd);
|
||||
close (dest_fd);
|
||||
return !content_match;
|
||||
}
|
||||
|
||||
static void
|
||||
cp_option_init (struct cp_options *x)
|
||||
{
|
||||
@@ -183,8 +289,10 @@ cp_option_init (struct cp_options *x)
|
||||
x->preserve_links = false;
|
||||
x->preserve_mode = false;
|
||||
x->preserve_timestamps = false;
|
||||
x->reduce_diagnostics=false;
|
||||
x->require_preserve = false;
|
||||
x->require_preserve_context = false;
|
||||
x->require_preserve_xattr = false;
|
||||
x->recursive = false;
|
||||
x->sparse_mode = SPARSE_AUTO;
|
||||
x->symbolic_link = false;
|
||||
@@ -200,6 +308,7 @@ cp_option_init (struct cp_options *x)
|
||||
x->open_dangling_dest_symlink = false;
|
||||
x->update = false;
|
||||
x->preserve_security_context = false;
|
||||
x->preserve_xattr = false;
|
||||
x->verbose = false;
|
||||
x->dest_info = NULL;
|
||||
x->src_info = NULL;
|
||||
@@ -360,7 +469,7 @@ main (int argc, char **argv)
|
||||
we'll actually use backup_suffix_string. */
|
||||
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pt:TvS:Z:", long_options,
|
||||
while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:", long_options,
|
||||
NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
@@ -372,6 +481,9 @@ main (int argc, char **argv)
|
||||
break;
|
||||
case 'c':
|
||||
break;
|
||||
case 'C':
|
||||
copy_only_if_needed = true;
|
||||
break;
|
||||
case 's':
|
||||
strip_files = true;
|
||||
#ifdef SIGCHLD
|
||||
@@ -528,6 +640,24 @@ main (int argc, char **argv)
|
||||
error (0, 0, _("WARNING: ignoring --strip-program option as -s option was "
|
||||
"not specified"));
|
||||
|
||||
if (copy_only_if_needed && x.preserve_timestamps)
|
||||
{
|
||||
error (0, 0, _("options --compare (-C) and --preserve-timestamps are "
|
||||
"mutually exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (copy_only_if_needed && strip_files)
|
||||
{
|
||||
error (0, 0, _("options --compare (-C) and --strip are mutually "
|
||||
"exclusive"));
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (copy_only_if_needed && extra_mode (mode))
|
||||
error (0, 0, _("the --compare (-C) option is ignored when you"
|
||||
" specify a mode with non-permission bits"));
|
||||
|
||||
get_ids ();
|
||||
|
||||
if (dir_arg)
|
||||
@@ -644,6 +774,9 @@ copy_file (const char *from, const char *to, const struct cp_options *x)
|
||||
{
|
||||
bool copy_into_self;
|
||||
|
||||
if (copy_only_if_needed && !need_copy (from, to, x))
|
||||
return true;
|
||||
|
||||
/* Allow installing from non-regular files like /dev/null.
|
||||
Charles Karney reported that some Sun version of install allows that
|
||||
and that sendmail's installation process relies on the behavior.
|
||||
@@ -816,6 +949,12 @@ Usage: %s [OPTION]... [-T] SOURCE DEST\n\
|
||||
"),
|
||||
program_name, program_name, program_name, program_name);
|
||||
fputs (_("\
|
||||
\n\
|
||||
This install program copies files (often just compiled) into destination\n\
|
||||
locations you choose. If you want to download and install a ready-to-use\n\
|
||||
package on a GNU/Linux system, you should instead be using a package manager\n\
|
||||
like yum(1) or apt-get(1).\n\
|
||||
\n\
|
||||
In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to\n\
|
||||
the existing DIRECTORY, while setting permission modes and owner/group.\n\
|
||||
In the 4th form, create all components of the given DIRECTORY(ies).\n\
|
||||
@@ -828,6 +967,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
--backup[=CONTROL] make a backup of each existing destination file\n\
|
||||
-b like --backup but does not accept an argument\n\
|
||||
-c (ignored)\n\
|
||||
-C, --compare compare each pair of source and destination files, and\n\
|
||||
in some cases, do not modify the destination at all\n\
|
||||
-d, --directory treat all arguments as directory names; create all\n\
|
||||
components of the specified directories\n\
|
||||
"), stdout);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "system.h"
|
||||
#include "error.h"
|
||||
#include "hard-locale.h"
|
||||
#include "linebuffer.h"
|
||||
#include "memcasecmp.h"
|
||||
#include "quote.h"
|
||||
|
||||
6
src/ln.c
6
src/ln.c
@@ -1,5 +1,5 @@
|
||||
/* `ln' program to create links between files.
|
||||
Copyright (C) 1986, 1989-1991, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1986, 1989-1991, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -359,7 +359,9 @@ In the 1st form, create a link to TARGET with the name LINK_NAME.\n\
|
||||
In the 2nd form, create a link to TARGET in the current directory.\n\
|
||||
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.\n\
|
||||
Create hard links by default, symbolic links with --symbolic.\n\
|
||||
When creating hard links, each TARGET must exist.\n\
|
||||
When creating hard links, each TARGET must exist. Symbolic links\n\
|
||||
can hold arbitrary text; if later resolved, a relative link is\n\
|
||||
interpreted in relation to its parent directory.\n\
|
||||
\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
|
||||
140
src/ls.c
140
src/ls.c
@@ -1,5 +1,5 @@
|
||||
/* `dir', `vdir' and `ls' directory listing programs for GNU.
|
||||
Copyright (C) 85, 88, 90, 91, 1995-2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 85, 88, 90, 91, 1995-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -87,17 +87,14 @@
|
||||
#include "acl.h"
|
||||
#include "argmatch.h"
|
||||
#include "dev-ino.h"
|
||||
#include "dirfd.h"
|
||||
#include "error.h"
|
||||
#include "filenamecat.h"
|
||||
#include "hard-locale.h"
|
||||
#include "hash.h"
|
||||
#include "human.h"
|
||||
#include "filemode.h"
|
||||
#include "filevercmp.h"
|
||||
#include "idcache.h"
|
||||
#include "ls.h"
|
||||
#include "lstat.h"
|
||||
#include "mbswidth.h"
|
||||
#include "mpsort.h"
|
||||
#include "obstack.h"
|
||||
@@ -156,6 +153,12 @@ verify (sizeof filetype_letter - 1 == arg_directory + 1);
|
||||
C_LINK, C_SOCK, C_FILE, C_DIR \
|
||||
}
|
||||
|
||||
enum acl_type
|
||||
{
|
||||
ACL_T_NONE,
|
||||
ACL_T_SELINUX_ONLY,
|
||||
ACL_T_YES
|
||||
};
|
||||
|
||||
struct fileinfo
|
||||
{
|
||||
@@ -184,7 +187,7 @@ struct fileinfo
|
||||
|
||||
/* For long listings, true if the file has an access control list,
|
||||
or an SELinux security context. */
|
||||
bool have_acl;
|
||||
enum acl_type acl_type;
|
||||
};
|
||||
|
||||
#define LEN_STR_PAIR(s) sizeof (s) - 1, s
|
||||
@@ -213,7 +216,8 @@ static uintmax_t gobble_file (char const *name, enum filetype type,
|
||||
ino_t inode, bool command_line_arg,
|
||||
char const *dirname);
|
||||
static bool print_color_indicator (const char *name, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype type);
|
||||
bool stat_ok, enum filetype type,
|
||||
nlink_t nlink);
|
||||
static void put_indicator (const struct bin_str *ind);
|
||||
static void add_ignore_pattern (const char *pattern);
|
||||
static void attach (char *dest, const char *dirname, const char *name);
|
||||
@@ -227,18 +231,21 @@ static size_t calculate_columns (bool by_columns);
|
||||
static void print_current_files (void);
|
||||
static void print_dir (char const *name, char const *realname,
|
||||
bool command_line_arg);
|
||||
static void print_file_name_and_frills (const struct fileinfo *f);
|
||||
static size_t print_file_name_and_frills (const struct fileinfo *f,
|
||||
size_t start_col);
|
||||
static void print_horizontal (void);
|
||||
static int format_user_width (uid_t u);
|
||||
static int format_group_width (gid_t g);
|
||||
static void print_long_format (const struct fileinfo *f);
|
||||
static void print_many_per_line (void);
|
||||
static void print_name_with_quoting (const char *p, mode_t mode,
|
||||
int linkok, bool stat_ok,
|
||||
enum filetype type,
|
||||
struct obstack *stack);
|
||||
static size_t print_name_with_quoting (const char *p, mode_t mode,
|
||||
int linkok, bool stat_ok,
|
||||
enum filetype type,
|
||||
struct obstack *stack,
|
||||
nlink_t nlink,
|
||||
size_t start_col);
|
||||
static void prep_non_filename_text (void);
|
||||
static void print_type_indicator (bool stat_ok, mode_t mode,
|
||||
static bool print_type_indicator (bool stat_ok, mode_t mode,
|
||||
enum filetype type);
|
||||
static void print_with_commas (void);
|
||||
static void queue_directory (char const *name, char const *realname,
|
||||
@@ -517,14 +524,15 @@ enum indicator_no
|
||||
C_LEFT, C_RIGHT, C_END, C_RESET, C_NORM, C_FILE, C_DIR, C_LINK,
|
||||
C_FIFO, C_SOCK,
|
||||
C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,
|
||||
C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP
|
||||
C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_HARDLINK,
|
||||
C_CLR_TO_EOL
|
||||
};
|
||||
|
||||
static const char *const indicator_name[]=
|
||||
{
|
||||
"lc", "rc", "ec", "rs", "no", "fi", "di", "ln", "pi", "so",
|
||||
"bd", "cd", "mi", "or", "ex", "do", "su", "sg", "st",
|
||||
"ow", "tw", "ca", NULL
|
||||
"ow", "tw", "ca", "hl", "cl", NULL
|
||||
};
|
||||
|
||||
struct color_ext_type
|
||||
@@ -557,7 +565,9 @@ static struct bin_str color_indicator[] =
|
||||
{ LEN_STR_PAIR ("37;44") }, /* st: sticky: black on blue */
|
||||
{ LEN_STR_PAIR ("34;42") }, /* ow: other-writable: blue on green */
|
||||
{ LEN_STR_PAIR ("30;42") }, /* tw: ow w/ sticky: black on green */
|
||||
{ LEN_STR_PAIR ("30;41") }, /* capability: black on red */
|
||||
{ LEN_STR_PAIR ("30;41") }, /* ca: black on red */
|
||||
{ LEN_STR_PAIR ("44;37") }, /* hl: white on blue */
|
||||
{ LEN_STR_PAIR ("\033[K") }, /* cl: clear to end of line */
|
||||
};
|
||||
|
||||
/* FIXME: comment */
|
||||
@@ -715,11 +725,14 @@ static int exit_status;
|
||||
/* Exit statuses. */
|
||||
enum
|
||||
{
|
||||
/* "ls" had a minor problem (e.g., it could not stat a directory
|
||||
entry). */
|
||||
/* "ls" had a minor problem. E.g., while processing a directory,
|
||||
ls obtained the name of an entry via readdir, yet was later
|
||||
unable to stat that name. This happens when listing a directory
|
||||
in which entries are actively being removed or renamed. */
|
||||
LS_MINOR_PROBLEM = 1,
|
||||
|
||||
/* "ls" had more serious trouble. */
|
||||
/* "ls" had more serious trouble (e.g., memory exhausted, invalid
|
||||
option or failure to stat a command line argument. */
|
||||
LS_FAILURE = 2
|
||||
};
|
||||
|
||||
@@ -1760,7 +1773,7 @@ decode_switches (int argc, char **argv)
|
||||
|
||||
case FULL_TIME_OPTION:
|
||||
format = long_format;
|
||||
time_style_option = "full-iso";
|
||||
time_style_option = bad_cast ("full-iso");
|
||||
break;
|
||||
|
||||
case COLOR_OPTION:
|
||||
@@ -1878,7 +1891,7 @@ decode_switches (int argc, char **argv)
|
||||
|
||||
if (! style)
|
||||
if (! (style = getenv ("TIME_STYLE")))
|
||||
style = "locale";
|
||||
style = bad_cast ("locale");
|
||||
|
||||
while (strncmp (style, posix_prefix, sizeof posix_prefix - 1) == 0)
|
||||
{
|
||||
@@ -2688,6 +2701,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
|
||||
|
||||
if (format == long_format || print_scontext)
|
||||
{
|
||||
bool have_selinux = false;
|
||||
bool have_acl = false;
|
||||
int attr_len = (do_deref
|
||||
? getfilecon (absolute_name, &f->scontext)
|
||||
@@ -2706,7 +2720,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
|
||||
}
|
||||
|
||||
if (err == 0)
|
||||
have_acl = ! STREQ ("unlabeled", f->scontext);
|
||||
have_selinux = ! STREQ ("unlabeled", f->scontext);
|
||||
else
|
||||
{
|
||||
f->scontext = UNKNOWN_SECURITY_CONTEXT;
|
||||
@@ -2719,15 +2733,19 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
|
||||
err = 0;
|
||||
}
|
||||
|
||||
if (err == 0 && ! have_acl && format == long_format)
|
||||
if (err == 0 && format == long_format)
|
||||
{
|
||||
int n = file_has_acl (absolute_name, &f->stat);
|
||||
err = (n < 0);
|
||||
have_acl = (0 < n);
|
||||
}
|
||||
|
||||
f->have_acl = have_acl;
|
||||
any_has_acl |= have_acl;
|
||||
f->acl_type = (!have_selinux && !have_acl
|
||||
? ACL_T_NONE
|
||||
: (have_selinux && !have_acl
|
||||
? ACL_T_SELINUX_ONLY
|
||||
: ACL_T_YES));
|
||||
any_has_acl |= f->acl_type != ACL_T_NONE;
|
||||
|
||||
if (err)
|
||||
error (0, errno, "%s", quotearg_colon (absolute_name));
|
||||
@@ -3271,7 +3289,7 @@ print_current_files (void)
|
||||
case one_per_line:
|
||||
for (i = 0; i < cwd_n_used; i++)
|
||||
{
|
||||
print_file_name_and_frills (sorted_file[i]);
|
||||
print_file_name_and_frills (sorted_file[i], 0);
|
||||
putchar ('\n');
|
||||
}
|
||||
break;
|
||||
@@ -3448,7 +3466,9 @@ print_long_format (const struct fileinfo *f)
|
||||
}
|
||||
if (! any_has_acl)
|
||||
modebuf[10] = '\0';
|
||||
else if (f->have_acl)
|
||||
else if (f->acl_type == ACL_T_SELINUX_ONLY)
|
||||
modebuf[10] = '.';
|
||||
else if (f->acl_type == ACL_T_YES)
|
||||
modebuf[10] = '+';
|
||||
|
||||
switch (time_type)
|
||||
@@ -3621,8 +3641,9 @@ print_long_format (const struct fileinfo *f)
|
||||
}
|
||||
|
||||
DIRED_FPUTS (buf, stdout, p - buf);
|
||||
print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
|
||||
f->stat_ok, f->filetype, &dired_obstack);
|
||||
size_t w = print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
|
||||
f->stat_ok, f->filetype, &dired_obstack,
|
||||
f->stat.st_nlink, p - buf);
|
||||
|
||||
if (f->filetype == symbolic_link)
|
||||
{
|
||||
@@ -3630,7 +3651,8 @@ print_long_format (const struct fileinfo *f)
|
||||
{
|
||||
DIRED_FPUTS_LITERAL (" -> ", stdout);
|
||||
print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
|
||||
f->stat_ok, f->filetype, NULL);
|
||||
f->stat_ok, f->filetype, NULL,
|
||||
f->stat.st_nlink, (p - buf) + w + 4);
|
||||
if (indicator_style != none)
|
||||
print_type_indicator (true, f->linkmode, unknown);
|
||||
}
|
||||
@@ -3664,7 +3686,6 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
|
||||
if (qmark_funny_chars)
|
||||
{
|
||||
#if HAVE_MBRTOWC
|
||||
if (MB_CUR_MAX > 1)
|
||||
{
|
||||
char const *p = buf;
|
||||
@@ -3704,7 +3725,7 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
reach its end, replacing each non-printable multibyte
|
||||
character with a single question mark. */
|
||||
{
|
||||
mbstate_t mbstate = { 0, };
|
||||
DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate);
|
||||
do
|
||||
{
|
||||
wchar_t wc;
|
||||
@@ -3767,7 +3788,6 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
len = q - buf;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
char *p = buf;
|
||||
char const *plimit = buf + len;
|
||||
@@ -3783,11 +3803,9 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
}
|
||||
else if (width != NULL)
|
||||
{
|
||||
#if HAVE_MBRTOWC
|
||||
if (MB_CUR_MAX > 1)
|
||||
displayed_width = mbsnwidth (buf, len, 0);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
char const *p = buf;
|
||||
char const *plimit = buf + len;
|
||||
@@ -3809,19 +3827,21 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
return len;
|
||||
}
|
||||
|
||||
static void
|
||||
static size_t
|
||||
print_name_with_quoting (const char *p, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype type,
|
||||
struct obstack *stack)
|
||||
struct obstack *stack, nlink_t nlink,
|
||||
size_t start_col)
|
||||
{
|
||||
bool used_color_this_time
|
||||
= (print_with_color
|
||||
&& print_color_indicator (p, mode, linkok, stat_ok, type));
|
||||
&& print_color_indicator (p, mode, linkok, stat_ok, type, nlink));
|
||||
|
||||
if (stack)
|
||||
PUSH_CURRENT_DIRED_POS (stack);
|
||||
|
||||
dired_pos += quote_name (stdout, p, filename_quoting_options, NULL);
|
||||
size_t width = quote_name (stdout, p, filename_quoting_options, NULL);
|
||||
dired_pos += width;
|
||||
|
||||
if (stack)
|
||||
PUSH_CURRENT_DIRED_POS (stack);
|
||||
@@ -3830,7 +3850,11 @@ print_name_with_quoting (const char *p, mode_t mode, int linkok,
|
||||
{
|
||||
process_signals ();
|
||||
prep_non_filename_text ();
|
||||
if (start_col / line_length != (start_col + width - 1) / line_length)
|
||||
put_indicator (&color_indicator[C_CLR_TO_EOL]);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -3850,8 +3874,8 @@ prep_non_filename_text (void)
|
||||
Also print file size, inode number, and filetype indicator character,
|
||||
as requested by switches. */
|
||||
|
||||
static void
|
||||
print_file_name_and_frills (const struct fileinfo *f)
|
||||
static size_t
|
||||
print_file_name_and_frills (const struct fileinfo *f, size_t start_col)
|
||||
{
|
||||
char buf[MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND (uintmax_t))];
|
||||
|
||||
@@ -3867,11 +3891,14 @@ print_file_name_and_frills (const struct fileinfo *f)
|
||||
if (print_scontext)
|
||||
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
|
||||
|
||||
print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
|
||||
f->stat_ok, f->filetype, NULL);
|
||||
size_t width = print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f),
|
||||
f->linkok, f->stat_ok, f->filetype,
|
||||
NULL, f->stat.st_nlink, start_col);
|
||||
|
||||
if (indicator_style != none)
|
||||
print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
|
||||
width += print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/* Given these arguments describing a file, return the single-byte
|
||||
@@ -3908,12 +3935,13 @@ get_type_indicator (bool stat_ok, mode_t mode, enum filetype type)
|
||||
return c;
|
||||
}
|
||||
|
||||
static void
|
||||
static bool
|
||||
print_type_indicator (bool stat_ok, mode_t mode, enum filetype type)
|
||||
{
|
||||
char c = get_type_indicator (stat_ok, mode, type);
|
||||
if (c)
|
||||
DIRED_PUTCHAR (c);
|
||||
return !!c;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CAP
|
||||
@@ -3941,7 +3969,7 @@ has_capability (char const *name)
|
||||
}
|
||||
#else
|
||||
static bool
|
||||
has_capability (char const *name)
|
||||
has_capability (char const *name ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -3950,7 +3978,8 @@ has_capability (char const *name)
|
||||
/* Returns whether any color sequence was printed. */
|
||||
static bool
|
||||
print_color_indicator (const char *name, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype filetype)
|
||||
bool stat_ok, enum filetype filetype,
|
||||
nlink_t nlink)
|
||||
{
|
||||
int type;
|
||||
struct color_ext_type *ext; /* Color extension */
|
||||
@@ -3974,10 +4003,12 @@ print_color_indicator (const char *name, mode_t mode, int linkok,
|
||||
type = C_SETUID;
|
||||
else if ((mode & S_ISGID) != 0)
|
||||
type = C_SETGID;
|
||||
else if (has_capability (name))
|
||||
else if (is_colored (C_CAP) && has_capability (name))
|
||||
type = C_CAP;
|
||||
else if ((mode & S_IXUGO) != 0)
|
||||
type = C_EXEC;
|
||||
else if (1 < nlink)
|
||||
type = C_HARDLINK;
|
||||
}
|
||||
else if (S_ISDIR (mode))
|
||||
{
|
||||
@@ -4112,7 +4143,7 @@ print_many_per_line (void)
|
||||
struct fileinfo const *f = sorted_file[filesno];
|
||||
size_t name_length = length_of_file_name_and_frills (f);
|
||||
size_t max_name_length = line_fmt->col_arr[col++];
|
||||
print_file_name_and_frills (f);
|
||||
print_file_name_and_frills (f, pos);
|
||||
|
||||
filesno += rows;
|
||||
if (filesno >= cwd_n_used)
|
||||
@@ -4137,7 +4168,7 @@ print_horizontal (void)
|
||||
size_t max_name_length = line_fmt->col_arr[0];
|
||||
|
||||
/* Print first entry. */
|
||||
print_file_name_and_frills (f);
|
||||
print_file_name_and_frills (f, 0);
|
||||
|
||||
/* Now the rest. */
|
||||
for (filesno = 1; filesno < cwd_n_used; ++filesno)
|
||||
@@ -4156,7 +4187,7 @@ print_horizontal (void)
|
||||
}
|
||||
|
||||
f = sorted_file[filesno];
|
||||
print_file_name_and_frills (f);
|
||||
print_file_name_and_frills (f, pos);
|
||||
|
||||
name_length = length_of_file_name_and_frills (f);
|
||||
max_name_length = line_fmt->col_arr[col];
|
||||
@@ -4194,7 +4225,7 @@ print_with_commas (void)
|
||||
putchar (separator);
|
||||
}
|
||||
|
||||
print_file_name_and_frills (f);
|
||||
print_file_name_and_frills (f, pos);
|
||||
pos += len;
|
||||
}
|
||||
putchar ('\n');
|
||||
@@ -4472,7 +4503,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
|
||||
fputs (_("\
|
||||
-r, --reverse reverse order while sorting\n\
|
||||
-R, --recursive list subdirectories recursively\n\
|
||||
-s, --size print the size of each file, in blocks\n\
|
||||
-s, --size print the allocated size of each file, in blocks\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
-S sort by file size\n\
|
||||
@@ -4527,7 +4558,10 @@ colors, and can be set easily by the dircolors command.\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
\n\
|
||||
Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble.\n\
|
||||
Exit status:\n\
|
||||
0 if OK,\n\
|
||||
1 if minor problems (e.g., cannot access subdirectory),\n\
|
||||
2 if serious trouble (e.g., cannot access command-line argument).\n\
|
||||
"), stdout);
|
||||
emit_bug_reporting_address ();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#endif
|
||||
#include "error.h"
|
||||
#include "stdio--.h"
|
||||
#include "xfreopen.h"
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#if HASH_ALGO_MD5
|
||||
@@ -391,7 +392,7 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result)
|
||||
if (*binary < 0)
|
||||
*binary = ! isatty (STDIN_FILENO);
|
||||
if (*binary)
|
||||
freopen (NULL, "rb", stdin);
|
||||
xfreopen (NULL, "rb", stdin);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -685,7 +686,7 @@ main (int argc, char **argv)
|
||||
binary = 0;
|
||||
|
||||
if (optind == argc)
|
||||
argv[argc++] = "-";
|
||||
argv[argc++] = bad_cast ("-");
|
||||
|
||||
for (; optind < argc; ++optind)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "system.h"
|
||||
#include "error.h"
|
||||
#include "lchmod.h"
|
||||
#include "mkdir-p.h"
|
||||
#include "modechange.h"
|
||||
#include "prog-fprintf.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user