diff options
author | Pádraig Brady <P@draigBrady.com> | 2015-10-28 13:02:31 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2015-11-04 02:03:41 +0000 |
commit | ab40a941a07d80326aaa051e3c94c88b800cbd7d (patch) | |
tree | 382e656f126d0e63ca1158f8f43630e1dd10d18b /src | |
parent | 00eb7af8ea30ccbefeb17213cd644b8f0ade1ef8 (diff) | |
download | coreutils-ab40a941a07d80326aaa051e3c94c88b800cbd7d.tar.xz |
all: replace most uses of quotearg_colon() with quote()
Related to commit v8.24-61-g6796698 this provides
more consistent quoting, as quotearg_colon() defaults
to "literal" quoting by default, while quote()
provides appropriate quoting for diagnostics by default.
* gl/modules/randread: Depend on quote module rather than quotearg.
* gl/lib/randread.c: Used quote() not quotearg_colon().
* src/: Likewise.
* src/shred.c: Likewise. Also avoid unnecessary quoting
introducing overhead when wiping names.
* cfg.mk: Relax the matching expression to allow
"qname" variables as used in shred.c to satisfy the check.
* tests/: Adjust accordingly.
Diffstat (limited to 'src')
-rw-r--r-- | src/chcon.c | 3 | ||||
-rw-r--r-- | src/chmod.c | 3 | ||||
-rw-r--r-- | src/du.c | 9 | ||||
-rw-r--r-- | src/head.c | 5 | ||||
-rw-r--r-- | src/install.c | 3 | ||||
-rw-r--r-- | src/ls.c | 6 | ||||
-rw-r--r-- | src/runcon.c | 5 | ||||
-rw-r--r-- | src/shred.c | 55 | ||||
-rw-r--r-- | src/shuf.c | 5 | ||||
-rw-r--r-- | src/sort.c | 2 | ||||
-rw-r--r-- | src/stat.c | 3 | ||||
-rw-r--r-- | src/tac.c | 19 | ||||
-rw-r--r-- | src/wc.c | 5 |
13 files changed, 55 insertions, 68 deletions
diff --git a/src/chcon.c b/src/chcon.c index 674d03366..4f51d70d4 100644 --- a/src/chcon.c +++ b/src/chcon.c @@ -24,7 +24,6 @@ #include "error.h" #include "ignore-value.h" #include "quote.h" -#include "quotearg.h" #include "root-dev-ino.h" #include "selinux-at.h" #include "xfts.h" @@ -98,7 +97,7 @@ compute_context_from_mask (char const *context, context_t *ret) if (!new_context) { error (0, errno, _("failed to create security context: %s"), - quotearg_colon (context)); + quote (context)); return 1; } diff --git a/src/chmod.c b/src/chmod.c index 5c6881c44..988ba7269 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -28,7 +28,6 @@ #include "ignore-value.h" #include "modechange.h" #include "quote.h" -#include "quotearg.h" #include "root-dev-ino.h" #include "xfts.h" @@ -312,7 +311,7 @@ process_file (FTS *fts, FTSENT *ent) new_perms[10] = naively_expected_perms[10] = '\0'; error (0, 0, _("%s: new permissions are %s, not %s"), - quotearg_colon (file_full_name), + quote (file_full_name), new_perms + 1, naively_expected_perms + 1); ok = false; } @@ -37,7 +37,6 @@ #include "human.h" #include "mountlist.h" #include "quote.h" -#include "quotearg.h" #include "stat-size.h" #include "stat-time.h" #include "stdio--.h" @@ -692,7 +691,7 @@ du_files (char **files, int bit_flags) if (errno != 0) { error (0, errno, _("fts_read failed: %s"), - quotearg_colon (fts->fts_path)); + quote (fts->fts_path)); ok = false; } @@ -883,7 +882,7 @@ main (int argc, char **argv) if (add_exclude_file (add_exclude, exclude, optarg, EXCLUDE_WILDCARDS, '\n')) { - error (0, errno, "%s", quotearg_colon (optarg)); + error (0, errno, "%s", quote (optarg)); ok = false; } break; @@ -1069,7 +1068,7 @@ main (int argc, char **argv) goto argv_iter_done; case AI_ERR_READ: error (0, errno, _("%s: read error"), - quotearg_colon (files_from)); + quote (files_from)); ok = false; goto argv_iter_done; case AI_ERR_MEM: @@ -1106,7 +1105,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", quotearg_colon (files_from), + error (0, 0, "%s:%lu: %s", quote (files_from), file_number, _("invalid zero-length file name")); } skip_file = true; diff --git a/src/head.c b/src/head.c index 410cc4f49..a77376d10 100644 --- a/src/head.c +++ b/src/head.c @@ -34,7 +34,6 @@ #include "error.h" #include "full-read.h" #include "quote.h" -#include "quotearg.h" #include "safe-read.h" #include "stat-size.h" #include "xfreopen.h" @@ -223,7 +222,7 @@ elseek (int fd, off_t offset, int whence, char const *filename) _(whence == SEEK_SET ? N_("%s: cannot seek to offset %s") : N_("%s: cannot seek to relative offset %s")), - quotearg_colon (filename), + quote (filename), offtostr (offset, buf)); return new_offset; @@ -838,7 +837,7 @@ head (const char *filename, int fd, uintmax_t n_units, bool count_lines, if (fstat (fd, &st) != 0) { error (0, errno, _("cannot fstat %s"), - quotearg_colon (filename)); + quote (filename)); return false; } if (! presume_input_pipe && usable_st_size (&st)) diff --git a/src/install.c b/src/install.c index bbd67bc02..d338cbb29 100644 --- a/src/install.c +++ b/src/install.c @@ -38,7 +38,6 @@ #include "modechange.h" #include "prog-fprintf.h" #include "quote.h" -#include "quotearg.h" #include "savewd.h" #include "stat-time.h" #include "utimens.h" @@ -374,7 +373,7 @@ setdefaultfilecon (char const *file) if (lsetfilecon (file, scontext) < 0 && errno != ENOTSUP) error (0, errno, _("warning: %s: failed to change context to %s"), - quotearg_colon (file), scontext); + quote_n (0, file), quote_n (1, scontext)); freecon (scontext); return; @@ -2534,7 +2534,7 @@ set_exit_status (bool serious) static void file_failure (bool serious, char const *message, char const *file) { - error (0, errno, message, quotearg_colon (file)); + error (0, errno, message, quote (file)); set_exit_status (serious); } @@ -2601,7 +2601,7 @@ print_dir (char const *name, char const *realname, bool command_line_arg) if (visit_dir (dir_stat.st_dev, dir_stat.st_ino)) { error (0, 0, _("%s: not listing already-listed directory"), - quotearg_colon (name)); + quote (name)); closedir (dirp); set_exit_status (true); return; @@ -3109,7 +3109,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode, any_has_acl |= f->acl_type != ACL_T_NONE; if (err) - error (0, errno, "%s", quotearg_colon (absolute_name)); + error (0, errno, "%s", quote (absolute_name)); } if (S_ISLNK (f->stat.st_mode) diff --git a/src/runcon.c b/src/runcon.c index ecb12985a..d5ec57958 100644 --- a/src/runcon.c +++ b/src/runcon.c @@ -49,7 +49,6 @@ #include "system.h" #include "error.h" #include "quote.h" -#include "quotearg.h" /* The official name of this program (e.g., no 'g' prefix). */ #define PROGRAM_NAME "runcon" @@ -231,7 +230,7 @@ main (int argc, char **argv) con = context_new (cur_context); if (!con) error (EXIT_FAILURE, errno, _("failed to create security context: %s"), - quotearg_colon (cur_context)); + quote (cur_context)); if (user && context_user_set (con, user)) error (EXIT_FAILURE, errno, _("failed to set new user: %s"), quote (user)); @@ -248,7 +247,7 @@ main (int argc, char **argv) if (security_check_context (context_str (con)) < 0) error (EXIT_FAILURE, errno, _("invalid context: %s"), - quotearg_colon (context_str (con))); + quote (context_str (con))); if (setexeccon (context_str (con)) != 0) error (EXIT_FAILURE, errno, _("unable to set security context %s"), diff --git a/src/shred.c b/src/shred.c index 6029d37e3..9c6752881 100644 --- a/src/shred.c +++ b/src/shred.c @@ -91,7 +91,6 @@ #include "fcntl--.h" #include "human.h" #include "quote.h" -#include "quotearg.h" /* For quotearg_colon */ #include "randint.h" #include "randread.h" #include "stat-size.h" @@ -341,7 +340,7 @@ dosync (int fd, char const *qname) err = errno; if ( ! ignorable_sync_errno (err)) { - error (0, err, _("%s: fdatasync failed"), quote (qname)); + error (0, err, _("%s: fdatasync failed"), qname); errno = err; return -1; } @@ -352,7 +351,7 @@ dosync (int fd, char const *qname) err = errno; if ( ! ignorable_sync_errno (err)) { - error (0, err, _("%s: fsync failed"), quote (qname)); + error (0, err, _("%s: fsync failed"), qname); errno = err; return -1; } @@ -470,7 +469,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, if (! dorewind (fd, st)) { - error (0, errno, _("%s: cannot rewind"), quote (qname)); + error (0, errno, _("%s: cannot rewind"), qname); other_error = true; goto free_pattern_mem; } @@ -490,8 +489,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, /* Set position if first status update */ if (n) { - error (0, 0, _("%s: pass %lu/%lu (%s)..."), - quote (qname), k, n, pass_string); + error (0, 0, _("%s: pass %lu/%lu (%s)..."), qname, k, n, pass_string); thresh = time (NULL) + VERBOSE_UPDATE; previous_human_offset = ""; } @@ -543,7 +541,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, continue; } error (0, errnum, _("%s: error writing at offset %s"), - quote (qname), umaxtostr (offset + soff, buf)); + qname, umaxtostr (offset + soff, buf)); /* 'shred' is often used on bad media, before throwing it out. Thus, it shouldn't give up on bad blocks. This @@ -563,7 +561,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, write_error = true; continue; } - error (0, errno, _("%s: lseek failed"), quote (qname)); + error (0, errno, _("%s: lseek failed"), qname); } other_error = true; goto free_pattern_mem; @@ -575,7 +573,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, if (OFF_T_MAX - offset < soff) { - error (0, 0, _("%s: file too large"), quote (qname)); + error (0, 0, _("%s: file too large"), qname); other_error = true; goto free_pattern_mem; } @@ -600,7 +598,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, { if (! known (size)) error (0, 0, _("%s: pass %lu/%lu (%s)...%s"), - quote (qname), k, n, pass_string, human_offset); + qname, k, n, pass_string, human_offset); else { uintmax_t off = offset; @@ -616,8 +614,8 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep, if (done) human_offset = human_size; error (0, 0, _("%s: pass %lu/%lu (%s)...%s/%s %d%%"), - quote (qname), k, n, pass_string, human_offset, - human_size, percent); + qname, k, n, pass_string, human_offset, human_size, + percent); } strcpy (previous_offset_buf, human_offset); @@ -874,7 +872,7 @@ do_wipefd (int fd, char const *qname, struct randint_source *s, if (fstat (fd, &st)) { - error (0, errno, _("%s: fstat failed"), quote (qname)); + error (0, errno, _("%s: fstat failed"), qname); return false; } @@ -885,12 +883,12 @@ do_wipefd (int fd, char const *qname, struct randint_source *s, || S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode)) { - error (0, 0, _("%s: invalid file type"), quote (qname)); + error (0, 0, _("%s: invalid file type"), qname); return false; } else if (S_ISREG (st.st_mode) && st.st_size < 0) { - error (0, 0, _("%s: file has negative size"), quote (qname)); + error (0, 0, _("%s: file has negative size"), qname); return false; } @@ -984,7 +982,7 @@ do_wipefd (int fd, char const *qname, struct randint_source *s, if (flags->remove_file && ftruncate (fd, 0) != 0 && S_ISREG (st.st_mode)) { - error (0, errno, _("%s: error truncating"), quote (qname)); + error (0, errno, _("%s: error truncating"), qname); ok = false; goto wipefd_out; } @@ -1004,13 +1002,12 @@ wipefd (int fd, char const *qname, struct randint_source *s, if (fd_flags < 0) { - error (0, errno, _("%s: fcntl failed"), quote (qname)); + error (0, errno, _("%s: fcntl failed"), qname); return false; } if (fd_flags & O_APPEND) { - error (0, 0, _("%s: cannot shred append-only file descriptor"), - quote (qname)); + error (0, 0, _("%s: cannot shred append-only file descriptor"), qname); return false; } return do_wipefd (fd, qname, s, flags); @@ -1085,7 +1082,7 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags) char *base = last_component (newname); size_t len = base_len (base); char *dir = dir_name (newname); - char *qdir = xstrdup (quotearg_colon (dir)); + char *qdir = xstrdup (quote (dir)); bool first = true; bool ok = true; int dir_fd = -1; @@ -1094,7 +1091,7 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags) dir_fd = open (dir, O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); if (flags->verbose) - error (0, 0, _("%s: removing"), quote (qoldname)); + error (0, 0, _("%s: removing"), qoldname); while ((flags->remove_file != remove_unlink) && len) { @@ -1119,7 +1116,7 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags) */ char const *old = (first ? qoldname : oldname); error (0, 0, _("%s: renamed to %s"), - quote_n (0, old), quote_n (1, newname)); + old, newname); first = false; } memcpy (oldname + (base - newname), base, len + 1); @@ -1141,18 +1138,18 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags) } if (unlink (oldname) != 0) { - error (0, errno, _("%s: failed to remove"), quote (qoldname)); + error (0, errno, _("%s: failed to remove"), qoldname); ok = false; } else if (flags->verbose) - error (0, 0, _("%s: removed"), quote (qoldname)); + error (0, 0, _("%s: removed"), qoldname); if (0 <= dir_fd) { if (dosync (dir_fd, qdir) != 0) ok = false; if (close (dir_fd) != 0) { - error (0, errno, _("%s: failed to close"), quote (qdir)); + error (0, errno, _("%s: failed to close"), qdir); ok = false; } } @@ -1188,14 +1185,14 @@ wipefile (char *name, char const *qname, fd = open (name, O_WRONLY | O_NOCTTY | O_BINARY); if (fd < 0) { - error (0, errno, _("%s: failed to open for writing"), quote (qname)); + error (0, errno, _("%s: failed to open for writing"), qname); return false; } ok = do_wipefd (fd, qname, s, flags); if (close (fd) != 0) { - error (0, errno, _("%s: failed to close"), quote (qname)); + error (0, errno, _("%s: failed to close"), qname); ok = false; } if (ok && flags->remove_file) @@ -1305,12 +1302,12 @@ main (int argc, char **argv) randint_source = randint_all_new (random_source, SIZE_MAX); if (! randint_source) - error (EXIT_FAILURE, errno, "%s", quotearg_colon (random_source)); + error (EXIT_FAILURE, errno, "%s", quote (random_source)); atexit (clear_random_data); for (i = 0; i < n_files; i++) { - char *qname = xstrdup (quotearg_colon (file[i])); + char *qname = xstrdup (quote (file[i])); if (STREQ (file[i], "-")) { ok &= wipefd (STDOUT_FILENO, qname, randint_source, &flags); diff --git a/src/shuf.c b/src/shuf.c index 040b00028..d7b5a3521 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -27,7 +27,6 @@ #include "getopt.h" #include "linebuffer.h" #include "quote.h" -#include "quotearg.h" #include "randint.h" #include "randperm.h" #include "read-file.h" @@ -545,7 +544,7 @@ main (int argc, char **argv) ? SIZE_MAX : randperm_bound (head_lines, n_lines))); if (! randint_source) - error (EXIT_FAILURE, errno, "%s", quotearg_colon (random_source)); + error (EXIT_FAILURE, errno, "%s", quote (random_source)); if (use_reservoir_sampling) { @@ -567,7 +566,7 @@ main (int argc, char **argv) permutation = randperm_new (randint_source, head_lines, n_lines); if (outfile && ! freopen (outfile, "w", stdout)) - error (EXIT_FAILURE, errno, "%s", quotearg_colon (outfile)); + error (EXIT_FAILURE, errno, "%s", quote (outfile)); /* Generate output according to requested method */ if (repeat) diff --git a/src/sort.c b/src/sort.c index 09231c44b..3e741027c 100644 --- a/src/sort.c +++ b/src/sort.c @@ -4612,7 +4612,7 @@ main (int argc, char **argv) unsigned long int file_number = i + 1; error (SORT_FAILURE, 0, _("%s:%lu: invalid zero-length file name"), - quotearg_colon (files_from), file_number); + quote (files_from), file_number); } } } diff --git a/src/stat.c b/src/stat.c index 680a598f0..a8a8c9d64 100644 --- a/src/stat.c +++ b/src/stat.c @@ -66,7 +66,6 @@ #include "getopt.h" #include "mountlist.h" #include "quote.h" -#include "quotearg.h" #include "stat-size.h" #include "stat-time.h" #include "strftime.h" @@ -1188,7 +1187,7 @@ print_it (char const *format, int fd, char const *filename, dest[len + 1] = *fmt_char; dest[len + 2] = '\0'; error (EXIT_FAILURE, 0, _("%s: invalid directive"), - quotearg_colon (dest)); + quote (dest)); } putchar ('%'); break; @@ -46,7 +46,6 @@ tac -r -s '.\| #include "error.h" #include "filenamecat.h" #include "quote.h" -#include "quotearg.h" #include "safe-read.h" #include "stdlib--.h" #include "xfreopen.h" @@ -221,7 +220,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"), quotearg_colon (file)); + error (0, errno, _("%s: seek failed"), quote (file)); } /* Scan backward, looking for end of file. This caters to proc-like @@ -231,7 +230,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"), quotearg_colon (file)); + error (0, errno, _("%s: seek failed"), quote (file)); file_pos -= read_size; } @@ -249,7 +248,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"), quotearg_colon (file)); + error (0, errno, _("%s: read error"), quote (file)); return false; } @@ -341,7 +340,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"), quotearg_colon (file)); + error (0, errno, _("%s: seek failed"), quote (file)); /* Shift the pending record data right to make room for the new. The source and destination regions probably overlap. */ @@ -355,7 +354,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"), quotearg_colon (file)); + error (0, errno, _("%s: read error"), quote (file)); return false; } } @@ -512,13 +511,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"), quotearg_colon (file)); + error (0, errno, _("%s: read error"), quote (file)); goto Fail; } if (fwrite (G_buffer, 1, bytes_read, fp) != bytes_read) { - error (0, errno, _("%s: write error"), quotearg_colon (file_name)); + error (0, errno, _("%s: write error"), quote (file_name)); goto Fail; } @@ -530,7 +529,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"), quotearg_colon (file_name)); + error (0, errno, _("%s: write error"), quote (file_name)); goto Fail; } @@ -598,7 +597,7 @@ tac_file (const char *filename) if (!is_stdin && close (fd) != 0) { - error (0, errno, _("%s: read error"), quotearg_colon (filename)); + error (0, errno, _("%s: read error"), quote (filename)); ok = false; } return ok; @@ -33,7 +33,6 @@ #include "mbchar.h" #include "physmem.h" #include "quote.h" -#include "quotearg.h" #include "readtokens0.h" #include "safe-read.h" #include "stat-size.h" @@ -765,7 +764,7 @@ main (int argc, char **argv) goto argv_iter_done; case AI_ERR_READ: error (0, errno, _("%s: read error"), - quotearg_colon (files_from)); + quote (files_from)); ok = false; goto argv_iter_done; case AI_ERR_MEM: @@ -798,7 +797,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", quotearg_colon (files_from), + error (0, 0, "%s:%lu: %s", quote (files_from), file_number, _("invalid zero-length file name")); } skip_file = true; |