diff options
| author | Lexi Winter <ivy@FreeBSD.org> | 2026-08-03 14:02:51 +0000 |
|---|---|---|
| committer | Lexi Winter <ivy@FreeBSD.org> | 2026-08-03 14:02:51 +0000 |
| commit | f1d98862044f7748c6f930e9d4339abc166a5b16 (patch) | |
| tree | 376e4b8970023c7d5b76e70f1fee6e045feda221 | |
| parent | 0787b1f5b8bdfcaed97eeee7bfbd7f14ac162b0d (diff) | |
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
| -rw-r--r-- | lib/libc/stdlib/getopt.c | 2 | ||||
| -rw-r--r-- | 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; |
