[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tail -c fails (coreutils 5.92)
From: |
Paul Eggert |
Subject: |
Re: tail -c fails (coreutils 5.92) |
Date: |
Tue, 01 Nov 2005 15:08:39 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Vincent Lefevre <address@hidden> writes:
> prunille:~> /opt/local/bin/gtail -c 2 blah
> /opt/local/bin/gtail: cannot open `2' for reading: No such file or directory
Thanks for reporting this. I've installed the following patch.
2005-11-01 Paul Eggert <address@hidden>
* NEWS: tail -c 2 FILE now operates as POSIX 1002.1-2001 requires.
* doc/coreutils.texi (tail invocation): Describe obsolete usages
like "tail -2" more precisely.
* src/tail.c (parse_obsolete_option): Implement this.
Problem reported by Vincent Lefevre.
* tests/tail/Test.pm (c-2, c-2-minus, c2, c2-minus): New tests.
(test_vector): Add special cases for _POSIX2_VERSION, and
regularize the old ones a bit.
--- NEWS 27 Oct 2005 19:44:45 -0000 1.332
+++ NEWS 1 Nov 2005 23:00:16 -0000
@@ -22,6 +22,10 @@ GNU coreutils NEWS
tac now works when stdin is a tty, even on non-Linux systems
+ "tail -c 2 FILE" now operates as POSIX 1003.1-2001 requires, even
+ when "tail" is conforming to older POSIX standards, as the
+ newly-mandated behavior is upward-compatible with the old.
+
** Build-related bug fixes
installing .mo files would fail
--- doc/coreutils.texi 23 Oct 2005 16:05:26 -0000 1.290
+++ doc/coreutils.texi 1 Nov 2005 23:00:19 -0000
@@ -2549,9 +2549,9 @@ Always print file name headers.
@end table
-For compatibility @command{tail} also supports an obsolete option
-syntax @address@hidden, which is recognized only if it
-is specified first and does not conflict with the usage described
+For compatibility @command{tail} also supports an obsolete usage
address@hidden address@hidden address@hidden, which is recognized
+only if it does not conflict with the usage described
above. @var{count} is an optional decimal number optionally
followed by a size letter (@samp{b}, @samp{c}, @samp{l}) to mean count
by 512-byte blocks, bytes, or lines, optionally followed by @samp{f}
--- src/tail.c 15 Oct 2005 10:15:34 -0000 1.243
+++ src/tail.c 1 Nov 2005 23:00:19 -0000
@@ -1363,7 +1363,7 @@ tail_file (struct File_spec *f, uintmax_
static bool
parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
{
- const char *p = argv[1];
+ const char *p;
const char *n_string;
const char *n_string_end;
bool obsolete_usage;
@@ -1372,13 +1372,15 @@ parse_obsolete_option (int argc, char *
bool t_count_lines = true;
bool t_forever = false;
- /* With the obsolete form, there is one option string and
- (technically) at most one file argument. But we allow two or more
- by default. */
- if (argc < 2)
+ /* With the obsolete form, there is one option string and at most
+ one file argument. Watch out for "-" and "--", though. */
+ if (! (argc == 2
+ || (argc == 3 && ! (argv[2][0] == '-' && argv[2][1]))
+ || (3 <= argc && argc <= 4 && STREQ (argv[2], "--"))))
return false;
obsolete_usage = (posix2_version () < 200112);
+ p = argv[1];
switch (*p++)
{
--- tests/tail/Test.pm 29 Apr 2005 23:51:11 -0000 1.16
+++ tests/tail/Test.pm 1 Nov 2005 23:00:19 -0000
@@ -58,6 +58,11 @@ my @tv = (
['minus-1', '-', '', '', 0],
['minus-2', '-', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
+['c-2', '-c 2', "abcd\n", "d\n", 0],
+['c-2-minus', '-c 2 --', "abcd\n", "d\n", 0],
+['c2', '-c2', "abcd\n", "d\n", 0],
+['c2-minus', '-c2 --', "abcd\n", "d\n", 0],
+
['n-1', '-n 10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
['n-2', '-n -10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
['n-3', '-n +10', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
@@ -78,17 +83,19 @@ my @tv = (
sub test_vector
{
- # With _POSIX2_VERSION=199209, `tail -c' succeeds, but err-6 expects
- # a failure, so set _POSIX2_VERSION to ensure it fails.
- $Test::env{'err-6'} = ['_POSIX2_VERSION=200112'];
-
my $t;
foreach $t (@tv)
{
my ($test_name, $flags, $in, $exp, $ret) = @$t;
- $test_name =~ /^(obs-plus-|minus-)/
- and $Test::env{$test_name} = ['_POSIX2_VERSION=199209'];
+ if ($test_name =~ /^(obs-plus-|minus-)/)
+ {
+ $Test::env{$test_name} = ['_POSIX2_VERSION=199209'];
+ }
+ if ($test_name =~ /^(err-6|c-2)$/)
+ {
+ $Test::env{$test_name} = ['_POSIX2_VERSION=200112'];
+ }
# If you run the minus* tests with a FILE arg they'd hang.
# If you run the err-1 or err-3 tests with a FILE, they'd misinterpret