summaryrefslogtreecommitdiff
path: root/src/truncate.c
AgeCommit message (Collapse)Author
2012-08-04truncate: don't leak a file descriptor with --ref=PIPEJim Meyering
* src/truncate.c (main): For a user who makes the mistake of using a non-seekable file as a reference for the desired length, truncate would open that file, attempt to seek to its end, but upon seek failure would neglect to close the file descriptor. Close the file descriptor even when lseek fails. In addition, ignore failure to close that reference FD, since as long as the lseek succeeds, a close failure doesn't matter. Coverity spotted the potential FD leak. Improved-by: Pádraig Brady.
2012-06-22maint: refactor common mode bits used to create filesPádraig Brady
* src/system.h (MODE_RW_UGO): The new refactored define (666). * src/mkfifo.c: Use the new define. * src/mknod.c: Likewise. * src/split.c: Likewise. * src/system.h: Likewise. * src/touch.c: Likewise. * src/truncate.c: Likewise. Suggested-by: Jim Meyering
2012-05-10maint: handle file sizes more reliablyPaul Eggert
Problem reported by Samuel Thibault in <http://bugs.gnu.org/11424>. * NEWS: Document this. * src/dd.c (skip): Handle skipping past EOF on shared or typed memory objects the same way as with regular files. (dd_copy): It's OK to truncate shared memory objects. * src/du.c (duinfo_add): Check for overflow. (print_only_size): Report overflow. (process_file): Ignore negative file sizes in the --apparent-size case. * src/od.c (skip): Fix comment about st_size. * src/split.c (main): * src/truncate.c (do_ftruncate, main): On files where st_size is not portable, fall back on using lseek with SEEK_END to determine the size. Although strictly speaking POSIX says the behavior is implementation-defined, in practice if lseek returns a nonnegative value it's a reasonable one to use for the file size. * src/system.h (usable_st_size): Symlinks have reliable st_size too. * tests/misc/truncate-dir-fail: Don't assume that getting the size of a dir is not allowed, as it's now allowed on many platforms, e.g., GNU/Linux.
2012-01-09maint: src/*.c: change remaining quotes (without embedded spaces)Jim Meyering
Run this (twice): git grep -E -l '`[^ ]+'\' src/*.c \ |xargs perl -pi -e 's/`([^ ]+'\'')/'\''$1/'
2012-01-09maint: convert `...' to '...' in --help outputJim Meyering
All affected lines end with \ or \n\, so run this command until it produces no new changes (4 times): git grep -E -l '`[^ ]+'\''.*\\' src \ |xargs perl -pi -e 's/`([^ ]+'\''.*\\)/'\''$1/'
2012-01-09maint: prep for global quoting changes: handle irregular cases manuallyJim Meyering
* src/chroot.c (usage): Change ``...'' to '...', and describe the default more accurately (also adding quotes): s,/bin/sh,'/bin/sh -i', * src/join.c (usage): Change ` ...'' ' to "...''". * src/fmt.c (isopen): Change `' to '` in list of bytes, so that a subsequent change can safely perform the `...' to '...' conversion. * src/truncate.c (main): Tweak quoting in comments to use '...', not `...`, for consistency with the rest of comments in coreutils.
2012-01-07maint: use new emit_try_help in place of equivalent fprintfJim Meyering
Run this command: perl -0777 -pi -e \ 's/fprintf \(stderr, _\("Try `%s --help.*\n.*;/emit_try_help ();/m'\ src/*.c
2012-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2011-06-13maint: use stat-size module from gnulibJames Youngman
* gnulib: Update to latest. * src/system.h: Definitions of ST_* macros have moved into the gnulib module stat-size (specifically, the header file stat-size.h), so remove them from here. * src/truncate.c: Include stat-size.h. * src/stat.c: Likewise. * src/shred.c: Likewise. * src/ls.c: Likewise. * src/du.c: Likewise. * src/ioblksize.h: New file. Move definition of io_blksize out of system.h so that system.h does not have to include stat-size.h. * src/cat.c: Include ioblksize.h. * src/split.c: Likewise. * src/copy.c: Include both stat-size.h and ioblksize.h. * src/Makefile.am (noinst_HEADERS): Add ioblksize.h.
2011-06-09maint: remove unneeded includesPádraig Brady
Remove unneeded includes as reported by: http://code.google.com/p/include-what-you-use/ * src/cp-hash.c: Remove unused include. * src/dd.c: Likewise. * src/du.c: Likewise. * src/head.c: Likewise. * src/kill.c: Likewise. * src/ls.c: Likewise. * src/stdbuf.c: Likewise. * src/timeout.c: Likewise. * src/truncate.c: Likewise.
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-11-16truncate: fix a very unlikely case for undiagnosed errorsPádraig Brady
src/truncate.c (main): Use a bool to store if an error occurred, rather than an int, to protect against overflow. (do_ftruncate): Likewise. Also change 0/false to mean failure rather than success.
2010-05-31maint: make spacing around "=" consistent, even in IF_LINTJim Meyering
E.g., - size_t desired_width IF_LINT (= 0); + size_t desired_width IF_LINT ( = 0); Use this command: g grep -l IF_LINT | grep '\.[ch]$' \ | xargs perl -pi -e 's/(IF_LINT \()= /$1 = /'
2010-05-29truncate: improve handling of non regular filesPádraig Brady
Previously we copied `dd` and suppressed error messages when truncating neither regular files or shared mem objects. This was valid for `dd`, as truncation is ancillary to copying it may also do, but for `truncate` we should display all errors. Also we used the st_size from non regular files which is undefined, so we display an error when the user tries this. * src/truncate (do_truncate): Error when referencing the size of non regular files or non shared memory objects. Display all errors returned by ftruncate(). (main): Error when referencing the size of non regular files or non shared memory objects. Don't suppress error messages for any file types that can't be opened for writing. * tests/misc/truncate-dir-fail: Check that referencing the size of a directory is not supported. * tests/misc/truncate-fifo: Ensure the test doesn't hang by using the `timeout` command. Don't test the return from running ftruncate on the fifo as it's system dependent as to whether this fails or not. NEWS: Mention the change in behavior. Reported by Jim Meyering.
2010-05-28truncate: support sizes relative to an existing filePádraig Brady
* doc/coreutils.texi (truncate invocation): Mention that --reference bases the --size rather than just setting it. * src/truncate.c (usage): Likewise. Also remove the clause describing --size and --reference as being mutually exclusive. (do_truncate): Add an extra parameter to hold the size of a referenced file, and use it if positive. (main): Pass the size of a referenced file to do_truncate(). * tests/misc/truncate-parameters: Adjust for the new combinations. * NEWS: Mention the change Suggested by Richard W.M. Jones
2010-04-09maint: ftruncate is always available, even without gnulibJim Meyering
Now that even MinGW provides ftruncate, we know that all reasonable portability targets provide this function. Remove the workaround code. We nearly removed the gnulib module three years ago: http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/9203 and it is now officially "obsolete". * bootstrap.conf (gnulib_modules): Remove ftruncate. * src/copy.c (copy_reg): Remove use of HAVE_FTRUNCATE and its no-longer-used workaround code. * src/truncate.c: Remove a comment about handling missing ftruncate.
2010-02-15doc: fix inconsistent capitalization in --help outputPádraig Brady
* src/base64.c (usage): Don't capitalize the first character in an --option description. * src/stdbuf.c (usage): Likewise. * src/truncate.c (usage): Likewise. * cfg.mk (sc_option_desc_uppercase): A new syntax check to stop this happening in future. * man/Makefile.am (sc_option_desc_uppercase): Ensure all man pages are generated, then search for erroneous uppercase chars. * src/Makefile.am (all_programs): Ensure all commands are built so that all man pages can be generated.
2010-01-01maint: update all FSF copyright year lists to include 2010Jim Meyering
Use this command: git ls-files | grep -v COPYING \ | xargs env UPDATE_COPYRIGHT_USE_INTERVALS=1 \ build-aux/update-copyright
2009-09-21doc: mention the texinfo documentation in --helpPádraig Brady
* src/system.h: Rename emit_bug_reporting_address() to emit_ancillary_info() and update it to not print the translation project address in en_* locales, and _do_ print it in the 'C' (and other) locales so that it's included in the default man page. Also mention how to invoke the texinfo documentation for each command. Also move the "hard-locale.h" include to the 8 files that now use it. * man/help2man: Strip the newly added texinfo reference from the --help output as a more verbose version is already added by help2man. Suggestion from C de-Avillez
2009-09-10doc: improve various BLOCKSIZE and SIZE helpOndřej Vašík
* doc/coreutils.texi (multiplierSuffixes): Mention that the suffix can be specified without a leading number * src/split.c (usage): Refactor SIZE help to within a function * src/truncate.c (usage): Likewise * src/ls.c (usage): Likewise * src/df.c (usage): Likewise. Also add a function with BLOCKSIZE help * src/du.c (usage): Likewise. * src/system.h: Define 2 functions to emit common help text This was prompted by https://bugzilla.redhat.com/show_bug.cgi?id=511188
2009-08-25maint: remove Local Variables: indent-tabs-mode: nil from all sourcesJim Meyering
* src/getlimits.c: Likewise. * src/group-list.c: Likewise. * src/groups.c: Likewise. * src/mktemp.c: Likewise. * src/setuidgid.c: Likewise. * src/stdbuf.c: Likewise. * src/timeout.c: Likewise. * src/truncate.c: Likewise. * gl/lib/mbsalign.c: Likewise. * tests/test-lib.sh: Likewise. * bootstrap: Likewise. * README-hacking: Likewise.
2009-05-11truncate: fix bug in use of isspaceEric Blake
* src/truncate.c (main): Pass unsigned characters to isspace. * NEWS: Mention this.
2009-04-07maint: Clarify ambiguous refs to Linux kernels or GNU/Linux systemsPádraig Brady
* README-prereq: s_linux_GNU/Linux_ or s_linux_Linux kernel_ * README-valgrind: ditto * src/chown-core.c: ditto * src/dd.c: ditto * src/df.c: ditto * src/ls.c: ditto * src/mv.c: ditto * src/pwd.c: ditto * src/remove.c: ditto * src/shred.c: ditto * src/stat.c: ditto * src/su.c: ditto * src/system.h: ditto * src/timeout.c: ditto * src/truncate.c: ditto
2008-12-21build: add configure-time --enable-gcc-warnings option; avoid warningsJim Meyering
* bootstrap.conf (gnulib_modules): Add "warnings" module. * configure.ac: Add --enable-gcc-warnings, derived from code in bison. * src/Makefile.am (AM_CFLAGS): Set to $(WARN_CFLAGS) # $(WERROR_CFLAGS) * lib/Makefile.am (AM_CFLAGS): Change spelling to $(WARN_CFLAGS) Don't use $(WERROR_CFLAGS), yet. * src/system.h (usage): Declare. * src/base64.c (usage): Declare to be global, for consistency. * src/timeout.c (usage): Likewise. * src/truncate.c (usage): Likewise. * src/getlimits.c (usage): Likewise. * src/pinky.c (ttyname): Declare with prototype, rather than an empty argument list. * src/who.c (ttyname): Likewise. * src/su.c (crypt, getusershell, setusershell, endusershell): Likewise.
2008-06-30truncate: ignore whitespace in --size parametersPádraig Brady
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.
2008-06-27truncate: silence -Wsign-compare warningsPádraig Brady
* src/truncate.c: Cast signed to unsigned to confirm intent which will silence -Wsign-compare warnings
2008-06-27truncate: Fix integer portability issuesPádraig Brady
* src/truncate.c: Explicitly convert from off_t to intmax_t when printing numbers as they may be different types. Also don't mix size_t and off_t types in operations as the latter will be promoted to unsigned when these types are the same size.
2008-06-26truncate: handle the case in which off_t != intmax_tJim Meyering
* src/truncate.c (parse_len): Use a temporary of type intmax_t, rather than off_t; detect out of range [OFF_T_MIN..OFF_T_MAX]. (main) [IF_LINT]: Initialize, to avoid an unwarranted "may be used uninitialized" warning. Reported by Michael Geng. Signed-off-by: Pádraig Brady <P@draigBrady.com>
2008-06-16remove redundant const directivesJim Meyering
In 1463824d8e7f72c31f1d803d7cfe2b608ccafc5c, I added some missing "const" directives, as well as some new, redundant ones. This removes the redundant ones. Pointed out by Eric Blake. * base64.c, cat.c, chcon.c, chgrp.c, chmod.c, chown.c, comm.c: * cp.c, csplit.c, cut.c, date.c, dd.c, df.c, dircolors.c, du.c: * env.c, expand.c, fmt.c, fold.c, groups.c, head.c, id.c: * install.c, join.c, kill.c, ln.c, ls.c, md5sum.c, mkdir.c: * mkfifo.c, mknod.c, mktemp.c, mv.c, nice.c, nl.c, od.c: * paste.c, pathchk.c, pinky.c, pr.c, ptx.c, readlink.c, rm.c: * rmdir.c, runcon.c, seq.c, shred.c, shuf.c, sort.c, split.c: * stat.c, stty.c, su.c, sum.c, tac.c, tail.c, tee.c, timeout.c: * touch.c, tr.c, truncate.c, tty.c, uname.c, unexpand.c, uniq.c: * wc.c, who.c: Remove redundant const directives. * maint.mk (sc_const_long_option): Don't require redundant "const".
2008-06-14add "const" attribute, where possibleJim Meyering
* maint.mk (sc_const_long_option): New rule. Enforce global change. * src/base64.c (long_options): Use "const" where possible. * src/cat.c (main): Likewise. * src/chcon.c (long_options): Likewise. * src/chgrp.c (long_options): Likewise. * src/chmod.c (long_options): Likewise. * src/chown.c (long_options): Likewise. * src/comm.c (long_options, OUTPUT_DELIMITER_OPTION): Likewise. * src/cp.c (long_opts): Likewise. * src/csplit.c (longopts): Likewise. * src/cut.c (longopts): Likewise. * src/date.c (long_options): Likewise. * src/dd.c (conversions, flags, statuses): Likewise. * src/df.c (long_options): Likewise. * src/dircolors.c (long_options): Likewise. * src/du.c (long_options): Likewise. * src/env.c (longopts): Likewise. * src/expand.c (longopts): Likewise. * src/fmt.c (long_options): Likewise. * src/fold.c (longopts): Likewise. * src/groups.c (longopts): Likewise. * src/head.c (long_options): Likewise. * src/id.c (longopts): Likewise. * src/install.c (long_options): Likewise. * src/join.c (longopts): Likewise. * src/kill.c (long_options): Likewise. * src/ln.c (long_options): Likewise. * src/ls.c (long_time_format, long_options, sort_functions): Likewise. * src/md5sum.c (long_options): Likewise. * src/mkdir.c (longopts): Likewise. * src/mkfifo.c (longopts): Likewise. * src/mknod.c (longopts): Likewise. * src/mktemp.c (longopts): Likewise. * src/mv.c (long_options): Likewise. * src/nice.c (longopts): Likewise. * src/nl.c (longopts): Likewise. * src/od.c (charname, long_options): Likewise. * src/paste.c (longopts): Likewise. * src/pathchk.c (longopts): Likewise. * src/pinky.c (longopts): Likewise. * src/pr.c (long_options): Likewise. * src/ptx.c (long_options): Likewise. * src/readlink.c (longopts): Likewise. * src/rm.c (long_opts): Likewise. * src/rmdir.c (longopts): Likewise. * src/runcon.c (long_options): Likewise. * src/seq.c (long_options): Likewise. * src/shred.c (long_opts): Likewise. * src/shuf.c (long_opts): Likewise. * src/sort.c (monthtab, long_options): Likewise. * src/split.c (longopts): Likewise. * src/stat.c (long_options): Likewise. * src/stty.c (mode_info, control_info, longopts, set_mode) Likewise. (set_control_char, speeds): Likewise. * src/su.c (longopts): Likewise. * src/sum.c (longopts): Likewise. * src/tac.c (longopts): Likewise. * src/tail.c (long_options): Likewise. * src/tee.c (long_options): Likewise. * src/timeout.c (long_options): Likewise. * src/touch.c (longopts): Likewise. * src/tr.c (long_options): Likewise. * src/truncate.c (longopts): Likewise. * src/tty.c (longopts): Likewise. * src/uname.c (uname_long_options, arch_long_options): Likewise. * src/unexpand.c (longopts): Likewise. * src/uniq.c (longopts): Likewise. * src/wc.c (longopts): Likewise. * src/who.c (longopts): Likewise.
2008-06-14revert previous change, "don't use "const" with scalar types"Jim Meyering
* src/truncate.c: There is nothing wrong with that construct. This reverts commit d7d80c5b7b122377fe250357a3ab182e8fbde20a.
2008-06-14don't use "const" with scalar typesJim Meyering
* src/truncate.c: Several vendor compilers reject that. See http://article.gmane.org/gmane.comp.lib.gnulib.bugs/13876
2008-06-08standardize some error messagesBo Borgerson
* maint.mk: (sc_error_message_warn_fatal, sc_error_message_uppercase): (sc_error_message_period): Add automatic checks for non-standard error messages. * .x-sc_error_message_uppercase: explicit exclusion for this check * src/cp.c: Standardize some error messages. * src/date.c: Likewise. * src/dircolors.c: Likewise. * src/du.c: Likewise. * src/expr.c: Likewise. * src/install.c: Likewise. * src/join.c: Likewise. * src/ln.c: Likewise. * src/mv.c: Likewise. * src/od.c: Likewise. * src/pr.c: Likewise. * src/split.c: Likewise. * src/truncate.c: Likewise. * src/wc.c: Likewise. * tests/du/files0-from: Expect new error message. * tests/misc/join: Likewise. * tests/misc/split-a: Likewise. * tests/misc/wc-files0-from: Likewise. * tests/misc/xstrtol: Likewise. * lib/xmemxfrm.c: Likewise.
2008-06-06Add new program: truncatePádraig Brady
* 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 * src/.gitignore: Add truncate binary to list to ignore * 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/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