git: f1d98862044f - main - libc: getopt{,_long}: Const correctness for C23

Lexi Winter <[email protected]> Mon, 03 Aug 2026 14:30:40 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a70a610.37a4b.9b19e8a__16852.1072411508$1785767461$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by ivy:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1d98862044f7748c6f930e9d4339abc166a5b16

commit f1d98862044f7748c6f930e9d4339abc166a5b16
Author:     Lexi Winter <[email protected]>
AuthorDate: 2026-08-03 14:02:51 +0000
Commit:     Lexi Winter <[email protected]>
CommitDate: 2026-08-03 14:02:51 +0000

    libc: getopt{,_long}: Const correctness for C23
    
    On some platforms, e.g. Linux Clang 22.1.8 / glibc 2.43, strchr()
    now implements the C23 behaviour where passing a const pointer to
    strchr() also returns a const pointer.  This breaks getopt during
    the bootstrap build, since it assumes the return value is always
    a mutable pointer.
    
    Since the pointed-to value is never modified, fix this by making
    the pointer const.
    
    MFC after:      1 week
    Reviewed by:    emaste
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58488
---
 lib/libc/stdlib/getopt.c      | 2 +-
 lib/libc/stdlib/getopt_long.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libc/stdlib/getopt.c b/lib/libc/stdlib/getopt.c
index 2b5e3fa69032..e1edc5a3ee83 100644
--- a/lib/libc/stdlib/getopt.c
+++ b/lib/libc/stdlib/getopt.c
@@ -57,7 +57,7 @@ int
 getopt(int nargc, char * const nargv[], const char *ostr)
 {
 	static char *place = EMSG;		/* option letter processing */
-	char *oli;				/* option letter list index */
+	const char *oli;			/* option letter list index */
 
 	if (optreset || *place == 0) {		/* update scanning pointer */
 		optreset = 0;
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c
index 5cf6a55649bd..99be520fe332 100644
--- a/lib/libc/stdlib/getopt_long.c
+++ b/lib/libc/stdlib/getopt_long.c
@@ -349,7 +349,7 @@ static int
 getopt_internal(int nargc, char * const *nargv, const char *options,
 	const struct option *long_options, int *idx, int flags)
 {
-	char *oli;				/* option letter list index */
+	const char *oli;			/* option letter list index */
 	int optchar, short_too;
 	static int posixly_correct = -1;