bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copy-file.c vs ignoring chown's return value


From: Jim Meyering
Subject: copy-file.c vs ignoring chown's return value
Date: Tue, 01 Mar 2011 15:24:28 +0100

Hi Bruno,

We're about to use the copy-file module in iwhd,
and I'm seeing this warning/error with our gcc options:

  copy-file.c: In function 'copy_file_preserving':
  copy-file.c:120:9: error: ignoring return value of 'chown', declared with 
attribute warn_unused_result [-Wunused-result]

I see two ways to address the problem.
One is to add this pragma along with a comment somewhere in copy-file.c:

    # pragma GCC diagnostic ignored "-Wunused-result"

but that seems unwise.  In a file like that, it would be all too easy to
introduce a real bug that would be warned about by -Wunused-result.
IMHO, we must not turn off that option.

How about this patch instead?

>From 6b8f3f6439d77ad4b84765eaee9eab501bd0d4de Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 1 Mar 2011 15:20:33 +0100
Subject: [PATCH] copy-file: ignore warning about chown's unused return value

* lib/copy-file.c: Include "ignore-value.h".
(copy_file_preserving): Ignore chown failure.
* modules/copy-file (Depends-on): Add ignore-value.
---
 ChangeLog         |    7 +++++++
 lib/copy-file.c   |    3 ++-
 modules/copy-file |    1 +
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ceff3bf..1d85cf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-01  Jim Meyering  <address@hidden>
+
+       copy-file: ignore warning about chown's unused return value
+       * lib/copy-file.c: Include "ignore-value.h".
+       (copy_file_preserving): Ignore chown failure.
+       * modules/copy-file (Depends-on): Add ignore-value.
+
 2011-02-28  Paul Eggert  <address@hidden>

        stdio: simplify by moving files to printf-posix, sigpipe
diff --git a/lib/copy-file.c b/lib/copy-file.c
index f9cd9c0..27a35c2 100644
--- a/lib/copy-file.c
+++ b/lib/copy-file.c
@@ -42,6 +42,7 @@
 #include "acl.h"
 #include "binary-io.h"
 #include "gettext.h"
+#include "ignore-value.h"
 #include "xalloc.h"

 #define _(str) gettext (str)
@@ -117,7 +118,7 @@ copy_file_preserving (const char *src_filename, const char 
*dest_filename)

 #if HAVE_CHOWN
   /* Preserve the owner and group.  */
-  chown (dest_filename, statbuf.st_uid, statbuf.st_gid);
+  ignore_value (chown (dest_filename, statbuf.st_uid, statbuf.st_gid));
 #endif

   /* Preserve the access permissions.  */
diff --git a/modules/copy-file b/modules/copy-file
index 6941e5a..ab25b6b 100644
--- a/modules/copy-file
+++ b/modules/copy-file
@@ -13,6 +13,7 @@ error
 exit
 full-write
 gettext-h
+ignore-value
 open
 safe-read
 unistd
--
1.7.4.1.21.g4cc62



reply via email to

[Prev in Thread] Current Thread [Next in Thread]