Skip to content

fix C23 compatibility for getenv/getopt prototypes#97

Open
codingWiz-rick wants to merge 1 commit intoProject-OSS-Revival:masterfrom
codingWiz-rick:fix-c23-prototypes
Open

fix C23 compatibility for getenv/getopt prototypes#97
codingWiz-rick wants to merge 1 commit intoProject-OSS-Revival:masterfrom
codingWiz-rick:fix-c23-prototypes

Conversation

@codingWiz-rick
Copy link
Copy Markdown

GCC 15 defaults to C23, which no longer supports unprototyped function declarations (K&R style). This fixes conflicts with strict prototypes in modern C libraries like musl.

Build-tested in Buildroot using musl libc and C23.

Files Modified

  1. src/getopt.h: Added full prototypes for getopt, getopt_long, getopt_long_only, and _getopt_internal to replace the old-style () declarations.
  2. src/getopt_long.c: Added the proper prototype for getenv(const char *name) instead of the unprototyped getenv().

GCC 15 defaults to C23, which no longer supports unprototyped function
declarations (K&R style). This fixes conflicts with strict prototypes
in modern C libraries like musl.

Build-tested in Buildroot using musl libc and C23.

Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
@Syed-Shahrukh-OSSRevival
Copy link
Copy Markdown
Member

Thank you for your contribution!

Though from a older version, both these files are from original gcc sources.
src/getopt.h

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=include/getopt.h;h=7e1eaef6b45fceb446ac6569657d5c8c9a5123f3;hb=HEAD

src/getopt_long.c‎

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libiberty/getopt.c;h=3b6e35946e10c804e274926b3c252c3d0ca12507;hb=HEAD
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libiberty/getopt1.c;h=6a3e9abd6f4a39c9d77d2b0b6ee27c5b6621bec6;hb=HEAD

The changes for src/getopt_long.c‎ can be merged as it does not change the behavior of library for incompatible API declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants