Skip to contentSkip to conversation

package/which: fix getopt implicit prototype conflicting with system headers

PATCH In review Shubham Chakraborty 2 participants 4 messages Mar 9

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 package/which: fix getopt implicit prototype conflicting with system headers

Older C standards allowed empty parentheses in function declarations, but modern C (C23) treats extern int getopt() as equivalent to extern int getopt(void), which conflicts with the typed prototype provided by system headers (e.g. musl's unistd.h).

Fix by providing the full prototype in the non-GNU fallback branch, matching the standard getopt() signature.

---
Changes in v2:
- Correct commit message title and body
- Use git format-patch format

---
 package/which/0001-fix-getopt-prototype.patch | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 package/which/0001-fix-getopt-prototype.patch
package/which/0001-fix-getopt-prototype.patch new file +15 -0
new file mode 100644
index 0000000000..af9597242f
@@ -0,0 +1,15 @@
+diff --git a/getopt.h b/getopt.h
+index f080053..f080054 100644
+--- a/getopt.h
++++ b/getopt.h
+@@ -102,7 +102,7 @@
+    errors, only prototype getopt for the GNU C library.  */
+ extern int getopt(int argc, char *const *argv, const char *shortopts);
+ #else  /* not __GNU_LIBRARY__ */
+-extern int getopt();
++extern int getopt(int argc, char *const *argv, const char *shortopts);
+ #endif /* __GNU_LIBRARY__ */
+ extern int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind);
+ extern int getopt_long_only(int argc, char *const *argv, const char *shortopts, const struct option *longopts,
+-- 
+2.43.0
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH v2 2/2 DEVELOPERS: add Shubham Chakraborty as maintainer of package/which

---
Changes in v2:
- Fix indentation to use tabs instead of spaces
- Add trailing slash to package/which/

---
 DEVELOPERS | 3 +++
 1 file changed, 3 insertions(+)
DEVELOPERS +3 -0
index 835be1f6a3..51d9f8a4be 100644
@@ -3058,6 +3058,9 @@ F:	package/tunctl/
 F:	package/ubus/
 F:	package/wolfssl/
 
+N:	Shubham Chakraborty <[email protected]>
+F:	package/which/
+
 N:	Simon Dawson <[email protected]>
 F:	boot/at91bootstrap3/
 F:	package/cppzmq/
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Shubham Chakraborty

Hello,

Quoted 9 lines · Shubham Chakraborty

Older C standards allowed empty parentheses in function declarations, but modern C (C23) treats extern int getopt() as equivalent to extern int getopt(void), which conflicts with the typed prototype provided by system headers (e.g. musl's unistd.h).

Fix by providing the full prototype in the non-GNU fallback branch, matching the standard getopt() signature.

Which gcc version broke this?

package/which/0001-fix-getopt-prototype.patch

Quoted 5 lines
package/which/0001-fix-getopt-prototype.patch new file +0 -0
new file mode 100644
index 0000000000..af9597242f

You didn't take into account my comments on the patch formatting.

Thanks!

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

Hi Thomas,

Thank you for the feedback. I have sent v3 of the patch, which addresses both issues:

- Identified GCC 15 as the version that introduced this issue.
- Fixed the patch file format to include a proper description and Signed-off-by line.

Best regards,

Shubham

Quoted 24 lines · Thomas Petazzoni

Hello,

Quoted 9 lines · Shubham Chakraborty

Older C standards allowed empty parentheses in function declarations, but modern C (C23) treats extern int getopt() as equivalent to extern int getopt(void), which conflicts with the typed prototype provided by system headers (e.g. musl's unistd.h).

Fix by providing the full prototype in the non-GNU fallback branch, matching the standard getopt() signature.

Which gcc version broke this?

Review

Quoted 1 line
(quoted diff) +0 -0

b/package/which/0001-fix-getopt-prototype.patch

package/which/0001-fix-getopt-prototype.patch

Quoted 4 lines

new file mode 100644
index 0000000000..af9597242f

package/which/0001-fix-getopt-prototype.patch new file +0 -0

You didn't take into account my comments on the patch formatting.

Quoted 8 lines

Thanks!

Thomas
--
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training
https://bootlin.com

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot