summaryrefslogtreecommitdiff
path: root/src/wc.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/wc.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/wc.c')
-rw-r--r--src/wc.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/wc.c b/src/wc.c
index 30a08926f..33b5ba4dd 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -32,7 +32,6 @@
#include "fadvise.h"
#include "mbchar.h"
#include "physmem.h"
-#include "quote.h"
#include "readtokens0.h"
#include "safe-read.h"
#include "stat-size.h"
@@ -258,7 +257,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
{
if (bytes_read == SAFE_READ_ERROR)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
ok = false;
break;
}
@@ -274,7 +273,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
{
if (bytes_read == SAFE_READ_ERROR)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
ok = false;
break;
}
@@ -342,7 +341,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
# endif
if (bytes_read == SAFE_READ_ERROR)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
ok = false;
break;
}
@@ -463,7 +462,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
const char *p = buf;
if (bytes_read == SAFE_READ_ERROR)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
ok = false;
break;
}
@@ -540,7 +539,7 @@ wc_file (char const *file, struct fstatus *fstatus)
int fd = open (file, O_RDONLY | O_BINARY);
if (fd == -1)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
return false;
}
else
@@ -548,7 +547,7 @@ wc_file (char const *file, struct fstatus *fstatus)
bool ok = wc (fd, file, fstatus, 0);
if (close (fd) != 0)
{
- error (0, errno, "%s", quote (file));
+ error (0, errno, "%s", quotef (file));
return false;
}
return ok;
@@ -696,7 +695,7 @@ main (int argc, char **argv)
on the command-line. */
if (optind < argc)
{
- error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ error (0, 0, _("extra operand %s"), quoteaf (argv[optind]));
fprintf (stderr, "%s\n",
_("file operands cannot be combined with --files0-from"));
usage (EXIT_FAILURE);
@@ -709,7 +708,7 @@ main (int argc, char **argv)
stream = fopen (files_from, "r");
if (stream == NULL)
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
- quote (files_from));
+ quoteaf (files_from));
}
/* Read the file list into RAM if we can detect its size and that
@@ -723,7 +722,7 @@ main (int argc, char **argv)
readtokens0_init (&tok);
if (! readtokens0 (stream, &tok) || fclose (stream) != 0)
error (EXIT_FAILURE, 0, _("cannot read file names from %s"),
- quote (files_from));
+ quoteaf (files_from));
files = tok.tok;
nfiles = tok.n_tok;
ai = argv_iter_init_argv (files);
@@ -764,7 +763,7 @@ main (int argc, char **argv)
goto argv_iter_done;
case AI_ERR_READ:
error (0, errno, _("%s: read error"),
- quote (files_from));
+ quotef (files_from));
ok = false;
goto argv_iter_done;
case AI_ERR_MEM:
@@ -779,7 +778,7 @@ main (int argc, char **argv)
printf - | wc --files0-from=- */
error (0, 0, _("when reading file names from stdin, "
"no file name of %s allowed"),
- quote (file_name));
+ quoteaf (file_name));
skip_file = true;
}
@@ -797,7 +796,7 @@ main (int argc, char **argv)
not totally appropriate, since NUL is the separator, not NL,
but it might be better than nothing. */
unsigned long int file_number = argv_iter_n_args (ai);
- error (0, 0, "%s:%lu: %s", quote (files_from),
+ error (0, 0, "%s:%lu: %s", quotef (files_from),
file_number, _("invalid zero-length file name"));
}
skip_file = true;