Hi Bruno,

On 2026-06-07T21:35:07+0200, Bruno Haible wrote:
> Collin Funk wrote:
> > > But we can add the intended return type in Gnulib. Done as follows. This
> > > patch removes two casts, instead of adding a cast.
> > 
> > I considered suggesting this as well for the same reason you mention,
> > i.e., the standard saying the returned string cannot be modified. But I
> > mistakenly assumed you would not want to diverge from the standardized
> > prototype.
> 
> We had some (conditional) change of return type from 'char *' to 'const char 
> *',
> or from 'void *' to 'const void *', in functions like strchr and memchr,
> and although it was a bit of a hassle for the people who maintain very old
> packages, it was a worthwhile modernization.
> 
> In POSIX, the following functions are marked with
>   "The application shall not modify the string returned."
> and could therefore be modernized:
>   ctermid
>   dlerror
>   getgrent
>   getgrgid, getgrnam
>   gethostent
>   getlogin
>   getnetent, getnetbyaddr, getnetbyname
>   getprotoent, getprotobyname, getprotobynumber
>   getpwent, getpwnam, getpwuid
>   getservent, getservbyname, getservbyport
>   localeconv
>   nl_langinfo, nl_langinfo_l
>   ptsname
>   setlocale
>   strerror, strerror_l
>   strsignal
>   ttyname
>   *gettext, *gettext_l

getenv(3) should also be included in that list, I believe.  It is also
in ISO C, so you may want to change it already, in order to provide
prior art for WG14.


Cheers,
Alex

> 
> > I vaguely remember
> > POSIX being willing to change the return type of gettext to be "const
> > char *" for similar reasons
> 
> That would be useful too, yes.
> 
> > Perhaps it is worth bringing this up with the ISO C people.
> 
> Yes, that would be useful, both for setlocale() and for localeconv().
> 
> Bruno
> 
> 
> 

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to