From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-04-04 08:43:20


On Mon, Apr 04, 2005 at 12:24:26PM +0100, John Maddock wrote:

> >The code in question is:
> >
> ># if defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
> > && defined(_SC_THREAD_SAFE_FUNCTIONS) \
> > && _POSIX_THREAD_SAFE_FUNCTIONS >= 0
> > if ( ::sysconf( _SC_THREAD_SAFE_FUNCTIONS ) >= 0 )
> > { return ::readdir_r( dirp, entry, result ); }
> ># endif
> >
> >Seems like _POSIX_THREAD_SAFE_FUNCTIONS but doesn't expand to anything.
>
> That's a common problem with the POSIX feature test macros, the workaround
> is to use :
>
> (_POSIX_THREAD_SAFE_FUNCTIONS+0 >= 0)

Out of interest, why can't you just use _SC_THREAD_SAFE_FUNCTIONS if it's
defined?

Also, if _POSIX_THREAD_SAFE_FUNCTIONS == 0, I thought that meant *not*
supported (in which case sysconf() would return -1) ? Does the test have
to be >= not just > ?

I'd have written it:

# if defined(_SC_THREAD_SAFE_FUNCTIONS)
      if ( ::sysconf( _SC_THREAD_SAFE_FUNCTIONS ) > 0 )
        { return ::readdir_r( dirp, entry, result ); }
# endif

But I didn't realise this wasn't good enough :-|

Finally, readdir_r() is available on FreeBSD even though neither
_POSIX_THREAD_SAFE_FUNCTIONS not _SC_THREAD_SAFE_FUNCTIONS is defined.
I don't know how to test for it though, FreeBSD's sysconf() only claims
to support POSIX 1990, even though some later interfaces are available.

jon