From: Pádraig Brady Date: Sun, 29 Jun 2008 00:55:03 +0000 (+0100) Subject: truncate: ignore whitespace in --size parameters X-Git-Tag: v7.0~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=760bc6f7e73014e934a744a9d46ea8dbf5ba25c8;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/src/truncate.c b/src/truncate.c index fd321c6c5b..3bc52ca144 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) diff --git a/tests/misc/truncate-parameters b/tests/misc/truncate-parameters index e416831905..27a22a91f4 100755 --- a/tests/misc/truncate-parameters +++ b/tests/misc/truncate-parameters @@ -40,4 +40,10 @@ truncate --io-blocks --reference=file file && fail=1 # must specify valid numbers truncate --size="invalid" file && fail=1 +# spaces not significant around size +truncate --size="> -1" file && fail=1 +truncate --size=" >1" file || fail=1 #file now 1 +truncate --size=" +1" file || fail=1 #file now 2 +test $(stat --format %s file) = 2 || fail=1 + (exit $fail); exit $fail