summaryrefslogtreecommitdiff
path: root/src/shred.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-10-28 13:02:31 +0000
committerPádraig Brady <P@draigBrady.com>2015-11-04 02:03:41 +0000
commitab40a941a07d80326aaa051e3c94c88b800cbd7d (patch)
tree382e656f126d0e63ca1158f8f43630e1dd10d18b /src/shred.c
parent00eb7af8ea30ccbefeb17213cd644b8f0ade1ef8 (diff)
downloadcoreutils-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/shred.c')
-rw-r--r--src/shred.c55
1 files changed, 26 insertions, 29 deletions
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);