maint: improve error messages upon failed read, write, access, close
authorBenno Schulenberg <bensberg@justemail.net>
Fri, 4 Jan 2013 21:45:34 +0000 (22:45 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 6 Feb 2013 15:57:34 +0000 (15:57 +0000)
Note we use "failed to {access,close}" for those single operations,
and "error {read,writ}ing" for those partial operation failures.

* 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
src/cp.c
src/dd.c
src/head.c
src/install.c
src/ln.c
src/mv.c
src/touch.c
src/truncate.c

index 60322b7..3f2cc2b 100644 (file)
@@ -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, _("failed to close %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, _("failed to close %s"), quote (src_name));
       return_val = false;
     }
 
index 0d64f9f..e235b32 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -567,7 +567,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;
@@ -1066,7 +1066,8 @@ 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));
index ef5664b..c98e578 100644 (file)
--- 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,8 @@ 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))
         {
index 306c1b8..d79d5f7 100644 (file)
@@ -859,7 +859,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, _("failed to close %s"), quote (filename));
       return false;
     }
   return ok;
index 55333c2..94374df 100644 (file)
@@ -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;
@@ -841,7 +841,8 @@ 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));
index e6c01b3..1aa1473 100644 (file)
--- 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;
         }
     }
@@ -512,7 +512,8 @@ 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));
index a5e8e08..1cfcd82 100644 (file)
--- 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;
 }
 
@@ -397,7 +397,8 @@ 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));
index 2806ef7..3a3ffbe 100644 (file)
@@ -169,7 +169,7 @@ touch (const char *file)
     {
       if (close (STDIN_FILENO) != 0)
         {
-          error (0, errno, _("closing %s"), quote (file));
+          error (0, errno, _("failed to close %s"), quote (file));
           return false;
         }
     }
index 44ff1cf..8349cb6 100644 (file)
@@ -414,7 +414,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, _("failed to close %s"), quote (fname));
               errors = true;
             }
         }