summaryrefslogtreecommitdiff
path: root/src/truncate.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-11-01 18:53:26 +0000
committerPádraig Brady <P@draigBrady.com>2015-11-04 23:30:14 +0000
commit08e8fd7e38f2dae7c69c54eb22d508b6517e66e5 (patch)
tree63d021e305cd93bea445f9484fe8b3446dda2c3d /src/truncate.c
parent1e8f9afac53a628dbc64e62bea53eb2da29c47fa (diff)
downloadcoreutils-08e8fd7e38f2dae7c69c54eb22d508b6517e66e5.tar.xz
all: avoid quoting file names when possible
Quote file names using the "shell-escape" or "shell-escape-always" methods, which quote as appropriate for most shells, and better support copy and paste of presented names. The "always" variant is used when the file name is embedded in an error message with surrounding spaces. * cfg.mk (sc_error_shell_quotes): A new syntax check rule to suggest quotef() where appropriate. (sc_error_shell_always_quotes): Likewise for quoteaf(). * src/system.h (quotef): A new define to apply shell quoting when needed. I.E. when shell character or ':' is present. (quoteaf): Likewise, but always quote. * src/*.c: Use quotef() and quoteaf() rather than quote() where appropriate. * tests/: Adjust accordingly.
Diffstat (limited to 'src/truncate.c')
-rw-r--r--src/truncate.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/truncate.c b/src/truncate.c
index c40cd6113..f49efc5e2 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -110,7 +110,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
if ((block_mode || (rel_mode && rsize < 0)) && fstat (fd, &sb) != 0)
{
- error (0, errno, _("cannot fstat %s"), quote (fname));
+ error (0, errno, _("cannot fstat %s"), quoteaf (fname));
return false;
}
if (block_mode)
@@ -122,7 +122,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
_("overflow in %" PRIdMAX
" * %" PRIdMAX " byte blocks for file %s"),
(intmax_t) ssize, (intmax_t) blksize,
- quote (fname));
+ quoteaf (fname));
return false;
}
ssize *= blksize;
@@ -144,7 +144,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
/* Sanity check. Overflow is the only reason I can think
this would ever go negative. */
error (0, 0, _("%s has unusable, apparently negative size"),
- quote (fname));
+ quoteaf (fname));
return false;
}
}
@@ -154,7 +154,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
if (file_size < 0)
{
error (0, errno, _("cannot get the size of %s"),
- quote (fname));
+ quoteaf (fname));
return false;
}
}
@@ -176,7 +176,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
if (overflow > OFF_T_MAX)
{
error (0, 0, _("overflow rounding up size of file %s"),
- quote (fname));
+ quoteaf (fname));
return false;
}
nsize = overflow;
@@ -186,7 +186,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
if (ssize > OFF_T_MAX - (off_t)fsize)
{
error (0, 0, _("overflow extending size of file %s"),
- quote (fname));
+ quoteaf (fname));
return false;
}
nsize = fsize + ssize;
@@ -200,7 +200,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
if (ftruncate (fd, nsize) == -1) /* note updates mtime & ctime */
{
error (0, errno,
- _("failed to truncate %s at %" PRIdMAX " bytes"), quote (fname),
+ _("failed to truncate %s at %" PRIdMAX " bytes"), quoteaf (fname),
(intmax_t) nsize);
return false;
}
@@ -334,7 +334,7 @@ main (int argc, char **argv)
struct stat sb;
off_t file_size = -1;
if (stat (ref_file, &sb) != 0)
- error (EXIT_FAILURE, errno, _("cannot stat %s"), quote (ref_file));
+ error (EXIT_FAILURE, errno, _("cannot stat %s"), quoteaf (ref_file));
if (usable_st_size (&sb))
file_size = sb.st_size;
else
@@ -356,7 +356,7 @@ main (int argc, char **argv)
}
if (file_size < 0)
error (EXIT_FAILURE, errno, _("cannot get the size of %s"),
- quote (ref_file));
+ quoteaf (ref_file));
if (!got_size)
size = file_size;
else
@@ -376,7 +376,7 @@ main (int argc, char **argv)
if (!(no_create && errno == ENOENT))
{
error (0, errno, _("cannot open %s for writing"),
- quote (fname));
+ quoteaf (fname));
errors = true;
}
continue;
@@ -388,7 +388,7 @@ main (int argc, char **argv)
errors |= !do_ftruncate (fd, fname, size, rsize, rel_mode);
if (close (fd) != 0)
{
- error (0, errno, _("failed to close %s"), quote (fname));
+ error (0, errno, _("failed to close %s"), quoteaf (fname));
errors = true;
}
}