Skip to content

Commit 3597d66

Browse files
src: fix C23 compatibility for getenv/getopt prototypes
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>
1 parent d4e4e59 commit 3597d66

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/getopt.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct option
144144
errors, only prototype getopt for the GNU C library. */
145145
extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
146146
# else /* not __GNU_LIBRARY__ */
147-
extern int getopt ();
147+
extern int getopt (int argc, char * const argv[], const char *shortopts);
148148
# endif /* __GNU_LIBRARY__ */
149149

150150
# ifndef __need_getopt
@@ -161,12 +161,18 @@ extern int _getopt_internal (int __argc, char *const *__argv,
161161
int __long_only);
162162
# endif
163163
#else /* not __STDC__ */
164-
extern int getopt ();
164+
extern int getopt (int argc, char * const argv[], const char *shortopts);
165165
# ifndef __need_getopt
166-
extern int getopt_long ();
167-
extern int getopt_long_only ();
166+
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
167+
const struct option *longopts, int *longind);
168+
extern int getopt_long_only (int argc, char *const *argv,
169+
const char *shortopts,
170+
const struct option *longopts, int *longind);
168171

169-
extern int _getopt_internal ();
172+
extern int _getopt_internal (int __argc, char *const *__argv,
173+
const char *__shortopts,
174+
const struct option *__longopts, int *__longind,
175+
int __long_only);
170176
# endif
171177
#endif /* __STDC__ */
172178

src/getopt_long.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static char *posixly_correct;
199199
whose names are inconsistent. */
200200

201201
#ifndef getenv
202-
extern char *getenv ();
202+
extern char *getenv (const char *name);
203203
#endif
204204

205205
static char *

0 commit comments

Comments
 (0)