[Midnightbsd-cvs] [MidnightBSD/src] 9603e1: libc: getopt{, _long}: const correctness for C23

Lucas Holt noreply at github.com
Mon Aug 3 11:39:33 EDT 2026


  Branch: refs/heads/master
  Home:   https://github.com/MidnightBSD/src
  Commit: 9603e14c55d586a42a14fd4eb415ac6d8a1bcc7f
      https://github.com/MidnightBSD/src/commit/9603e14c55d586a42a14fd4eb415ac6d8a1bcc7f
  Author: Lucas Holt <luke at foolishgames.com>
  Date:   2026-08-03 (Mon, 03 Aug 2026)

  Changed paths:
    M lib/libc/stdlib/getopt.c
    M lib/libc/stdlib/getopt_long.c

  Log Message:
  -----------
  libc: getopt{,_long}: const correctness for C23

C23 makes strchr() preserve the constness of its argument, returning a
const pointer when it is passed one.  getopt() and getopt_internal()
assign that result to a plain char *, which breaks the bootstrap build
on hosts whose libc has adopted the new behaviour: tools/build/Makefile
compiles both of these files out of lib/libc against the host's headers,
precisely so that cross-builds from Linux and macOS do not pick up the
host getopt().

The pointed-to string is only ever read -- oli is dereferenced for
oli[1] and oli[2], and the ++ in *++oli advances the pointer rather than
the string -- so declaring it const is enough, and assigning from
strchr() remains valid under both the old and the C23 signatures.

Obtained from:	FreeBSD (f1d98862044f)
AI-Assisted-by: Claude Opus 5

Co-Authored-By: Claude Opus 5 (1M context) <noreply at anthropic.com>
Signed-off-by: Lucas Holt <luke at foolishgames.com>



To unsubscribe from these emails, change your notification settings at https://github.com/MidnightBSD/src/settings/notifications


More information about the Midnightbsd-cvs mailing list