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

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Jan 22 16:12:59 GMT 2024


On Jan 22 16:47, Christian Franke via Cygwin wrote:
> 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.

Counter proposal:

First of all, Cygwin does NOT export itoa/utoa!  Only the prototypes
exist from the Cygwin POV.

As Cygwin is usually the only newlib project with backward compat
issues, we have two simple choices:

- Drop itoa/utoa entirely, or
- just guard them with

    #if __MISC_VISIBLE && !defined (__CYGWIN__)

You can make a proposal like that on the newlib list and then we can
discuss it there, ok?


Corinna


More information about the Cygwin mailing list