[bug] string.h inadequately respects __POSIX_VISIBLE

Colin Percival cperciva@tarsnap.com
Thu Jul 2 07:41:00 GMT 2015

[Please CC on replies, since I'm not subscribed to the list.]

Hi all,

I distribute some code (spiped) which sets _POSIX_C_SOURCE=200809L, in an
attempt at strict POSIX conformance.  Alas, this triggers a conformance
bug in newlib.

In newlib/libc/include/sys/cdefs.h this value is correctly translated to

 654 #if _POSIX_C_SOURCE >= 200809
 655 #define __POSIX_VISIBLE         200809
 656 #define __ISO_C_VISIBLE         1999

but __POSIX_VISIBLE is not respected in newlib/libc/include/string.h when
strdup is declared:
  79 #if __XSI_VISIBLE >= 500
  80 char    *_EXFUN(strdup,(const char *));
  81 #endif

The test in this case should be
     #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500

It looks like strdup is the only function you're missing from string.h,
but there are several others which you're declaring unconditionally or
simply based on __POSIX_VISIBLE being defined rather than checking the
exact value.  I haven't checked the other header files in your libc.

Colin Percival
Security Officer Emeritus, FreeBSD | The power to serve
Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid

More information about the Newlib mailing list