diff options
author | Pádraig Brady <P@draigBrady.com> | 2015-11-01 18:53:26 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2015-11-04 23:30:14 +0000 |
commit | 08e8fd7e38f2dae7c69c54eb22d508b6517e66e5 (patch) | |
tree | 63d021e305cd93bea445f9484fe8b3446dda2c3d /src/tac.c | |
parent | 1e8f9afac53a628dbc64e62bea53eb2da29c47fa (diff) | |
download | coreutils-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/tac.c')
-rw-r--r-- | src/tac.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -45,7 +45,6 @@ tac -r -s '.\| #include "error.h" #include "filenamecat.h" -#include "quote.h" #include "safe-read.h" #include "stdlib--.h" #include "xfreopen.h" @@ -220,7 +219,7 @@ tac_seekable (int input_fd, const char *file, off_t file_pos) { file_pos -= remainder; if (lseek (input_fd, file_pos, SEEK_SET) < 0) - error (0, errno, _("%s: seek failed"), quote (file)); + error (0, errno, _("%s: seek failed"), quotef (file)); } /* Scan backward, looking for end of file. This caters to proc-like @@ -230,7 +229,7 @@ tac_seekable (int input_fd, const char *file, off_t file_pos) { off_t rsize = read_size; if (lseek (input_fd, -rsize, SEEK_CUR) < 0) - error (0, errno, _("%s: seek failed"), quote (file)); + error (0, errno, _("%s: seek failed"), quotef (file)); file_pos -= read_size; } @@ -248,7 +247,7 @@ tac_seekable (int input_fd, const char *file, off_t file_pos) if (saved_record_size == SAFE_READ_ERROR) { - error (0, errno, _("%s: read error"), quote (file)); + error (0, errno, _("%s: read error"), quotef (file)); return false; } @@ -340,7 +339,7 @@ tac_seekable (int input_fd, const char *file, off_t file_pos) file_pos = 0; } if (lseek (input_fd, file_pos, SEEK_SET) < 0) - error (0, errno, _("%s: seek failed"), quote (file)); + error (0, errno, _("%s: seek failed"), quotef (file)); /* Shift the pending record data right to make room for the new. The source and destination regions probably overlap. */ @@ -354,7 +353,7 @@ tac_seekable (int input_fd, const char *file, off_t file_pos) if (safe_read (input_fd, G_buffer, read_size) != read_size) { - error (0, errno, _("%s: read error"), quote (file)); + error (0, errno, _("%s: read error"), quotef (file)); return false; } } @@ -456,7 +455,7 @@ temp_stream (FILE **fp, char **file_name) if (fd < 0) { error (0, errno, _("failed to create temporary file in %s"), - quote (tempdir)); + quoteaf (tempdir)); goto Reset; } @@ -464,7 +463,7 @@ temp_stream (FILE **fp, char **file_name) if (! tmp_fp) { error (0, errno, _("failed to open %s for writing"), - quote (tempfile)); + quoteaf (tempfile)); close (fd); unlink (tempfile); Reset: @@ -481,7 +480,7 @@ temp_stream (FILE **fp, char **file_name) || ftruncate (fileno (tmp_fp), 0) < 0) { error (0, errno, _("failed to rewind stream for %s"), - quote (tempfile)); + quoteaf (tempfile)); return false; } } @@ -511,13 +510,13 @@ copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file) break; if (bytes_read == SAFE_READ_ERROR) { - error (0, errno, _("%s: read error"), quote (file)); + error (0, errno, _("%s: read error"), quotef (file)); goto Fail; } if (fwrite (G_buffer, 1, bytes_read, fp) != bytes_read) { - error (0, errno, _("%s: write error"), quote (file_name)); + error (0, errno, _("%s: write error"), quotef (file_name)); goto Fail; } @@ -529,7 +528,7 @@ copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file) if (fflush (fp) != 0) { - error (0, errno, _("%s: write error"), quote (file_name)); + error (0, errno, _("%s: write error"), quotef (file_name)); goto Fail; } @@ -584,7 +583,7 @@ tac_file (const char *filename) if (fd < 0) { error (0, errno, _("failed to open %s for reading"), - quote (filename)); + quoteaf (filename)); return false; } } @@ -597,7 +596,7 @@ tac_file (const char *filename) if (!is_stdin && close (fd) != 0) { - error (0, errno, _("%s: read error"), quote (filename)); + error (0, errno, _("%s: read error"), quotef (filename)); ok = false; } return ok; |