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.
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;
/* 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);
/* 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));
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;
/* 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);