summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenno Schulenberg <bensberg@justemail.net>2013-01-04 22:45:34 +0100
committerPádraig Brady <P@draigBrady.com>2013-02-06 15:57:34 +0000
commita1ee5cd714c0825b0244d09bbaa0a61c883ac18f (patch)
treeb5b0308b264b9be73dbeb1723bef30b00ab69545 /src
parent6a404ec16555bc0757ff06d99af96c12bfbc235e (diff)
downloadcoreutils-a1ee5cd714c0825b0244d09bbaa0a61c883ac18f.tar.xz
maint: improve error messages upon failed read, write, access, close
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.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c8
-rw-r--r--src/cp.c5
-rw-r--r--src/dd.c13
-rw-r--r--src/head.c2
-rw-r--r--src/install.c5
-rw-r--r--src/ln.c9
-rw-r--r--src/mv.c5
-rw-r--r--src/touch.c2
-rw-r--r--src/truncate.c2
9 files changed, 28 insertions, 23 deletions
diff --git a/src/copy.c b/src/copy.c
index 60322b794..3f2cc2b0c 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, _("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;
}
diff --git a/src/cp.c b/src/cp.c
index 0d64f9f5e..e235b326d 100644
--- 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));
diff --git a/src/dd.c b/src/dd.c
index ef5664bf4..c98e578fe 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,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))
{
diff --git a/src/head.c b/src/head.c
index 306c1b884..d79d5f7de 100644
--- a/src/head.c
+++ b/src/head.c
@@ -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;
diff --git a/src/install.c b/src/install.c
index 55333c257..94374df3e 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;
@@ -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));
diff --git a/src/ln.c b/src/ln.c
index e6c01b3fa..1aa147324 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;
}
}
@@ -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));
diff --git a/src/mv.c b/src/mv.c
index a5e8e089d..1cfcd82f7 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;
}
@@ -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));
diff --git a/src/touch.c b/src/touch.c
index 2806ef71d..3a3ffbe0f 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, _("failed to close %s"), quote (file));
return false;
}
}
diff --git a/src/truncate.c b/src/truncate.c
index 44ff1cf47..8349cb61a 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -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;
}
}