summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-10-19 05:22:54 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-10-19 05:22:54 +0000
commit86823158eb72dd472499cba2fb2e947f69afae72 (patch)
tree378fbc64d921b31c7b522d82cdeade697db0560b
parent81afea011033c0389ff03cfd4cc968f0b0cefaf0 (diff)
downloadcoreutils-86823158eb72dd472499cba2fb2e947f69afae72.tar.xz
* src/copy.c (copy_reg): Rewrite slightly to avoid duplicte code
when opening dst_name. (copy_reg, copy_internal): Use (SYSCALL != 0) rather than plain (SYSCALL) to test for failure in a system call.
-rw-r--r--ChangeLog5
-rw-r--r--src/copy.c20
2 files changed, 13 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 86e7d849b..2141be066 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2006-10-18 Paul Eggert <eggert@cs.ucla.edu>
+ * src/copy.c (copy_reg): Rewrite slightly to avoid duplicte code
+ when opening dst_name.
+ (copy_reg, copy_internal): Use (SYSCALL != 0) rather than plain
+ (SYSCALL) to test for failure in a system call.
+
* src/copy.c (copy_internal): Use mknod rather than mkfifo to copy
a fifo. This preserves the special mode bits on Solaris 10, which
is compatible with what Solaris 10 cp -R does.
diff --git a/src/copy.c b/src/copy.c
index d9a727aa9..3cc809459 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -260,7 +260,7 @@ copy_reg (char const *src_name, char const *dst_name,
return false;
}
- if (fstat (source_desc, &src_open_sb))
+ if (fstat (source_desc, &src_open_sb) != 0)
{
error (0, errno, _("cannot fstat %s"), quote (src_name));
return_val = false;
@@ -280,11 +280,7 @@ copy_reg (char const *src_name, char const *dst_name,
/* These semantics are required for cp.
The if-block will be taken in move_mode. */
- if (*new_dst)
- {
- dest_desc = open (dst_name, O_WRONLY | O_CREAT | O_BINARY, dst_mode);
- }
- else
+ if (! *new_dst)
{
dest_desc = open (dst_name, O_WRONLY | O_TRUNC | O_BINARY, dst_mode);
@@ -301,12 +297,12 @@ copy_reg (char const *src_name, char const *dst_name,
/* Tell caller that the destination file was unlinked. */
*new_dst = true;
-
- /* Try the open again, but this time with different flags. */
- dest_desc = open (dst_name, O_WRONLY | O_CREAT | O_BINARY, dst_mode);
}
}
+ if (*new_dst)
+ dest_desc = open (dst_name, O_WRONLY | O_CREAT | O_BINARY, dst_mode);
+
if (dest_desc < 0)
{
error (0, errno, _("cannot create regular file %s"), quote (dst_name));
@@ -314,7 +310,7 @@ copy_reg (char const *src_name, char const *dst_name,
goto close_src_desc;
}
- if (fstat (dest_desc, &sb))
+ if (fstat (dest_desc, &sb) != 0)
{
error (0, errno, _("cannot fstat %s"), quote (dst_name));
return_val = false;
@@ -1580,8 +1576,8 @@ copy_internal (char const *src_name, char const *dst_name,
/* If either stat call fails, it's ok not to report
the failure and say dst_name is in the current
directory. Other things will fail later. */
- || stat (".", &dot_sb)
- || stat (dst_parent, &dst_parent_sb)
+ || stat (".", &dot_sb) != 0
+ || stat (dst_parent, &dst_parent_sb) != 0
|| SAME_INODE (dot_sb, dst_parent_sb));
free (dst_parent);