Add ability to hide non-standard itoa/utoa() in stdlib.h ?

Christian Franke Christian.Franke@t-online.de
Mon Jan 22 15:47:00 GMT 2024


Busybox does not build OOTB on Cygwin due to the addition of itoa/utoa() 
to newlib in 2014:
https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=32c96dd

This is because Busybox use local functions with same name but different 
signature. This does not affect build on FreeBSD, Linux (glibc, musl 
libc), ... because these functions simply do not exits there. For the 
busybox Cygwin package, I use an ugly local hack to fix this.

itoa() is mentioned as a non-standard extension here:
https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa
https://cplusplus.com/reference/cstdlib/itoa/

MSVC provides itoa() as a "POSIX version" of _itoa():
https://learn.microsoft.com/cpp/c-runtime-library/reference/itoa-itow

But SUS-1997... POSIX-2018 do not mention these functions:
https://pubs.opengroup.org/onlinepubs/7908799/
https://pubs.opengroup.org/onlinepubs/9699919799/

Newlib guards the prototypes with __MISC_VISIBLE in stdlib.h and 
sys/features.h says:

  * __MISC_VISIBLE
  *      Extensions found in both BSD and SVr4 (shorthand for
  *      (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
  *      extensions; enabled by default.

__MISC_VISIBLE is set if and only if _DEFAULT_SOURCE is set, so the 
comment below should also include "... or newlib-specific extensions":

  * _DEFAULT_SOURCE (or none of the above)
  *     POSIX-1.2008 with BSD and SVr4 extensions


The above is not suitable to disable only the non-standard functions for 
such use cases. Using -D_GNU_SOURCE should IMO not enable functions 
unavailable on Linux. This is not the case because _GNU_SOURCE implies 
_DEFAULT_SOURCE.

No patch provided for now, as I'm not yet sure how to handle this. Possibly:

- Use __MISC_VISIBLE only for (__BSD_VISIBLE || __SVID_VISIBLE) - under 
the assumption that this is applicable for most cases.
- Introduce __NONSTD_VISIBLE for non-standard functions like itoa().
- Introduce _NONSTD_SOURCE to set __NONSTD_VISIBLE independent from 
other _*_SOURCE defines.

-- 
Regards,
Christian



More information about the Cygwin mailing list