Opened 3 years ago

Closed 3 years ago

#387 closed defect (wontfix)

Fix a prototype of putenv()

Reported by: KO Myung-Hun Owned by:
Priority: normal Milestone: new
Component: libc Version: 0.6.6
Severity: normal Keywords:
Cc:

Description

Hi/2.

A prototype of putenv() of kLIBC is:

int putenv(const char *);

But POSIX says at https://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html:

int putenv(char *);

It would be better to conform to POSIX. In addition, FreeBSD doesn't use const, too. See https://www.freebsd.org/cgi/man.cgi?query=putenv.

Change History (2)

comment:1 Changed 3 years ago by Silvan Scherrer

I suggest to open an issue at https://github.com/bitwiseworks/libc as well. As the change is probably higher we will fix it there.

comment:2 Changed 3 years ago by bird

Resolution: wontfix
Status: newclosed

The putenv() function has been taking an const char * argument since const became fashionable. Just look at the Microsoft and Watcom CRTs. From what I can tell, even the opengroup guys had it down with a const argument until issue 5 of their standard.

I cannot imagine how keeping it const char * would create trouble for you, unless you duplicate the prototype with the non-const argument. Which is silly anyway since the stdlib.h may be doing other tweaks to the function prototype that will make gcc barf.

However, making it 'char *' will certainly screw up things for existing source code, because passing a const string to a function taking a non-const argument will typically generate a warning (or an error if you're in paranoid -Werror mode, which I personally prefer). Anything written for windows, openwatcom, EMX or existing kLIBC will probably trigger this warning if they use putenv.

So, if you can convince me that this breaks lots of important source code, there is probably some #ifdef trickery that can be done in the header. Otherwise, forget it.

Note: See TracTickets for help on using tickets.