From: Paul Eggert Date: Thu, 19 Oct 2006 05:22:54 +0000 (+0000) Subject: * src/copy.c (copy_reg): Rewrite slightly to avoid duplicte code X-Git-Tag: COREUTILS-6_4~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=86823158eb72dd472499cba2fb2e947f69afae72;p=thirdparty%2Fcoreutils.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 86e7d849be..2141be0661 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-10-18 Paul Eggert + * 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 d9a727aa91..3cc8094593 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);