1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 10:51:48 +02:00

truncate: ignore whitespace in --size parameters

Without this, `truncate -s '> -1' F` would truncate F to length 0,
and `truncate -s " +1" F` would truncate F to 1 byte.  Now, each
elicits a diagnostic.
* src/truncate.c: Skip leading white space in the --size option
argument and any white space after one of the relative modifiers,
so that the presence of a +/- modifier can be detected reliably.
* tests/misc/truncate-parameters: Add tests for the above.
This commit is contained in:
Pádraig Brady
2008-06-29 01:55:03 +01:00
committed by Jim Meyering
parent 9396eb9037
commit 760bc6f7e7
2 changed files with 12 additions and 0 deletions

View File

@@ -286,6 +286,9 @@ main (int argc, char **argv)
break;
case 's':
/* skip any whitespace */
while (isspace (*optarg))
optarg++;
switch (*optarg)
{
case '<':
@@ -305,6 +308,9 @@ main (int argc, char **argv)
optarg++;
break;
}
/* skip any whitespace */
while (isspace (*optarg))
optarg++;
if (*optarg == '+' || *optarg == '-')
{
if (rel_mode)