# HG changeset patch # User Jim Meyering # Date 1251796841 -7200 # Node ID 4934b28baa2baa72f7bf73b89ae7ed510e6a59bd # Parent 10d064d93551e7acabaf31afab97a61d5131cfc7 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 --- 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 --- a/lib/fts_.h +++ b/lib/fts_.h @@ -233,12 +233,30 @@ 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