unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return.
@ 2011-12-21 21:38 David Edmondson
  2011-12-22  7:03 ` Austin Clements
  2011-12-22  9:32 ` [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return Dmitry Kurochkin
  0 siblings, 2 replies; 17+ messages in thread
From: David Edmondson @ 2011-12-21 21:38 UTC (permalink / raw)
  To: notmuch

---

The mechanism used here works for me in an isolated test case and no
warnings appear when using it as below, but I'm unsure why the
original warning that it is intended to address didn't appear when I
build. Any thoughts?

 compat/compat.h |    6 ++++++
 notmuch-new.c   |    2 +-
 notmuch-show.c  |    2 +-
 notmuch-tag.c   |    2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/compat/compat.h b/compat/compat.h
index 7767fe8..1160301 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -30,6 +30,12 @@
 extern "C" {
 #endif
 
+#ifdef __GNUC__
+#define ignore_result(x) ({ __typeof__(x) z = x; (void) sizeof (z); })
+#else /* !__GNUC__ */
+#define ignore_result(x) x
+#endif /* __GNUC__ */
+
 #if !HAVE_GETLINE
 #include <stdio.h>
 #include <unistd.h>
diff --git a/notmuch-new.c b/notmuch-new.c
index 3512de7..0ac04cc 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -67,7 +67,7 @@ handle_sigint (unused (int sig))
 {
     static char msg[] = "Stopping...         \n";
 
-    (void) write(2, msg, sizeof(msg)-1);
+    ignore_result(write(STDERR_FILENO, msg, sizeof(msg)-1));
     interrupted = 1;
 }
 
diff --git a/notmuch-show.c b/notmuch-show.c
index 19fb49f..681f778 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -866,7 +866,7 @@ do_show_single (void *ctx,
 
 	while (!feof (file)) {
 	    size = fread (buf, 1, sizeof (buf), file);
-	    (void) fwrite (buf, size, 1, stdout);
+	    ignore_result(fwrite (buf, size, 1, stdout));
 	}
 
 	fclose (file);
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 292c5da..2cbfdc3 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -26,7 +26,7 @@ static void
 handle_sigint (unused (int sig))
 {
     static char msg[] = "Stopping...         \n";
-    (void) write(2, msg, sizeof(msg)-1);
+    ignore_result(write(STDERR_FILENO, msg, sizeof(msg)-1));
     interrupted = 1;
 }
 
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-01-11 13:04 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21 21:38 [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return David Edmondson
2011-12-22  7:03 ` Austin Clements
2011-12-22  7:21   ` David Edmondson
2011-12-22 19:03     ` Austin Clements
2011-12-22 19:25       ` David Edmondson
2011-12-22 20:04         ` David Edmondson
2011-12-22 20:15         ` Austin Clements
2011-12-22 20:15           ` [PATCH] Properly handle short writes in sigint handlers Austin Clements
2011-12-23  8:10             ` David Edmondson
2011-12-23 12:30               ` Tomi Ollila
2011-12-25  0:38                 ` Austin Clements
2011-12-25  0:38               ` Austin Clements
2011-12-23 19:10             ` Dmitry Kurochkin
2012-01-10 11:13               ` David Bremner
2012-01-11 13:04                 ` Tomi Ollila
2011-12-22  9:32 ` [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return Dmitry Kurochkin
2011-12-22 11:24   ` David Edmondson

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).