fts: help ensure that return values are not ignored
authorJim Meyering <meyering@redhat.com>
Tue, 1 Sep 2009 09:20:41 +0000 (11:20 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 1 Sep 2009 09:29:04 +0000 (11:29 +0200)
* lib/fts_.h (__GNUC_PREREQ): Define.
(__attribute_warn_unused_result__): Define.
(fts_children, fts_close, fts_open, fts_read): Declare with
__attribute_warn_unused_result__.

ChangeLog
lib/fts_.h

index 89cf0ee..efb2906 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-09-01  Jim Meyering  <meyering@redhat.com>
 
+       fts: help ensure that return values are not ignored
+       * lib/fts_.h (__GNUC_PREREQ): Define.
+       (__attribute_warn_unused_result__): Define.
+       (fts_children, fts_close, fts_open, fts_read): Declare with
+       __attribute_warn_unused_result__.
+
        fts: fts_close now fails also when closing a dir file descriptor fails
        * lib/fts.c (fts_close): Detect close failure, not just fchdir failure,
        and propagate to caller, along with errno.
index ad339ca..0e2d505 100644 (file)
@@ -233,12 +233,30 @@ typedef struct _ftsent {
        char fts_name[1];               /* file name */
 } FTSENT;
 
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+#  define __GNUC_PREREQ(maj, min) \
+         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#if __GNUC_PREREQ (3,4)
+# undef __attribute_warn_unused_result__
+# define __attribute_warn_unused_result__ \
+   __attribute__ ((__warn_unused_result__))
+#else
+# define __attribute_warn_unused_result__ /* empty */
+#endif
+
 __BEGIN_DECLS
-FTSENT *fts_children (FTS *, int) __THROW;
-int     fts_close (FTS *) __THROW;
+FTSENT *fts_children (FTS *, int) __THROW __attribute_warn_unused_result__;
+int     fts_close (FTS *) __THROW __attribute_warn_unused_result__;
 FTS    *fts_open (char * const *, int,
-                  int (*)(const FTSENT **, const FTSENT **)) __THROW;
-FTSENT *fts_read (FTS *) __THROW;
+                  int (*)(const FTSENT **, const FTSENT **))
+  __THROW __attribute_warn_unused_result__;
+FTSENT *fts_read (FTS *) __THROW __attribute_warn_unused_result__;
 int     fts_set (FTS *, FTSENT *, int) __THROW;
 __END_DECLS