summaryrefslogtreecommitdiff
path: root/src/truncate.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2008-06-29 01:55:03 +0100
committerJim Meyering <meyering@redhat.com>2008-06-30 10:23:17 +0200
commit760bc6f7e73014e934a744a9d46ea8dbf5ba25c8 (patch)
treed223895de4241de31247bc2034516340ebe0d089 /src/truncate.c
parent9396eb903752ad4a1375235f62dcb094a5ae2cf0 (diff)
downloadcoreutils-760bc6f7e73014e934a744a9d46ea8dbf5ba25c8.tar.xz
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.
Diffstat (limited to 'src/truncate.c')
-rw-r--r--src/truncate.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/truncate.c b/src/truncate.c
index fd321c6c5..3bc52ca14 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -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)