From: Jim Meyering Date: Tue, 1 Sep 2009 09:20:41 +0000 (+0200) Subject: fts: help ensure that return values are not ignored X-Git-Tag: v0.1~5562 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=9b740ea4bcb104eeceb0c847a376d2b7dbb77d1b;p=gnulib.git 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__. --- diff --git a/ChangeLog b/ChangeLog index 89cf0ee67..efb29064f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-09-01 Jim Meyering + 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. diff --git a/lib/fts_.h b/lib/fts_.h index ad339cab5..0e2d505af 100644 --- a/lib/fts_.h +++ b/lib/fts_.h @@ -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