platform/upstream/coreutils.git
11 years agofactor: tidy up primes.h again
Paul Eggert [Sat, 17 Nov 2012 00:51:50 +0000 (16:51 -0800)]
factor: tidy up primes.h again

See Stefano Lattarini in <http://bugs.gnu.org/12899>.
* src/local.mk (BUILT_SOURCES): Put $(top_srcdir)/src/primes.h here
(MAINTAINERCLEANFILES): ... instead of here.

11 years agofactor: cleanup for primes.h
Paul Eggert [Tue, 13 Nov 2012 15:43:08 +0000 (07:43 -0800)]
factor: cleanup for primes.h

* .gitignore: Add src/primes.h back, since it's no longer
in the repository.

11 years agomaint: avoid unnecessary #include to fix syntax-check failure
Jim Meyering [Tue, 13 Nov 2012 06:03:01 +0000 (07:03 +0100)]
maint: avoid unnecessary #include to fix syntax-check failure

* src/factor.c: Remove unneeded #inclusion of"verify.h".
It's already included via system.h.

11 years agofactor: improve primes.h change
Paul Eggert [Tue, 13 Nov 2012 05:10:17 +0000 (21:10 -0800)]
factor: improve primes.h change

This follows suggestions by Jim Meyering in
<http://bugs.gnu.org/12841#34>.
* src/make-prime-list.c (print_wide_uint): Change "nested" argument
to "nesting", and use it to avoid outputting lines that are too long.
* src/primes.h: Remove from git.  This can be generated by a
maintainer.  It's nicer to do so on a host with at least 128-bit
arithmetic.

11 years agofactor: maintainer builds primes.h, not builder
Paul Eggert [Mon, 12 Nov 2012 16:32:04 +0000 (08:32 -0800)]
factor: maintainer builds primes.h, not builder

With this change, the maintainer builds primes.h and it is part of
the tarball.  primes.h's contents are not architecture-specific.
* .gitignore: Remove /src/primes.h.
* src/factor.c: Include verify.h.
(W): New constant.  Verify that uintmax_t lacks holes
and that W is no wider than the integers used to generate primes.h.
* src/local.mk (EXTRA_DIST): Add src/primes.h.
(BUILT_SOURCES, CLEANFILES): Remove src/primes.h.
($(top_srcdir)/src/primes.h): Rename from src/primes.h.
Do not depend on src/make-prime-list.  Instead, use sub-make to
build, so that we build primes.h only if it does not exist.
* src/make-prime-list.c: Include <limits.h>, for ULONG_MAX.
(wide_uint): Define to uintmax_t or unsigned __int128 if not #defined.
(struct prime, binvert, process_prime): Use it instead of uintmax_t.
(print_wide_uint): New function.  This generates the proper pinv
value regardless of the width of uintmax_t on the target, so long
as the width doesn't exceed that of the width of wide_uint on the
maintainer host that generated src/primes.h.
(output_primes): Use it.  Output WIDE_UINT_BITS, too.  Let the
target compute its own lim, since its uintmax_t may be narrower
than ours.
(SZ): Remove.
* src/primes.h: New file, generated with 128-bit integers and usable
on any host where uintmax_t's width is no greater than 128 bits.

11 years agofactor: port to systems with rpl_malloc
Paul Eggert [Mon, 12 Nov 2012 16:16:30 +0000 (08:16 -0800)]
factor: port to systems with rpl_malloc

* src/make-prime-list.c (malloc): Undef.  This fixes a problem on
AIX 8.20 reported by Michael Felt in <http://bugs.gnu.org/12841>.

11 years agotests: fix factor's tests to use coreutil's own sha1sum
Bernhard Voelker [Fri, 9 Nov 2012 14:09:05 +0000 (15:09 +0100)]
tests: fix factor's tests to use coreutil's own sha1sum

The test used the shasum utility which seems to belong to the
perl package. On SLES-10.4, perl doesn't include this yet:

  + seq 0 10000000
  + factor
  + shasum -c --status exp
  ./tests/factor/t00.sh: line 30: shasum: command not found
  + Exit 1

It is better to use our own stuff anyway.

* tests/factor/run.sh: s/shasum/sha1sum/. Additionally, add
sha1sum to the print_ver_ call.

11 years agodoc: chcon: add descriptions for three undocumented options
Benno Schulenberg [Mon, 15 Oct 2012 17:37:34 +0000 (19:37 +0200)]
doc: chcon: add descriptions for three undocumented options

These were missed in this related change v8.14-104-g44e20cd

* src/chcon.c (usage): Mention the two --preserve-root options.
* doc/coreutils.texi (chcon invocation): Plus the --dereferece option.

11 years agodoc: with cp -n, option -f is not redundant but ignored
Benno Schulenberg [Mon, 15 Oct 2012 11:06:37 +0000 (13:06 +0200)]
doc: with cp -n, option -f is not redundant but ignored

* src/cp.c (usage): Replace "redundant" with "ignored".
* doc/coreutils.texi (cp invocation): Likewise.

11 years agodf: port the new df test to POSIX sed, larger file systems
Paul Eggert [Fri, 9 Nov 2012 09:11:18 +0000 (01:11 -0800)]
df: port the new df test to POSIX sed, larger file systems

* tests/df/df-output.sh: For the test "df -B1K --output=size",
do not assume that the file system size fits in 9 bytes; it
might be larger than that, so omit leading space.  Also, use
portable 'sed' commands: POSIX says sed commands inside { } should
all end in newline.

11 years agodf: add a test for the --output option
Bernhard Voelker [Sun, 23 Sep 2012 20:29:25 +0000 (22:29 +0200)]
df: add a test for the --output option

* tests/df/df-output.sh: Add a test case.
* tests/local.mk (all_tests): Mention the test.
* cfg.mk (sc_file_system): Exempt the test from this syntax-check.

11 years agodf: document the new --output option
Bernhard Voelker [Sat, 29 Sep 2012 16:44:18 +0000 (18:44 +0200)]
df: document the new --output option

* src/df.c (usage): Add a short description of --output and its
available field names for use in the optional argument.
* doc/coreutils.texi (df invocation): Add the new option with more
details and a few examples.
* NEWS (New features): Mention the new option.
(Changes in behvaior): Mention the new placeholder for fields
in the "total" line.

11 years agodf: add --output to select which fields to display
Bernhard Voelker [Thu, 30 Aug 2012 12:58:22 +0000 (14:58 +0200)]
df: add --output to select which fields to display

This supports changing the order of the fields displayed,
and also allows the simultaneous display of inode and block fields.

src/df.c (get_dev): Factor out calling get_header to ...
(main): ... here.  Call print_table only if file_systems_processed.

src/df.c (Displayable fields): Rename DEV_FIELD to SOURCE_FIELD.
Rename TYPE_FIELD to FSTYPE_FIELD.  Rename FREE_FIELD to AVAIL_FIELD.
Rename MNT_FIELD to TARGET_FIELD.

* src/df.c (display_field_t): Turn loose enum definition of the
displayable fields into a typedef.  Add the inode fields ITOTAL_FIELD,
IUSED_FIELD, IAVAIL_FIELD, IPCENT_FIELD.
(field_data_t): Define structure to hold the display field, the
caption, the width and the alignment for each field of the above
type.
(field_data): Add array the values of field data for each display
field.
(headers, alignments, widths): Remove arrays.
(columns): Add a pointer to the storage for the array of the actual
output columns, i.e., fields.
(ncolumns): Add counter for the current output columns.
(alloc_table_row): Allocate the dynamic ncolumns value of strings.
(print_table): Loop over ncolumns instead of constant NFIELDS.  Rename
loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure.  Adjust the condition for printing
the last column by comparing with the column number instead of the
field name (TARGET_FIELD).  Use the width and the alignment stored in
the columns data.
(alloc_field): Add new function to allocate a field in the columns
array.
(get_field_list): Add new function to fill the array of output columns
for each mode.
(get_header): Loop over ncolumns instead of constant NFIELDS.  Rename
the loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure.  Remove the code for continuing the
loop if the current column is the file system type and print_type is not
active (which is now impossible).  Store the cell in the columns store
along with the new width.
(get_dev): Loop over ncolumns instead of the constant NFIELDS.  Rename
the loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure; move the definition down to where it
is used first.  Add cases for the inode fields ITOTAL_FIELD,
IUSED_FIELD, IAVAIL_FIELD and IPCENT_FIELD.  Store the cell in the
columns store along with the new width.
(main): Use new get_field_list function to fill the list of output
columns.

* src/df.c (print_table): Instead of fputs()ing directly, apply
ambsalign on the last field, too.  Use the new MBA_NO_RIGHT_PAD flag
for this.

* src/df.c (TOTAL_OPTION): Add new enum value.
(long_options): Use it for the "total" option instead of 'c'.
(main): Likewise.

* src/df.c (get_dev): Remove condition to copy the fstype into the
FSTYPE_FIELD - based on whether print_type is non-Null.  Since the
introduction of get_field_list(), there are only fields added to
the columns array which have to be added.

* src/df.c (get_dev): Guard the summing up of the values for the
grand total: only do it if we have to print the total and if the
current invocation is not for processing it.

* src/df.c (main): Pass a hyphen "-" for the mount point name
to get_dev.
(get_dev): As the mount_point is now always there,
remove the condition and the else case for the TARGET_FIELD.
Instead, simply copy the mount_point.
All cells are now always present.  Therefore, add an assertion
statement if one was not.  Furthermore, hide the problematic
characters unconditionally.
(print_table): Remove the skipping of empty cells.
* tests/df/total-verify.sh: Accommodate to the new "-" in the
target field of the summary line.
* NEWS: Mention the change in behavior.

* src/df.c (field_type_t): Add new typedef of 3 enums to distinguish
between block, inode and other fields.
(field_data_t): Add field_type member of the above new type.
(field_data): Add default values for the above field_type,
indicating whether a field contains block values, inode values
or other, generic values.
(field_values_t): Add this struct to store the field values, used
by and factored out from get_dev to be able to define such a struct
for both the inode and the block values.
(get_field_values): Add this function to obtain the block values
and the inode values from the file system usage, used by and
factored out from get_dev.
(add_to_grand_total): Add this function to sum the values of the
current mount point up for the grand total, used by and factored
out from get_dev.
(get_dev): Move the definition of the variables fsu, buf, pct and
cell down to where they are used first to give them a better scope.
Factor out input_units, output_units, total, available,
negate_available, available_to_root, used and negate_used into the
above struct field_values_t.
Factor out the mapping of the fsu values to the above variables
into above function get_field_values.
Factor out the summing up of the grand total values into the
above function add_to_grand_total.
Define block_values and inode_values of the new type and call the
new get_field_values to fill them from the fsu values.
Call the above function add_to_grand_total for summing up the
values for the grand total.
Inside the loop over all fields, define a variable 'v' to point
to either the block_values or the inode_values, depending on the
current field's field_type.  Change the code in the cases
TOTAL_FIELD/ITOTAL_FIELD, USED_FIELD/IUSED_FIELD, AVAIL_FIELD/
IAVAIL_FIELD and PCENT_FIELD/IPCENT_FIELD to use the field values
where 'v' is pointing to, i.e., either the block_values or the
inode_values.

* src/df.c (main): Remove setting of grand_fsu.fsu_blocks in the
inode_format case as this is no longer needed and would lead to
wrong results once when mixed block/inode fields will be used.

* src/df.c (main): Cleanup the code at the end regarding
file_systems_processed to make the code clearer.

* src/df.c (inode_format): Remove variable.
(main): Remove initialization of the above variable.
In getopts loop, directly set the header_mode to INODES_MODE
instead of using the above variable.  Afterwards, remove the
mapping to INODES_MODE as it is already set.

* src/df.c (posix_format): Move variable ...
(main): ... to here.

* src/df.c (print_table): Enhance the comment about 2-line format
in cases where the SOURCE_FIELD exceeds 20 chars, as such
behavior has been removed long ago by commit v8.10-40-g99679ff.

* src/df.c (Display modes): Add OUTPUT_MODE, remove unused NMODES.
(display_field_t): Remove unnecessary NFIELDS.
(field_data_t): Add member 'arg' for the field name in the --output
argument.  Add member 'used' to remember if a field is already used
in the columns array.
(field_data): Add values for the above new members arg and used.
(all_args_string): Add variable which represents the argument for
the --output option which includes all fields.
(OUTPUT_OPTION): Add enum to identify the long --output option.
(long_options): Add optional-argument --output option.
(alloc_field): Assert that the field is not already used.
Mark the field as used.
(decode_output_arg): Add function to parse the comma-separated
field list passed to the --output option in order to add the
appropriate fields to the columns array.
(get_field_list): Add case for the new OUTPUT_MODE to add all
available fields to columns in the case the --output option
has been passed without any values.  Use the comma-separated
field list form to pass to decode_output_arg to keep the field
header mapping for the OUTPUT_MODE only on one place.
(main): Define format string msg_mut_excl to be used in the
following checks whether the use of --output and the other
option is mutually exclusive.
In the getopt_long loop, add a check to the case for the -i option
to issue an error message when it is used together with --output;
Likewise for -T and -P.
Add a new case for OUTPUT_OPTION, together with similar checks as
above and eventually passing the optarg to decode_output_arg.
After the getopt_long loop, consider the OUTPUT_MODE case in order
not to run into -h or -P mode.

* src/df.c (get_dev): Also xstrdup the dev_name, and free it
afterwards to silence a valgrind warning about definitely lost
memory.
(main): Free the columns store to silence valgrind, guarded by
the IF_LINT macro.

* src/df.c (main): Pass "total" as the mount point to get_dev if
the SOURCE_FIELD is not among the columns to output.
* tests/df/df-output.sh: Change the test to ensure the content of
the target field of the grand total line: if the source field is
present, then the target should be "-", else the target field should
be "target".
* NEWS (Changes in behavior): Enhance the exiting NEWS entry.
* doc/coreutils.texi (df invocation): Document the content of the
source and target field in the grand total line.

* src/df.c (main): Add another condition to the need_fs_type
parameter of read_file_system_list whether the FSTYPE_FIELD is
used or not.

* src/df.c (get_header): Indicate the block size used,
in the "size" header, when using --output without -h.
* tests/df/df-output.sh: Adjust for, and add an extra test for,
the new behavior.

11 years agomaint: fix factor's test file name pattern in .gitignore
Bernhard Voelker [Mon, 5 Nov 2012 19:35:13 +0000 (20:35 +0100)]
maint: fix factor's test file name pattern in .gitignore

* .gitignore: Adapt the entry for the files generated during
the factor tests (see v8.20-9-g1cace4a).

11 years agotimeout: add --preserve-status to always propagate the exit status
Ángel González [Mon, 29 Oct 2012 00:36:08 +0000 (00:36 +0000)]
timeout: add --preserve-status to always propagate the exit status

It's useful for commands that support running for an indeterminite
amount of time, to not return a specific timeout exit status (124),
and instead let the command handle the timeout signal and return
a status for the work done so far.

* doc/coreutils.texi (timeout invocation): Describe the new option.
* src/timeout.c (preserve_status): A new global boolean to
enable the --preserve-status behavior.
(usage): Describe the new option.
(main): Don't return EXIT_TIMEOUT of preserve_status is set.
* tests/misc/timeout.sh: Add a test for the new option.

11 years agomaint: fix the error message from sc_check-I18N-AUTHORS
Pádraig Brady [Sun, 4 Nov 2012 00:55:57 +0000 (00:55 +0000)]
maint: fix the error message from sc_check-I18N-AUTHORS

* cfk.mk (sc_check-I18N-AUTHORS): Fix the quoting so
you don't get a 'command not found' error.

11 years agobuild: avoid build failure on some HPPA systems
Pádraig Brady [Tue, 30 Oct 2012 02:02:05 +0000 (02:02 +0000)]
build: avoid build failure on some HPPA systems

* src/longlong.h: Restrict some HPPA assembly variants to PA RISC V2.0.
Note we also avoid this assembly for ilp32 runtimes, since even though
the assembly is accepted there, it's not safe as the context can get
clobbered between the 'add' and 'add,dc'.
This fixes a compile failure with newer HPPA systems with default
GCC CPU options.
Reported by John David Anglin

11 years agobuild: don't assume uintmax_t is 64 bits
Pádraig Brady [Tue, 30 Oct 2012 02:15:36 +0000 (02:15 +0000)]
build: don't assume uintmax_t is 64 bits

This was not seen to be an issue in practise,
but to make the code more robust, don't assume
uintmax_t is 64 bits.

* src/factor.c (W_TYPE_SIZE): Define based on integer limits.
* src/make-prime-list.c (output_primes): Define format width
based on integer limits.

11 years agobuild: don't rely on support for '%j' printf format
Pádraig Brady [Tue, 30 Oct 2012 02:12:23 +0000 (02:12 +0000)]
build: don't rely on support for '%j' printf format

* src/factor.c (print_uintmaxes): Replace with PRIuMAX.
* src/join.c (check_order): Likewise.
* cfg.mk (sc_check-j-printf-format): Add a syntax-check rule
to flag new cases of this.

11 years agobuild: don't rely on support for '%*j' printf format
Pádraig Brady [Mon, 29 Oct 2012 02:27:24 +0000 (02:27 +0000)]
build: don't rely on support for '%*j' printf format

* src/make-prime-list.c: Hardcode the uintmax_t width
to 16 hex digits (64 bit), to avoid this compile issue
on HPUS systems at least.

11 years agotests: fix syntax error in setuidgid_has_perm_
Bernhard Voelker [Thu, 1 Nov 2012 15:50:51 +0000 (16:50 +0100)]
tests: fix syntax error in setuidgid_has_perm_

An invalid sed expression lead to the following error:
  + sed -n 'ls/.* //p'
  sed: -e expression #1, char 2: extra characters after command
Use "one" instead of "el".
Bug introduced in v8.19-111-g51a4b04.

* init.cfg (setuidgid_has_perm_): s/ls/1s/.
* NEWS (Build-related): Mention the fix.

11 years agotests: shorten factor's inordinately-long test file names
Bernhard Voelker [Sat, 27 Oct 2012 11:24:18 +0000 (13:24 +0200)]
tests: shorten factor's inordinately-long test file names

Besides what the subject says, this commit moves the test data
for the factor tests from tests/local.mk into the directory
tests/factor/ where it belongs.

* tests/local.mk (EXTRA_DIST): Add new tests/factor/create-test.sh.
(p,q,t1,t2) Factor out the factor-related magic numbers.
(factor_tests): Rename the test names to t{00..36}.sh. Factor out
the triples of test data.
($(factor_tests)): Add dependency to new
tests/factor/create-factor.sh.
Call that script to generate the test scripts.
* tests/factor/run.sh: Turn this script into a template, and
therefore remove it's executable permission bit.
Add template variables START, END and CKSUM, replacing the code
to split the test data from the test script's file name.
Use the new template variables in the call to seq and for
creating the exp file.
* tests/factor/create-test.sh: Add new script to create the
test scripts from the template tests/factor/run.sh.
Use test data and magic numbers factored out from the above
files. Let the script also change the __TEMPLATE__ line in
run.sh to make clear that the test scripts are generated.
* cfg.mk (sc_tests_list_consistency): Exempt the new test.
(exclude_file_name_regexp--sc_prohibit_test_backticks):
Likewise.

Improved-by: Stefano Lattarini
Improved by: Jim Meyering

11 years agobuild: man page generation: degrade gracefully when perl is lacking
Stefano Lattarini [Tue, 11 Sep 2012 18:54:30 +0000 (20:54 +0200)]
build: man page generation: degrade gracefully when perl is lacking

Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaked the
distributed Makefile.in to make each man page 'man/foo.1' depend
on the corresponding source 'src/foo.c' rather than the corresponding
program 'src/foo'.  That was done to accommodate systems without
perl, which cannot run help2man to regenerate the manpage after
its corresponding program has been built.

This seems a right and proper graceful degradation, in that the
man pages dependencies are still 100% correct in a git checkout,
while being more lax but "more portable" in a distribution tarball.
Alas, that is not the case in practice, as it turns out the tweaked
Makefile makes the building of man pages unreliable and potentially
incorrect!

In fact, assume that instead of the correct a dependency:

    man/ls.1: src/ls

we have the laxer one:

    man/ls.1: src/ls.c

and think of what happens if a user modifies, say, 'src/ls.c', and then
runs "make -j4" to rebuild everything.  The make process will see that
it has to rebuild the man page 'man/ls.1' (because its prerequisite
'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
*before* re-running 'help2man' to generate that man page; so, if
'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
make), our user will get either a build error (if 'src/ls' did non
exist) or, worse, a man page with an up-to-date timestamp but an
out-of-date content.  And what's even worse in all of this is that
this problem will be present also for users who have perl installed:
this is not a "graceful degradation" at all!

In our situation, the best and simplest way to implement a graceful
degradation it to keep the correct dependencies for man pages (that
is, "man/ls.1: src/ls"), and if perl is not present, just generate
dummy man pages reporting that built-time issue and redirecting the
user back to either the info documentation or the '--help' output.

As a consequence of this change, we also stop distributing man pages,
since they will now be generated unconditionally.

* Makefile.am (do-not-require-help2man): Remove.
(dist-hook): Don't depend on it.
* man/local.mk: Remove an obsolete comment.
(EXTRA_DIST): Stop distributing generated man pages.
($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
(MAINTAINERCLEANFILES): $(ALL_MANS) Do not list it here, and ...
(CLEANFILES): ... list it here, instead.
(.x.1): Instead of warning if perl is missing, but then trying to run
'help2man' unconditionally, simply run ...
(run_help2man): ... the command referenced by this new variable, that
expands to a proper invocation of 'help2man' if perl is present, and
to an invocation of a shell script generating a dummy manpage if it
is not.
(EXTRA_DIST): Distribute that shell script.
* man/dummy-man: New shell script.
* NEWS (Build-related): Mention this.
Fixes coreutils http://bugs.gnu.org/12715.

11 years agomaint: tweak sc_check-I18N-AUTHORS
Jim Meyering [Thu, 25 Oct 2012 16:35:34 +0000 (18:35 +0200)]
maint: tweak sc_check-I18N-AUTHORS

* cfg.mk (sc_check-I18N-AUTHORS): Remove unnecessary subshell;
add a self-explanatory diagnostic.

11 years agomaint: remove an obsolete test comment
Jim Meyering [Thu, 25 Oct 2012 11:41:45 +0000 (13:41 +0200)]
maint: remove an obsolete test comment

* tests/du/bind-mount-dir-cycle.sh: Remove obsolete comment
spotted by Gilles Espinasse.

11 years agopr: fix -n to pad consistently and not crash
Pádraig Brady [Wed, 24 Oct 2012 09:55:13 +0000 (10:55 +0100)]
pr: fix -n to pad consistently and not crash

* src/pr.c: Replace the code to truncate the most significant
digits of line numbers, with much simpler string manipulation
that supports arbitrary widths.  Before this, specifying a
width >= 32 to -n would result in a divide by zero error.
Also remove the inconsistent padding with zeros and spaces, which
would result in zero padding for widths 12 and 15.
* tests/pr/pr-tests.pl: Added a test to ensure no zero padding,
and also a test for the divide by zero case.
* NEWS: Mentioned the fix
Reported by Ondrej Oprala

11 years agobuild: ensure factor links the iconv library
Pádraig Brady [Thu, 25 Oct 2012 09:59:23 +0000 (10:59 +0100)]
build: ensure factor links the iconv library

* src/local.mk (src_factor_LDADD): Append $(LIBICONV).
* crg.mk (sc_check-I18N-AUTHORS): A new syntax check rule
to ensure we add LIBICONV where appropriate.
* THANKS.in: Add the reporter.
Reported by Christian Jullien
Syntax check suggested by Jim Meyering

11 years agomaint: refactor tests/misc/pr.pl into tests/pr/pr-tests.pl
Pádraig Brady [Wed, 24 Oct 2012 22:18:23 +0000 (23:18 +0100)]
maint: refactor tests/misc/pr.pl into tests/pr/pr-tests.pl

* tests/misc/pr.pl: Refactor this test into ...
* tests/pr/pr-tests.pl: ... here.
* tests/local.mk: Remove the reference to the removed test
Improved by Jim Meyering

11 years agobuild: do not redefine _FORTIFY_SOURCE
Mike Frysinger [Tue, 23 Oct 2012 19:20:07 +0000 (15:20 -0400)]
build: do not redefine _FORTIFY_SOURCE

When _FORTIFY_SOURCE is defined by the compiler or via flags, as
it is on Gentoo, do not override it.  Otherwise we get many
redefinition warnings.

* configure.ac (FORTIFY_SOURCE): Check if _FORTIFY_SOURCE is defined.
This addresses http://bugs.gnu.org/12714

11 years agomaint: post-release administrivia
Pádraig Brady [Tue, 23 Oct 2012 16:27:19 +0000 (17:27 +0100)]
maint: post-release administrivia

* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.

11 years agoversion 8.20 v8.20
Pádraig Brady [Tue, 23 Oct 2012 15:48:48 +0000 (16:48 +0100)]
version 8.20

* NEWS: Record release date.

11 years agofactor: add comments
Jim Meyering [Tue, 23 Oct 2012 10:08:58 +0000 (12:08 +0200)]
factor: add comments

* src/factor.c (is_square): Use active voice in comment, not passive.
(factor): Add function-describing comment.
(mp_factor): Likewise.

11 years agobuild: avoid warnings about unused variables and macros
Pádraig Brady [Tue, 23 Oct 2012 10:59:04 +0000 (11:59 +0100)]
build: avoid warnings about unused variables and macros

src/factor.c (__GMP_DECLSPEC): Move back from longlong.h
to treat consistently with other stub macros.
(__GMP_GNUC_PREREQ): Reference to avoid -Wunused-macros warning.
(__GMP_DECLSPEC): Likewise.
(ASSERT): Likewise.
(__clz_tab): Likewise.
(factor_using_division): Mark a variable as unused.
(mulredc): Likewise.
(mulredc2): Likewise.
(divexact_21): Likewise.

11 years agobuild: avoid compile warnings in factor.c on some systems
Pádraig Brady [Tue, 23 Oct 2012 10:03:32 +0000 (11:03 +0100)]
build: avoid compile warnings in factor.c on some systems

* src/factor.c (factor_using_pollard_rho2): On some systems
(like sparc) we need to promote all addmod2() parameters
to uintmax_t to avoid warnings.

11 years agobuild: avoid build failure on some sparc systems
Pádraig Brady [Tue, 23 Oct 2012 10:00:24 +0000 (11:00 +0100)]
build: avoid build failure on some sparc systems

* src/longlong.h: Restrict some sparc assembly variants
to sparc V9. This was seen to be an issue with newer
sparc systems with default gcc CPU options.

11 years agotests: correctly restrict factor test without GMP
Pádraig Brady [Mon, 22 Oct 2012 12:03:27 +0000 (13:03 +0100)]
tests: correctly restrict factor test without GMP

* tests/misc/factor.pl: Correct the precedence and
regular expression in the command to check for GMP.

11 years agodoc: NEWS: the cp bug affects mv and install, too
Jim Meyering [Sun, 21 Oct 2012 09:56:44 +0000 (11:56 +0200)]
doc: NEWS: the cp bug affects mv and install, too

* NEWS (Bug fixes): Note that the copy-induced corruption but affects
mv (sometimes) and install, too.  Pointed out by Bernhard Voelker.

11 years agodoc: remove a stray parenthesis from 'cp --force' description
Benno Schulenberg [Mon, 15 Oct 2012 11:12:46 +0000 (13:12 +0200)]
doc: remove a stray parenthesis from 'cp --force' description

* doc/coreutils.texi (cp invocation): Remove Cheshire Cat.

11 years agobuild: update gnulib submodule to latest
Jim Meyering [Wed, 17 Oct 2012 09:21:12 +0000 (11:21 +0200)]
build: update gnulib submodule to latest

11 years agocp: avoid data-corrupting free-memory-read
Jim Meyering [Tue, 16 Oct 2012 15:43:49 +0000 (17:43 +0200)]
cp: avoid data-corrupting free-memory-read

* src/extent-scan.c (extent_scan_read): Reset our last_ei
pointer whenever the parent buffer might have just been freed.
* tests/cp/fiemap-extent-FMR.sh: New test.
* tests/local.mk (all_tests): Add it.
* NEWS (Bug fixes): Mention it.
Reported by Mike Gerth in http://bugs.gnu.org/12656, and with
help from Alan Curry.  Bug introduced in commit v8.10-60-g18f5a85.

11 years agodoc: improve HACKING guidelines
Nikolas Kallis [Sat, 13 Oct 2012 17:52:33 +0000 (19:52 +0200)]
doc: improve HACKING guidelines

* HACKING: Add "cd coreutils" after the git clone command.
Copyright-paperwork-exempt: Yes

11 years agofactor: fix integer validation and GMP fallback
Pádraig Brady [Mon, 8 Oct 2012 14:48:43 +0000 (15:48 +0100)]
factor: fix integer validation and GMP fallback

In the recent factor rewrite, the GMP code
wasn't actually used; just an error was printed
on integer overflow.  While fixing that it was noticed
that correct input validation wasn't done in all cases
when falling back to the GMP code.

* src/factor.c (print_factors) Fallback to GMP on overflow.
(strto2uintmax): Scan the string for invalid characters,
so that case can be detected independently of overflow.
Return an error when an empty string is passed.
Also allow leading spaces and '+' in input numbers.
* tests/misc/factor.pl: Ensure the GMP code is exercised
when compiled in. Also add a test to verify leading
spaces and '+' are allowed.

11 years agobuild: support older GMP versions
Pádraig Brady [Mon, 8 Oct 2012 10:38:41 +0000 (11:38 +0100)]
build: support older GMP versions

The new factor code introduced usage of mpz_inits() and
mpz_clears(), which are only available since GMP >= 5,
and will result in a compile error when missing.

* m4/gmp.m4 (cu_GMP): Define HAVE_DECL_MPZ_INITS appropriately.
* src/factor (mpz_inits): New function, defined where missing.
(mpz_clears): Likewise.

11 years agomaint: avoid warning from gcc's -Wunused-macros
Jim Meyering [Sun, 7 Oct 2012 08:37:25 +0000 (10:37 +0200)]
maint: avoid warning from gcc's -Wunused-macros

On some systems, -Wunused-macros would warn about two macros:
src/factor.c:148:0: warning: macro "__clz_tab" is not used
src/factor.c:126:0: warning: macro "UHWtype" is not used
* src/factor.c: Add a use to placate gcc.

11 years agobuild: avoid link failure when strerror is replaced
Jim Meyering [Fri, 5 Oct 2012 20:35:27 +0000 (22:35 +0200)]
build: avoid link failure when strerror is replaced

When building the new make-prime-list program on a system for which
strerror is defined to rpl_strerror, we'd get a link failure.
The problem is that we're including <config.h> for some definitions,
but do not want the rpl_ ones, since this particular program must
not be linked against gnulib (aka libcoreutils.a).  This did not
arise on Fedora 17 or 18, but did on Debian wheezy/sid.
* src/make-prime-list.c (strerror): #undef.
Build failure introduced by commit v8.19-152-gcf67e4c.

11 years agofactor: 25% speed-up, on output
Jim Meyering [Tue, 18 Sep 2012 06:26:17 +0000 (08:26 +0200)]
factor: 25% speed-up, on output

* src/factor.c (print_factors_single): Use fputs and umaxtostr
rather than printf with "%ju".  This reduced the time required
to compute and print the factors of the first 10^7 integers from
over 8 seconds to 5.75s.  Run this command:
seq $((10**7)) | env time factor > /dev/null

11 years agofactor: merge with preexisting factor; integrate tests; avoid warnings
Jim Meyering [Sun, 16 Sep 2012 20:31:04 +0000 (22:31 +0200)]
factor: merge with preexisting factor; integrate tests; avoid warnings

* src/factor.c: Renamed from factor-ng.c, with the following changes:
Adjust copyright header to be consistent with others.
Use xmalloc and xrealloc, to avoid segv upon OOM.
Switch back to using readtokens to handle input.
Diagnose invalid inputs.
s/fprintf+exit/error/
(print_factors): Add comments.
(strto2uintmax): Return strtol_error, not int.
(read_item): Remove, no longer used.
(main): Use atexit(close_stdout) so that we don't ignore failed write.
* cfg.mk: Exempt src/longlong.h from several tests.
Exempt run.sh from the test-list-consistency test.
Exempt make-prime-list.c from numerous tests, since we won't
be making it conform: it must not link with libcoreutils.a.
Exempt factor-ng.c from the no-upper-case error message test.
* AUTHORS (factor): Add Torbjörn and Niels.
* tests/local.mk (factor_tests): Encode the 37 tests.
($(factor_tests)): Rule to generate a test script for each test.
* tests/factor/run.sh: New script, marked as very expensive.
* .gitignore: Ignore new generated files.
* src/local.mk (src/primes.h): New rule.
(noinst_PROGRAMS): Add make-prime-list.
(noinst_HEADERS): Add longlong.h.
Remove all wheel-related rules and files.
* src/wheel-gen.pl: Remove file.

maint: mark set-but-not-used variables with ATTRIBUTE_UNUSED
* src/factor-ng.c (redcify, prime_p, isqrt2): Mark them, so we
don't have to disable -Wunused-but-set-variable.

maint: use __builtin_expect only if __GNUC__
* src/factor-ng.c (LIKELY, UNLIKELY) [__GNUC__]: Add #ifdef guard.

build: avoid warning about unused macro
* src/factor-ng.c (__GMP_DECLSPEC): Don't define here
* src/longlong.h (__GMP_DECLSPEC): Define if not already defined.

11 years agofactor: more improvements
Niels Möller [Wed, 19 Sep 2012 14:20:11 +0000 (16:20 +0200)]
factor: more improvements

* src/factor-ng.c: Import some improvements from
http://gmplib.org:8000/factoring
Co-authored-by: Torbjörn Granlund <tg@gmplib.org>
11 years agofactor: new much-improved implementation; not yet integrated
Torbjörn Granlund [Sun, 16 Sep 2012 20:27:20 +0000 (22:27 +0200)]
factor: new much-improved implementation; not yet integrated

* src/factor-ng.c: New file, from nt-factor.
* src/longlong.h: New file.
* NEWS (Improvements): Mention the upcoming improvements.
Co-authored-by: Niels Möller
11 years agomaint: make-prime-list: syntax conventions; be robust for large N
Jim Meyering [Thu, 4 Oct 2012 18:27:31 +0000 (20:27 +0200)]
maint: make-prime-list: syntax conventions; be robust for large N

* src/make-prime-list.c: Insert spaces before parens.
(main): Abort if the 8-delta value ever exceeds 255.

11 years agomaint: make-prime-list: do not ignore write failure
Jim Meyering [Sun, 23 Sep 2012 09:33:01 +0000 (11:33 +0200)]
maint: make-prime-list: do not ignore write failure

Even though this is just a helper program that is run solely to create
primes.h, it should not ignore a write failure.  Normally we would
simply call atexit (close_stdout), but we cannot do that from this
helper program, since it must be built before the generated header,
primes.h.  If we were to make the linking of make-prime-list depend
on libcoreutils.a, that would add all lib/*.o files to the list
of dependents of $(BUILT_HEADERS).  Then, since there is currently no
provision to ensure that a file like lib/stdio.h (another built header)
is built before the first lib/*.o file that also includes <stdio.h>,
some lib/*.o files would be built before lib/stdio.h and some after.
The former would provoke link failures due to undefined rpl_* functions.
* src/make-prime-list.c: Include <errno.h>.
(fclose): Undef, so that a definition to rpl_fclose does not
cause a link failure.
(main): Per the above, in this exceptional case, we check for fclose
and ferror failure manually, and don't worry about the ferror-only
failure case in which errno may not be relevant.

11 years agomaint: make-prime-list: avoid -Wsuggest-attribute=const warning
Jim Meyering [Wed, 19 Sep 2012 09:07:41 +0000 (11:07 +0200)]
maint: make-prime-list: avoid -Wsuggest-attribute=const warning

* src/make-prime-list.c: Include <config.h>.
(binvert): Add _GL_ATTRIBUTE_CONST.

11 years agofactor: prepare for the new factor program
Torbjörn Granlund [Sun, 16 Sep 2012 19:59:40 +0000 (21:59 +0200)]
factor: prepare for the new factor program

* src/make-prime-list.c: New file, from nt-factor.
Co-authored-by: Niels Möller <nisse@lysator.liu.se>
11 years agobuild: remove redundant dependency: $(PROGRAMS): lib/libcoreutils.a
Jim Meyering [Tue, 18 Sep 2012 19:57:38 +0000 (21:57 +0200)]
build: remove redundant dependency: $(PROGRAMS): lib/libcoreutils.a

* src/local.mk: Remove the above dependency.
A soon-to-be-added new program, make-prime-list, must not depend
on that, since it is used to create a BUILT_SOURCES file.
That dependency is already handled via the ..._LD_ADD variables,
and so that redundant dependency has so far been harmless.

11 years agodu: avoid abort on systems for which ->me_type is not malloc'd
Jim Meyering [Sun, 30 Sep 2012 12:28:47 +0000 (14:28 +0200)]
du: avoid abort on systems for which ->me_type is not malloc'd

On some systems (notably, BSD-based, like at least OpenBSD 4.9),
the me_type member does not come from the heap.
* src/du.c (fill_mount_table): Free the ->me_type member only
when it was malloc'd, i.e., when ->me_type_malloced is nonzero.
Bug introduced via commit v8.19-2-gcf7e1b5.
Reported as http://bugs.gnu.org/12542.

11 years agodoc: same correction, but now in texinfo documentation
Jim Meyering [Sat, 29 Sep 2012 12:56:13 +0000 (14:56 +0200)]
doc: same correction, but now in texinfo documentation

* doc/coreutils.texi (nice invocation): s/nicenesses/niceness values/

11 years agodoc: correct an old bit of ugliness in nice --help output
Jim Meyering [Fri, 28 Sep 2012 16:42:05 +0000 (18:42 +0200)]
doc: correct an old bit of ugliness in nice --help output

* src/nice.c (usage): s/Nicenesses/Niceness values/

11 years agodoc: disambiguate the niceness explanation in nice --help
Pádraig Brady [Fri, 28 Sep 2012 16:13:57 +0000 (17:13 +0100)]
doc: disambiguate the niceness explanation in nice --help

* src/nice.c (usage): Specify the entity (process) that
that relative terms are referring to.
* THANKS: Update.
Reported-by: David Diggles
11 years agocp: fix the --no-preserve=mode option
Ondrej Oprala [Tue, 7 Aug 2012 14:56:52 +0000 (16:56 +0200)]
cp: fix the --no-preserve=mode option

The --no-preserve=mode option did not do what its name implies:
it would mistakenly preserve permission mode bits.
* NEWS: Mention the fix.
* TODO: Remove an entry.
* src/copy.c (copy_reg): Add a condition to properly
handle the --no-preserve=mode option for files
(copy_internal): Add a condition to properly handle the
--no-preserve=mode option for directories.
* src/copy.h (struct cp_options): Add a new boolean.
* src/cp.c (cp_option_init,decode_preserve_arg): Set the
new boolean value according to specified options.
* src/install.c (struct cp_options): Initialize the new boolean.
* src/mv.c (struct cp_options): Initialize the new boolean.
* tests/cp/preserve-mode.sh: Add a new test.
* tests/cp/link-preserve.sh (-a --no-preserve=mode): Adjust the
expected perms: now, --no-preserve=mode overrides the --preserve=mode
that is inherent in -a, as it should.
* tests/local.mk: Add the new test to the list.

11 years agotimeout: handle signals more transparently
Pádraig Brady [Wed, 12 Sep 2012 02:21:11 +0000 (03:21 +0100)]
timeout: handle signals more transparently

This was originally attempted in commit v8.12-117-g5a647a0,
but reverted before release because of the unreliability
of disabling core dumps using setrlimit() on Linux kernels.
This new version instead uses prctl() where available to
more reliably disable core dumps for the timeout process.

* m4/jm-macros.m4: Define HAVE_SETRLIMIT and HAVE_PRCTL.
* src/timeout.c (disable_core_dumps): A new function
that disables coredumps using prctl or setrlimit if available.
(main): If the child exited with a signal and we can
disable core dumps, then raise that signal to the timeout
process itself, so that callers may also see the signal status.
Also print a message indicating when the monitored command
dumped core, as that information is lost in the signal
propagation through timeout.

11 years agodd: new option, status=none to suppress output statistics
Pozsár Balázs [Mon, 24 Sep 2012 01:39:09 +0000 (02:39 +0100)]
dd: new option, status=none to suppress output statistics

* src/dd.c (STATUS_NONE): A new bitmask combining all STATUS_
options, thus used to suppress all informational output.
(struct symbol_value statuses): Expose the "none" option,
corresponding to the STATUS_NONE bitmask above.
(print_stats): Return early if STATUS_NONE is specified.
Also move the call to gethrxtime() down so that it's only
called when needed.
(usage): Describe the new options.
* doc/coreutils.texi (dd invocation): Likewise.
* NEWS: Mention the new feature.
* tests/dd/misc.sh: Ensure the new option works.

11 years agotail,stat: improve support for vmhgfs
Jim Meyering [Wed, 19 Sep 2012 19:52:05 +0000 (21:52 +0200)]
tail,stat: improve support for vmhgfs

Teach tail -f that it must use polling on vmhgfs file systems, and
let stat -f --format=%T report the file system type name, "vmhgfs".
* src/stat.c (human_fstype): Add a case: vmhgfs, 0xbacbacbc, remote.
* NEWS (Improvements): Mention it.
* THANKS.in: Update.
Reported by Daniel Tschinder in http://bugs.gnu.org/12461.

11 years agobuild: move non-recursive-gnulib-prefix-hack to gnulib; update
Jim Meyering [Thu, 20 Sep 2012 15:47:25 +0000 (17:47 +0200)]
build: move non-recursive-gnulib-prefix-hack to gnulib; update

I've moved the non-recursive-gnulib-prefix-hack module to
gnulib, with two small improvements, so remove it from here
and update gnulib to the latest.
* gl/build-aux/prefix-gnulib-mk: Remove file.
* gl/m4/non-recursive-gnulib-prefix-hack.m4: Remove file.
* gl/modules/non-recursive-gnulib-prefix-hack: Remove file.
* gnulib: Update to latest.

11 years agorm: be even more careful when using a replacement errno value
Jim Meyering [Wed, 19 Sep 2012 07:35:12 +0000 (09:35 +0200)]
rm: be even more careful when using a replacement errno value

* src/remove.c (excise): The change in commit v8.19-107-gccbd3f3 made
the "rm -rf D" (for unreadable dir, D) diagnostic worse on Solaris 10:
  -rm: cannot remove 'D': Permission denied
  +rm: cannot remove 'D': File exists
That happened because unlinkat would fail with EEXIST there, given
an unreadable directory, which made the two tests, tests/rm/unread2
and tests/rm/unreadable fail.  Accommodate the EEXIST case, too.

11 years agomaint: fix a comment typo
Jim Meyering [Wed, 19 Sep 2012 05:52:25 +0000 (07:52 +0200)]
maint: fix a comment typo

* cfg.mk: Fix comment typo: s/recursive/non-recursive/ make

11 years agotests: cp/link-heap: avoid new failure on rawhide
Jim Meyering [Tue, 18 Sep 2012 21:05:42 +0000 (23:05 +0200)]
tests: cp/link-heap: avoid new failure on rawhide

* tests/cp/link-heap.sh: Increase virtual memory limit by 2000KiB --
from 20,000 to 22,000 KiB -- to avoid a new failure on rawhide.

11 years agomaint: make the tight-scope syntax-check rule work again
Jim Meyering [Tue, 18 Sep 2012 14:29:49 +0000 (16:29 +0200)]
maint: make the tight-scope syntax-check rule work again

* cfg.mk: Configure a few variable to make the tight-scope rule work.
* gnulib: Update submodule to latest.

11 years agodd: remove references to the word BLOCKS from help and texi docs
Benno Schulenberg [Tue, 18 Sep 2012 12:58:42 +0000 (14:58 +0200)]
dd: remove references to the word BLOCKS from help and texi docs

The renaming from BLOCKS to N was done in v8.15-38-g140eca1,
and documentation for N was added again in v8.17-26-g4f2e9d5
without noticing that.  Now, finally remove the word BLOCKS
from the documentation.

* src/dd.c (usage): Remove the word BLOCKS.
* doc/coreutils.texi (dd invocation): Likewise.

Improved by: Bernhard Voelker <mail@bernhard-voelker.de>

11 years agodoc: NEWS: mention the conversion to non-recursive make
Jim Meyering [Sun, 16 Sep 2012 19:46:17 +0000 (21:46 +0200)]
doc: NEWS: mention the conversion to non-recursive make

* NEWS (Build-related): Mention the non-recursive make improvement.
Improved by: Pádraig Brady

11 years agols: fix coloring of dangling symlinks in default listing mode
Pádraig Brady [Sun, 16 Sep 2012 03:10:50 +0000 (04:10 +0100)]
ls: fix coloring of dangling symlinks in default listing mode

When listing a directory containing dangling symlinks,
and not outputting a long format listing, and orphaned links
are set to no coloring in LS_COLORS, then the symlinks
would get no color rather than reverting to the standard
symlink color.  The issue was introduced in v8.13-19-g84457c4

* src/ls.c (print_color_indicator): Use the standard method
to check if coloring is specified for orphaned symlinks.
The existing method would consider 'or=00' or 'or=0' as significant
in LS_COLORS. Even 'or=' was significant as in that case the
string='or=' and the length=0.  Also apply the same change
for missing symlinks for consistency.
(gobble_file): Remove the simulation of linkok, which is only
tested in print_color_indicator() which now handles this directly
by keying on the LS_COLORS values correctly.
* tests/misc/ls-misc.pl: Add a test case.
* THANKS: Add the reporter.
* NEWS: Mention the fix.
Reported-by: David Matei
11 years agodoc: update seq description
Jim Meyering [Sat, 15 Sep 2012 06:09:18 +0000 (08:09 +0200)]
doc: update seq description

* doc/coreutils.texi (seq invocation): Update an example and mention
that with the new constraints, seq can print arbitrarily large numbers.

11 years agoseq: enable the fast integer printing code in more cases
Pádraig Brady [Fri, 14 Sep 2012 13:21:03 +0000 (14:21 +0100)]
seq: enable the fast integer printing code in more cases

* src/seq.c (main): Adjust the initial arbitrary precision
seq_fast enablement checks to be more maintainable, and
a little more general, by allowing single character
separators to use seq_fast.
Also check again after the number arguments are processed,
to see if we can still use seq_fast, which while not
allowing arbitarly large integers, it will handle
integers of the form 10E10 etc.
(seq_fast): Use a specified separator character,
rather than hardcoding '\n'.

11 years agobuild: do not rely on automake's AM_TESTS_ENVIRONMENT
Jim Meyering [Fri, 14 Sep 2012 17:38:33 +0000 (19:38 +0200)]
build: do not rely on automake's AM_TESTS_ENVIRONMENT

* tests/local.mk (TESTS_ENVIRONMENT): Rename from AM_TESTS_ENVIRONMENT,
since it is not honored in automake-1.11.3 after all.
This reverts commit v8.19-38-g34c9c8f.  For now, I'll leave
the following commit that made bootstrap.conf require 1.11.2.
Prompted by a report of test failure from Pádraig Brady.

11 years agobuild: don't prefix the RHS of "GPERF = ..." with "lib/"
Jim Meyering [Fri, 14 Sep 2012 16:19:39 +0000 (18:19 +0200)]
build: don't prefix the RHS of "GPERF = ..." with "lib/"

* gl/build-aux/prefix-gnulib-mk (prefix_assignment): Exempt
the RHS of a "GPERF = ..." assignment from lib/ prefixing.

11 years agoseq: 70x faster for non-negative whole numbers and incr==1
Jim Meyering [Thu, 13 Sep 2012 16:09:49 +0000 (18:09 +0200)]
seq: 70x faster for non-negative whole numbers and incr==1

Handle non-negative whole numbers robustly and efficiently when
the increment is 1 and when no format-changing option is specified.
On the correctness front, for very large numbers, seq now works fine:

    $ b=1000000000000000000000000000
    $ src/seq ${b}09 ${b}11
    100000000000000000000000000009
    100000000000000000000000000010
    100000000000000000000000000011

while the old one would infloop, printing garbage:

    $ seq ${b}09 ${b}11 | head -2
    99999999999999999997315645440
    99999999999999999997315645440

The new code is much more efficient, too:
Old vs new: 55.81s vs 0.82s

  $ env time --f=%e seq $((10**8)) > /dev/null
  55.81
  $ env time --f=%e src/seq $((10**8)) > /dev/null
  0.82

* seq.c (incr): New function, inspired by the one in cat.c.
(cmp, seq_fast): New functions, inspired by code in nt-factor
by Torbjörn Granlund and Niels Möller.
(trim_leading_zeros): New function, without which cmp would malfunction.
(all_digits_p): New function.
(main): Hoist the format_str-vs-equal_width check to precede first
treatment of operands, and insert code to call seq_fast when possible.
* NEWS (Bug fixes): Mention the correctness fix.
(Improvements): Mention the speed-up.
* tests/misc/seq.pl: Exercise the new code.

Improved by: Bernhard Voelker.
http://thread.gmane.org/gmane.comp.gnu.coreutils.general/3340

11 years agotests: reenable "make -C tests ..." commands
Jim Meyering [Fri, 14 Sep 2012 07:25:33 +0000 (09:25 +0200)]
tests: reenable "make -C tests ..." commands

The README-documented way to run individual tests was invalidated
by the conversion of tests/ to non-recursive make.  Add a GNUmakefile
shim to reenable that usage.
* tests/GNUmakefile: New file, so that "make -C tests ..." works
like it did before the conversion of tests/ to non-recursive build.
Reported by Bernhard Voelker.
* Makefile.am (EXTRA_DIST): Add it.
* cfg.mk (sc_prohibit_tab_based_indentation): Also exempt any
GNUmakefile from this syntax-check.

11 years agobuild: fixup: correctly recognize if perl is missing
Stefano Lattarini [Tue, 11 Sep 2012 21:35:31 +0000 (23:35 +0200)]
build: fixup: correctly recognize if perl is missing

* configure.ac: Here, by adding a missing '*' to the wildcard in
a 'case' construct over the contents of $PERL.  Introduced in
commit v8.19-41-g00f5ba1.

11 years agomaint: mbsalign.h: fix typo from previous comment edit
Bernhard Voelker [Tue, 11 Sep 2012 21:57:25 +0000 (23:57 +0200)]
maint: mbsalign.h: fix typo from previous comment edit

* gl/lib/mbsalign.h: Fix comment typo.

11 years agobuild: build lib/ using non-recursive make
Jim Meyering [Sun, 9 Sep 2012 06:21:16 +0000 (08:21 +0200)]
build: build lib/ using non-recursive make

* bootstrap.conf (gnulib_modules): Use the new module.
(bootstrap_post_import_hook): Invoke prefix-gnulib-mk.
* configure.ac (AC_CONFIG_FILES): Remove lib/Makefile.
* lib/Makefile.am: Renamed...
* lib/local.mk: ...to this.
* src/local.mk (CLEANFILES): Append, don't set.
(noinst_LIBRARIES): Likewise.
(AM_CPPFLAGS): Don't set this here.
* Makefile.am (AM_CPPFLAGS): Define here instead.
(noinst_LIBRARIES, CLEANFILES, MOSTLYCLEANDIRS, MOSTLYCLEANFILES):
Initialize here, so we can append to them from each included local.mk
(SUBDIRS): Remove "lib".

11 years agobuild: handle @ALLOCA@-vs-non-recursive make problems
Jim Meyering [Sun, 9 Sep 2012 19:49:42 +0000 (21:49 +0200)]
build: handle @ALLOCA@-vs-non-recursive make problems

Here is a good reason to avoid alloca with non-recursive make.  These:

    $ grep @ALLOCA lib/gnulib.mk
    lib_libcoreutils_a_LIBADD += lib/@ALLOCA@
    lib_libcoreutils_a_DEPENDENCIES += lib/@ALLOCA@

would lead to this, when @ALLOCA@ expands to the empty string,
which is essentially "always", now:

    $ grep ' lib/$' Makefile
    lib_libcoreutils_a_LIBADD = $(gl_LIBOBJS) lib/
    lib_libcoreutils_a_DEPENDENCIES = $(gl_LIBOBJS) lib/

Tell the prefix-adding script not to add a prefix when the word it's
prefixing is "@ALLOCA@".  That is fine for most cases, but what about
when the expansion of @ALLOCA@ is nonempty?

* build-aux/prefix-gnulib-mk (prefix_word): Exclude @ALLOCA@.
* gl/m4/non-recursive-gnulib-prefix-hack.m4: Prefix non-empty
$ALLOCA with "lib/".  FIXME: I'm not sure this is required,
now that we...
Use AC_CONFIG_LIBOBJ_DIR([lib]).
Without using AC_CONFIG_LIBOBJ_DIR([lib]), automake (not autoconf)
would complain of failure to find aclocal.c, due to the use of
AC_LIBSOURCES(alloca.c).

11 years agobuild: new module to convert lib/ to non-recursive make
Jim Meyering [Mon, 10 Sep 2012 14:38:03 +0000 (16:38 +0200)]
build: new module to convert lib/ to non-recursive make

* gl/modules/non-recursive-gnulib-prefix-hack: New module.
* gl/m4/non-recursive-gnulib-prefix-hack.m4:
(gl_NON_RECURSIVE_GNULIB_PREFIX_HACK): This is the snippet
that this module inserts near the end of configure.
* gl/build-aux/prefix-gnulib-mk: New script, from bison.
Changes from the code in bison:
(prefix_assignment): Split a long line.
(prefix): Add trailing slashes to avoid a single false match.
Prefix imaxtostr.c and the other *tostr.c file names manually.
Also, use $prefix in place of hard-coded "lib/".

11 years agomaint: gen-lists-of-programs.sh: fix typo from previous comment edit
Bernhard Voelker [Tue, 11 Sep 2012 06:53:56 +0000 (08:53 +0200)]
maint: gen-lists-of-programs.sh: fix typo from previous comment edit

* build-aux/gen-lists-of-programs.sh: Fix comment typo.

11 years agomaint: add more control flags to mbsalign
Pádraig Brady [Tue, 4 Sep 2012 12:12:23 +0000 (13:12 +0100)]
maint: add more control flags to mbsalign

* gl/lib/mbsalign.h: Add MBA_UNIBYTE_ONLY (to allow
faster processing).  Also add MBA_NO_LEFT_PAD, MBA_NO_RIGHT_PAD
to give greater control of padding, useful with the first
or last fields on a line.
* gl/lib/mbsalign.c (mbsalign): Implement the new flags.
* gl/tests/test-mbsalign.c (main): Test combinations
of the new flags.

11 years agomaint: allow per-directory CFLAGS settings with non-recursive make
Jim Meyering [Sat, 8 Sep 2012 19:17:32 +0000 (21:17 +0200)]
maint: allow per-directory CFLAGS settings with non-recursive make

* src/local.mk (AM_CFLAGS): Don't use $(WARN_CFLAGS) here.
* cfg.mk (src_CFLAGS, lib_CFLAGS, gnulib-tests_CFLAGS): Define here
instead.
(AM_CFLAGS): Augment using the above.
* configure.ac: Note that the configure-time option,
--enable-gcc-warnings now functions only when using GNU make.
Well, currently it does still work in gnulib-tests, but that should
soon be fixed.
Improved-by: Stefano Lattarini
11 years agomaint: gen-lists-of-programs.sh: improve comments
Jim Meyering [Mon, 10 Sep 2012 09:00:35 +0000 (11:00 +0200)]
maint: gen-lists-of-programs.sh: improve comments

* build-aux/gen-lists-of-programs.sh: Improve comments.

11 years agobuild: do not require help2man at build-from-tarball time
Jim Meyering [Sun, 9 Sep 2012 17:27:25 +0000 (19:27 +0200)]
build: do not require help2man at build-from-tarball time

But do retain full dependencies when building from a git clone.
We do this by converting the full dependency (of the .1 file on
the binary we run with --help) into a dependency on the .c file.
* Makefile.am (do-not-require-help2man): New rule.
(dist-hook): depend on it.

11 years agobuild: fix a minor man-page generation dependency error
Jim Meyering [Sun, 9 Sep 2012 17:23:11 +0000 (19:23 +0200)]
build: fix a minor man-page generation dependency error

* man/local.mk (man/dir.1): Depend on src/dir, not src/ls.

11 years agomaint: move the last coreutils-specific files from lib/ to gl/
Jim Meyering [Sat, 8 Sep 2012 13:11:20 +0000 (15:11 +0200)]
maint: move the last coreutils-specific files from lib/ to gl/

Convert the few remaining coreutils-specific files in lib/ to
gnulib-style modules under gl/, removing their corresponding .m4
files, since the information recorded in those files is better
stored in module-description file in gl/modules/.
* bootstrap.conf (gnulib_modules): Add new modules:
fd-reopen, buffer-lcm, xfts, strnumcmp.
* gl/lib/buffer-lcm.c: Renamed from the file in lib/.
* gl/lib/buffer-lcm.h: Likewise.
* gl/lib/fd-reopen.c: Likewise.
* gl/lib/fd-reopen.h: Likewise.
* gl/lib/strintcmp.c: Likewise.
* gl/lib/strnumcmp-in.h: Likewise.
* gl/lib/strnumcmp.c: Likewise.
* gl/lib/strnumcmp.h: Likewise.
* gl/lib/xfts.c: Likewise.
* gl/lib/xfts.h: Likewise.
* gl/modules/buffer-lcm: New module-description file.
* gl/modules/fd-reopen: Likewise.
* gl/modules/strnumcmp: Likewise.
* gl/modules/xfts: Likewise.
* m4/fd-reopen.m4: Remove, no longer needed.
* m4/strnumcmp.m4: Likewise.
* m4/xfts.m4: Likewise.
* m4/prereq.m4: Do not AC_REQUIRE the m4 functions from
our just-removed m4/*.m4 files.

11 years agomaint: move gl/m4/root-dev-ino.m4 contents into its module definition
Jim Meyering [Sat, 8 Sep 2012 14:01:47 +0000 (16:01 +0200)]
maint: move gl/m4/root-dev-ino.m4 contents into its module definition

We can get the same effect using the modules file.
* gl/m4/root-dev-ino.m4: Remove file.
* gl/modules/root-dev-ino (Depends-on): Add lstat.
(Files): Remove m4/root-dev-ino.m4.
(Makefile.am) [lib_SOURCES]: Add root-dev-ino.c and root-dev-ino.h.
(configure.ac): Remove reference to gl_ROOT_DEV_INO.

11 years agomaint: adjust ChangeLog to correct Author
Jim Meyering [Fri, 7 Sep 2012 10:08:42 +0000 (12:08 +0200)]
maint: adjust ChangeLog to correct Author

* build-aux/git-log-fix: Add an entry to correct the Author:
of v8.19-111-g51a4b04.  It should be Ondrej Oprala, not me.

11 years agofactor: NEWS and tests
Jim Meyering [Tue, 4 Sep 2012 16:26:25 +0000 (18:26 +0200)]
factor: NEWS and tests

* NEWS (Bug fixes): Mention it.
* tests/misc/factor.pl: Add five of Torbjörn's tests.

11 years agofactor: don't ever declare composites to be prime
Torbjörn Granlund [Tue, 4 Sep 2012 16:38:29 +0000 (18:38 +0200)]
factor: don't ever declare composites to be prime

The multiple-precision factoring code (with HAVE_GMP) was copied from
a now-obsolete version of GMP that did not pass proper arguments to
the mpz_probab_prime_p function.  It makes that code perform no more
than 3 Miller-Rabin tests only, which is not sufficient.

A Miller-Rabin test will detect composites with at least a probability
of 3/4.  For a uniform random composite, the probability will actually
be much higher.

Or put another way, of the N-3 possible Miller-Rabin tests for checking
the composite N, there is no number N for which more than (N-3)/4 of the
tests will fail to detect the number as a composite.  For most numbers N
the number of "false witnesses" will be much, much lower.

Problem numbers are of the form N=pq, p,q prime and (p-1)/(q-1) = s,
where s is a small integer.  (There are other problem forms too,
involving 3 or more prime factors.)  When s = 2, we get the 3/4 factor.

It is easy to find numbers of that form that cause coreutils' factor to
fail:

  465658903
  2242724851
  6635692801
  17709149503
  17754345703
  20889169003
  42743470771
  54890944111
  72047131003
  85862644003
  98275842811
  114654168091
  117225546301
  ...

There are 9008992 composites of the form with s=2 below 2^64.  With 3
Miller-Rabin tests, one would expect about 9008992/64 = 140766 to be
invalidly recognized as primes in that range.

* src/factor.c (MR_REPS): Define to 25.
(factor_using_pollard_rho): Use MR_REPS, not 3.
(print_factors_multi): Likewise.
* THANKS.in: Remove my name, now that it will be automatically
included in the generated THANKS file.

11 years agotests: improve checks for setuidgid-using root-only tests
Jim Meyering [Thu, 6 Sep 2012 10:00:16 +0000 (12:00 +0200)]
tests: improve checks for setuidgid-using root-only tests

* init.cfg (setuidgid_has_perm_): New function.
(require_root_): Use it.
Improved-by: Bernhard Voelker
* NEWS (Build-related): Mention the improvement.

11 years agobuild: default to --enable-gcc-warnings for git tree
Eric Blake [Thu, 6 Sep 2012 14:20:17 +0000 (08:20 -0600)]
build: default to --enable-gcc-warnings for git tree

Anyone developing on coreutils can be assumed to have a new enough
environment, such that enabling gcc warnings by default will be
useful.  Tarballs still default to no warnings, and the defaults
can still be overridden with --disable-gcc-warnings.

* configure.ac (gl_gcc_warnings): Set default based on environment.
Suggested by Bernhard Voelker.

11 years agonproc: disallow non option command line parameters
Pádraig Brady [Thu, 6 Sep 2012 09:34:00 +0000 (10:34 +0100)]
nproc: disallow non option command line parameters

* src/nproc.c (main): Error if any non option parameters.
* NEWS: Mention the change in behavior.

11 years agotail,stat: add support for VZFS
Jim Meyering [Wed, 5 Sep 2012 20:33:44 +0000 (22:33 +0200)]
tail,stat: add support for VZFS

* src/stat.c (human_fstype): Add a case: vzfs, 0x565A4653 (local).
Reported by Jens Rosenboom in http://bugs.gnu.org/12356
* NEWS (Improvement): Mention it.

11 years agorm: be more careful when using a replacement errno value
Jim Meyering [Wed, 5 Sep 2012 14:48:50 +0000 (16:48 +0200)]
rm: be more careful when using a replacement errno value

* src/remove.c (excise): Tighten the test for when we defer to an
old errno value: instead of relying solely on an FTS_DNR (unreadable
directory) failure, also test current and replacement errno values.
This change would also have solved the problem addressed by commit
v8.19-106-g57dd067.  For more info, see http://bugs.gnu.org/12339#113

11 years agorm: avoid bogus diagnostic for a slash-decorated symlink-to-dir
Jim Meyering [Tue, 4 Sep 2012 12:40:11 +0000 (14:40 +0200)]
rm: avoid bogus diagnostic for a slash-decorated symlink-to-dir

These commands would evoke an invalid diagnostic:
    $ mkdir d && ln -s d s && env rm -r s/
    rm: cannot remove 's': Too many levels of symbolic links
remove.c was stripping trailing slashes from "s/" before passing
the name to "rm".  But a trailing slash may change the semantics,
and thus should not be stripped.
* src/remove.c (rm_fts): Do not strip trailing slashes.
* tests/rm/v-slash.sh: Adapt to new expected output.
* gnulib: Update to latest, for an improved fts.c that merely
normalizes trailing slashes.
Reported by Paul Eggert in discussion of http://bugs.gnu.org/12339

11 years agotests: depend on the programs we're testing
Jim Meyering [Tue, 4 Sep 2012 10:12:19 +0000 (12:12 +0200)]
tests: depend on the programs we're testing

* tests/local.mk ($(TEST_LOGS)): Depend on $(PROGRAMS), so that
tests are rerun when any program is rebuilt.  Technically, we could
specify precisely which few programs are dependents of each test,
but that can come later, if deemed worth the trouble and maintenance
burden.  Also, there is the issue of the primary program(s) being
tested (i.e., those itemized via print_ver_) versus those that are
tested incidentally: for example, nearly every test exercises "rm"
when its clean-up code removes files.

11 years agomaint: fix a spurious syntax-check failure
Stefano Lattarini [Sun, 2 Sep 2012 19:55:19 +0000 (21:55 +0200)]
maint: fix a spurious syntax-check failure

* cfg.mk (exclude_file_name_regexp--sc_file_system): Exempt
'init.cfg', not 'tests/init.cfg'.