Hi Bruno, Collin, 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
Of which, the following are in ISO C:
localeconv
setlocale
strerror
> > 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().
I will mention within the committee that now that we've changed the
prototypes of string APIs --thus accepting breaking changes--, we could
embrace the const-correctness even further by changing the return types
of those functions too.
Thanks for the suggestion!
And indeed, I agree that changing the return values of those functions
is a good idea, as a gnulib extension (and hopefully also in the
standards).
I've reviewed 8724b4400aac (2026-06-07; "setlocale: Detect invalid
writes to the returned string in some cases."), and it LGTM. Thanks!
Should I also have a look at anything else from this thread?
Have a lovely night!
Alex
>
> Bruno
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
