From 1bb86c6f228f16bd4e15a83bac81f5fe521fe55e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 4 Jan 2013 22:45:34 +0100 Subject: [PATCH 2/2] textual: improve error messages upon failed read, write, access, close * src/copy.c: Improve error messages for failing read, write and close. * src/cp.c: Improve error messages for failing access. * src/dd.c: Improve error messages for failing read, write and open. * src/head.c: Improve error message for failing close. * src/install.c: Improve error messages for failing access. * src/ln.c: Likewise. * src/mv.c: Likewise. * src/touch.c: Improve error message for failing close. * src/truncate.c: Likewise. --- src/copy.c | 8 ++++---- src/cp.c | 4 ++-- src/dd.c | 12 ++++++------ src/head.c | 2 +- src/install.c | 4 ++-- src/ln.c | 8 ++++---- src/mv.c | 4 ++-- src/touch.c | 2 +- src/truncate.c | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/copy.c b/src/copy.c index 0decf9f..664a878 100644 --- a/src/copy.c +++ b/src/copy.c @@ -165,7 +165,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, { if (errno == EINTR) continue; - error (0, errno, _("reading %s"), quote (src_name)); + error (0, errno, _("error reading %s"), quote (src_name)); return false; } if (n_read == 0) @@ -203,7 +203,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, size_t n = n_read; if (full_write (dest_fd, buf, n) != n) { - error (0, errno, _("writing %s"), quote (dst_name)); + error (0, errno, _("error writing %s"), quote (dst_name)); return false; } @@ -1172,13 +1172,13 @@ preserve_metadata: close_src_and_dst_desc: if (close (dest_desc) < 0) { - error (0, errno, _("closing %s"), quote (dst_name)); + error (0, errno, _("error closing %s"), quote (dst_name)); return_val = false; } close_src_desc: if (close (source_desc) < 0) { - error (0, errno, _("closing %s"), quote (src_name)); + error (0, errno, _("error closing %s"), quote (src_name)); return_val = false; } diff --git a/src/cp.c b/src/cp.c index 231d6a3..a5eb67d 100644 --- a/src/cp.c +++ b/src/cp.c @@ -568,7 +568,7 @@ target_directory_operand (char const *file, struct stat *st, bool *new_dst) if (err) { if (err != ENOENT) - error (EXIT_FAILURE, err, _("accessing %s"), quote (file)); + error (EXIT_FAILURE, err, _("failed to access %s"), quote (file)); *new_dst = true; } return is_a_dir; @@ -1067,7 +1067,7 @@ main (int argc, char **argv) { struct stat st; if (stat (optarg, &st) != 0) - error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); + error (EXIT_FAILURE, errno, _("failed to access %s"), quote (optarg)); if (! S_ISDIR (st.st_mode)) error (EXIT_FAILURE, 0, _("target %s is not a directory"), quote (optarg)); diff --git a/src/dd.c b/src/dd.c index 4e35df0..9d8f073 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1614,7 +1614,7 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize, { if (fdesc == STDIN_FILENO) { - error (0, errno, _("reading %s"), quote (file)); + error (0, errno, _("error reading %s"), quote (file)); if (conversions_mask & C_NOERROR) print_stats (); } @@ -1981,7 +1981,7 @@ dd_copy (void) if (nread < 0) { - error (0, errno, _("reading %s"), quote (input_file)); + error (0, errno, _("error reading %s"), quote (input_file)); if (conversions_mask & C_NOERROR) { print_stats (); @@ -2044,7 +2044,7 @@ dd_copy (void) w_bytes += nwritten; if (nwritten != n_bytes_read) { - error (0, errno, _("writing %s"), quote (output_file)); + error (0, errno, _("error writing %s"), quote (output_file)); return EXIT_FAILURE; } else if (n_bytes_read == input_blocksize) @@ -2107,7 +2107,7 @@ dd_copy (void) w_partial++; if (nwritten != oc) { - error (0, errno, _("writing %s"), quote (output_file)); + error (0, errno, _("error writing %s"), quote (output_file)); return EXIT_FAILURE; } } @@ -2204,7 +2204,7 @@ main (int argc, char **argv) else { if (fd_reopen (STDIN_FILENO, input_file, O_RDONLY | input_flags, 0) < 0) - error (EXIT_FAILURE, errno, _("opening %s"), quote (input_file)); + error (EXIT_FAILURE, errno, _("failed to open %s"), quote (input_file)); } offset = lseek (STDIN_FILENO, 0, SEEK_CUR); @@ -2233,7 +2233,7 @@ main (int argc, char **argv) || fd_reopen (STDOUT_FILENO, output_file, O_RDWR | opts, perms) < 0) && (fd_reopen (STDOUT_FILENO, output_file, O_WRONLY | opts, perms) < 0)) - error (EXIT_FAILURE, errno, _("opening %s"), quote (output_file)); + error (EXIT_FAILURE, errno, _("failed to open %s"), quote (output_file)); if (seek_records != 0 && !(conversions_mask & C_NOTRUNC)) { diff --git a/src/head.c b/src/head.c index c13c064..38596b8 100644 --- a/src/head.c +++ b/src/head.c @@ -860,7 +860,7 @@ head_file (const char *filename, uintmax_t n_units, bool count_lines, ok = head (filename, fd, n_units, count_lines, elide_from_end); if (!is_stdin && close (fd) != 0) { - error (0, errno, _("closing %s"), quote (filename)); + error (0, errno, _("error closing %s"), quote (filename)); return false; } return ok; diff --git a/src/install.c b/src/install.c index 8ea5491..8852a1d 100644 --- a/src/install.c +++ b/src/install.c @@ -399,7 +399,7 @@ target_directory_operand (char const *file) int err = (stat (file, &st) == 0 ? 0 : errno); bool is_a_dir = !err && S_ISDIR (st.st_mode); if (err && err != ENOENT) - error (EXIT_FAILURE, err, _("accessing %s"), quote (file)); + error (EXIT_FAILURE, err, _("failed to access %s"), quote (file)); if (is_a_dir < looks_like_a_dir) error (EXIT_FAILURE, err, _("target %s is not a directory"), quote (file)); return is_a_dir; @@ -842,7 +842,7 @@ main (int argc, char **argv) { struct stat st; if (stat (optarg, &st) != 0) - error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); + error (EXIT_FAILURE, errno, _("failed to access %s"), quote (optarg)); if (! S_ISDIR (st.st_mode)) error (EXIT_FAILURE, 0, _("target %s is not a directory"), quote (optarg)); diff --git a/src/ln.c b/src/ln.c index 8d5e31e..4b679f5 100644 --- a/src/ln.c +++ b/src/ln.c @@ -120,7 +120,7 @@ target_directory_operand (char const *file) int err = (stat_result == 0 ? 0 : errno); bool is_a_dir = !err && S_ISDIR (st.st_mode); if (err && err != ENOENT) - error (EXIT_FAILURE, err, _("accessing %s"), quote (file)); + error (EXIT_FAILURE, err, _("failed to access %s"), quote (file)); if (is_a_dir < looks_like_a_dir) error (EXIT_FAILURE, err, _("target %s is not a directory"), quote (file)); return is_a_dir; @@ -178,7 +178,7 @@ do_link (const char *source, const char *dest) : lstat (source, &source_stats)) != 0) { - error (0, errno, _("accessing %s"), quote (source)); + error (0, errno, _("failed to access %s"), quote (source)); return false; } @@ -199,7 +199,7 @@ do_link (const char *source, const char *dest) dest_lstat_ok = (lstat (dest, &dest_stats) == 0); if (!dest_lstat_ok && errno != ENOENT) { - error (0, errno, _("accessing %s"), quote (dest)); + error (0, errno, _("failed to access %s"), quote (dest)); return false; } } @@ -513,7 +513,7 @@ main (int argc, char **argv) { struct stat st; if (stat (optarg, &st) != 0) - error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); + error (EXIT_FAILURE, errno, _("failed to access %s"), quote (optarg)); if (! S_ISDIR (st.st_mode)) error (EXIT_FAILURE, 0, _("target %s is not a directory"), quote (optarg)); diff --git a/src/mv.c b/src/mv.c index 5b08fdd..54015cc 100644 --- a/src/mv.c +++ b/src/mv.c @@ -151,7 +151,7 @@ target_directory_operand (char const *file) int err = (stat (file, &st) == 0 ? 0 : errno); bool is_a_dir = !err && S_ISDIR (st.st_mode); if (err && err != ENOENT) - error (EXIT_FAILURE, err, _("accessing %s"), quote (file)); + error (EXIT_FAILURE, err, _("failed to access %s"), quote (file)); return is_a_dir; } @@ -398,7 +398,7 @@ main (int argc, char **argv) { struct stat st; if (stat (optarg, &st) != 0) - error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); + error (EXIT_FAILURE, errno, _("failed to access %s"), quote (optarg)); if (! S_ISDIR (st.st_mode)) error (EXIT_FAILURE, 0, _("target %s is not a directory"), quote (optarg)); diff --git a/src/touch.c b/src/touch.c index 3d93464..dd6f4c0 100644 --- a/src/touch.c +++ b/src/touch.c @@ -169,7 +169,7 @@ touch (const char *file) { if (close (STDIN_FILENO) != 0) { - error (0, errno, _("closing %s"), quote (file)); + error (0, errno, _("error closing %s"), quote (file)); return false; } } diff --git a/src/truncate.c b/src/truncate.c index d638993..186c526 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -415,7 +415,7 @@ main (int argc, char **argv) errors |= !do_ftruncate (fd, fname, size, rsize, rel_mode); if (close (fd) != 0) { - error (0, errno, _("closing %s"), quote (fname)); + error (0, errno, _("error closing %s"), quote (fname)); errors = true; } } -- 1.7.0.4