Pádraig Brady <[EMAIL PROTECTED]> wrote: > Take 2 attached Thanks! I've looked through the tests (thanks for writing so many!) marked a few things with FIXME comments, fixed some "exit..." lines (that matters for portability wrt traps), and adjusted nit-picky comment syntax ;-)
Here are a few more syntactic changes (just apply and amend; no need to attribute). Note that ChangeLog files are no longer manually updated. diff --git a/ChangeLog-2008 b/ChangeLog-2008 index 5de93c6..aac9feb 100644 --- a/ChangeLog-2008 +++ b/ChangeLog-2008 @@ -1,27 +1,3 @@ -2008-03-26 Pádraig Brady <[EMAIL PROTECTED]> - - Add new program: truncate - * AUTHORS: Register as the author - * NEWS: Mention this change - * README: Add truncate command to list - * src/truncate.c: New command - * src/Makefile.am: Add truncate command to list to build - * doc/coreutils.texi (truncate invocation): Add truncate info - * man/Makefile.am: Add truncate man page to list to build - * man/truncate.x: Add truncate man page template - * po/POTFILES.in: Add truncate to list to translate - * tests/misc/Makefile.am: Add truncate tests - * tests/misc/help-version: Add support for new truncate command - * tests/misc/truncate-dangling-symlink: check dangling link ok - * tests/misc/truncate-dir-fail: ensure dirs fail - * tests/misc/truncate-fail-diag: validate messages for missing paths - * tests/misc/truncate-fifo: ensure fifos ignored - * tests/misc/truncate-no-create-missing: ensure -c option honoured - * tests/misc/truncate-overflow: check signed integer overflows - * tests/misc/truncate-owned-by-other: root permissions check - * tests/misc/truncate-parameters: check invalid parameter combinations - * tests/misc/truncate-relative: check invalid relative sizes - 2008-02-07 Jim Meyering <[EMAIL PROTECTED]> We *do* need two different version files. diff --git a/src/truncate.c b/src/truncate.c index 639c52c..90962a2 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -23,7 +23,7 @@ Note if !defined(HAVE_FTRUNCATE) then the --skip-ftruncate configure flag was specified or we're in a mingw environment. In these cases gnulib emulation will be used and GNULIB_FTRUNCATE is defined. Note if emulation - can't even be provided ftruncate() will return EIO. */ + can't even be provided ftruncate() will return EIO. */ #include <config.h> /* sets _FILE_OFFSET_BITS=64 etc. */ #include <stdio.h> @@ -36,13 +36,12 @@ #include "quote.h" #include "xstrtol.h" - /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "truncate" #define AUTHORS "Padraig Brady" -/* The name by which this program was run. */ +/* The name by which this program was run. */ char *program_name; /* (-c) If true, don't create if not already there. */ @@ -69,8 +68,7 @@ typedef enum Return -1 on error, 0 on success. This supports dd BLOCK size suffixes + lowercase g,t,m for bsd compat - Note we don't support dd's b=512, c=1, w=2 or 21x512MiB formats -*/ + Note we don't support dd's b=512, c=1, w=2 or 21x512MiB formats. */ static int parse_len (const char *str, off_t *size) { @@ -202,10 +200,9 @@ main (int argc, char **argv) got_size = true; break; - case_GETOPT_HELP_CHAR; - - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + case_GETOPT_HELP_CHAR; + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: usage (EXIT_FAILURE); @@ -255,7 +252,7 @@ main (int argc, char **argv) { /* Complain only for a regular file, a directory, or a shared memory object, as POSIX 1003.1-2004 specifies - ftruncate's behavior only for these file types. */ + ftruncate's behavior only for these file types. */ if (!S_ISREG (sb.st_mode) && !S_ISDIR (sb.st_mode) && !S_TYPEISSHM (&sb)) continue; @@ -294,7 +291,7 @@ main (int argc, char **argv) { /* Complain only for a regular file, a directory, or a shared memory object, as POSIX 1003.1-2004 specifies - ftruncate's behavior only for these file types. */ + ftruncate's behavior only for these file types. */ if (S_ISREG (sb.st_mode) || S_ISDIR (sb.st_mode) || S_TYPEISSHM (&sb)) { diff --git a/tests/misc/truncate-dangling-symlink b/tests/misc/truncate-dangling-symlink index 8935361..35d24bd 100755 --- a/tests/misc/truncate-dangling-symlink +++ b/tests/misc/truncate-dangling-symlink @@ -23,6 +23,7 @@ fi . $srcdir/../test-lib.sh +# FIXME: no need to pre-remove these rm -f truncate-target t-symlink ln -s truncate-target t-symlink fail=0 @@ -30,6 +31,8 @@ fail=0 truncate -s0 t-symlink || fail=1 test -f truncate-target || fail=1 + +# FIXME: no need to clean up. test-lib.sh's trap does that. rm -f truncate-target t-symlink -exit $fail +(exit $fail); exit $fail diff --git a/tests/misc/truncate-dir-fail b/tests/misc/truncate-dir-fail index a677f4a..f01132a 100755 --- a/tests/misc/truncate-dir-fail +++ b/tests/misc/truncate-dir-fail @@ -11,4 +11,4 @@ fi # truncate on dir not allowed truncate -s+0 . && fail=1 || fail=0 -exit $fail +(exit $fail); exit $fail diff --git a/tests/misc/truncate-fail-diag b/tests/misc/truncate-fail-diag index ff7d9a2..34d54f9 100755 --- a/tests/misc/truncate-fail-diag +++ b/tests/misc/truncate-fail-diag @@ -29,12 +29,16 @@ fi . $srcdir/../test-lib.sh skip_if_root_ +# FIXME: no need for $$ or existence test. test-lib.sh ensures that each +# test is run in an empty, just-created directory. d1=no-$$ # Ensure that $d1 doesn't already exist. [ -e $d1 ] && framework_failure fail=0 +# FIXME: stray leading "/" ? +# FIXME: besides, don't use an absolute name unless needed dir=/$d1/such-dir truncate -s0 $dir > out 2>&1 && fail=1 cat <<EOF > exp @@ -42,6 +46,8 @@ truncate: cannot open \`$dir' for writing: No such file or directory EOF compare out exp || fail=1 +# FIXME: stray leading "/" ? Remove this, too. +# Do you want the trailing slash? dir=/$d1/ truncate -s0 $dir > out 2>&1 && fail=1 cat <<EOF > exp diff --git a/tests/misc/truncate-fifo b/tests/misc/truncate-fifo index 88308ff..d173249 100755 --- a/tests/misc/truncate-fifo +++ b/tests/misc/truncate-fifo @@ -23,6 +23,8 @@ fi . $srcdir/../test-lib.sh +# FIXME: rather than copying, how about creating a function in test-lib.sh, +# mkfifo_or_skip_? Then use it both here and in touch/fifo. if ! mkfifo fifo; then # Make an exception of this case -- usually we interpret framework-creation # failure as a test failure. However, in this case, when running on a SunOS @@ -35,4 +37,4 @@ fail=0 truncate -s0 fifo || fail=1 -exit $fail +(exit $fail); exit $fail diff --git a/tests/misc/truncate-no-create-missing b/tests/misc/truncate-no-create-missing index 183d77e..c49786a 100755 --- a/tests/misc/truncate-no-create-missing +++ b/tests/misc/truncate-no-create-missing @@ -25,7 +25,7 @@ fi fail=0 -#truncate -c no-such-file should not fail. +# truncate -c no-such-file should not fail. truncate -s0 -c no-such-file || fail=1 (exit $fail); exit $fail diff --git a/tests/misc/truncate-overflow b/tests/misc/truncate-overflow index 91bb48e..7471084 100755 --- a/tests/misc/truncate-overflow +++ b/tests/misc/truncate-overflow @@ -30,23 +30,23 @@ echo > non-empty-file truncate -s2147483648 -c no-such-file && _FILE_OFFSET_BITS=64 if [ $_FILE_OFFSET_BITS -eq 64 ]; then - #signed overflow + # signed overflow truncate -s9223372036854775808 file && fail=1 - #*= signed overflow + # *= signed overflow truncate --io-blocks --size="1E" file && fail=1 - #+= signed overflow + # += signed overflow truncate -s+9223372036854775807 non-empty-file && fail=1 else - #signed overflow + # signed overflow truncate -s2147483648 file && fail=1 - #*= signed overflow + # *= signed overflow truncate --io-blocks --size="1G" file && fail=1 - #+= signed overflow + # += signed overflow truncate -s+2147483647 non-empty-file && fail=1 fi -exit $fail +(exit $fail); exit $fail diff --git a/tests/misc/truncate-parameters b/tests/misc/truncate-parameters index 4d2273f..9d196ea 100755 --- a/tests/misc/truncate-parameters +++ b/tests/misc/truncate-parameters @@ -25,19 +25,19 @@ fi fail=0 -#must specify at least 1 file +# must specify at least 1 file truncate --size=0 && fail=1 -#must specify size. don't default to 0 +# must specify size. don't default to 0 truncate file && fail=1 -#mixture of size & reference not allowed +# mixture of size & reference not allowed truncate --size=0 --reference=file file && fail=1 -#blocks without size is not valid +# blocks without size is not valid truncate --io-blocks --reference=file file && fail=1 -#must specify valid numbers +# must specify valid numbers truncate --size="invalid" file && fail=1 -exit $fail +(exit $fail); exit $fail diff --git a/tests/misc/truncate-relative b/tests/misc/truncate-relative index 37f6cfc..2797be8 100755 --- a/tests/misc/truncate-relative +++ b/tests/misc/truncate-relative @@ -25,16 +25,16 @@ fi fail=0 -#mixture of relative modifiers not allowed +# mixture of relative modifiers not allowed truncate --size="+>0" file && fail=1 -#mixture of relative modifiers not allowed +# mixture of relative modifiers not allowed truncate --size=">+0" file && fail=1 -#division by zero +# division by zero truncate --size="/0" file && fail=1 -#division by zero +# division by zero truncate --size="%0" file && fail=1 -exit $fail +(exit $fail); exit $fail _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils