-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[Backport v4.3-branch] sys: getopt: Rename getopt to sys_getopt to avoid conflicts with Posix #100598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4.3-branch
Are you sure you want to change the base?
[Backport v4.3-branch] sys: getopt: Rename getopt to sys_getopt to avoid conflicts with Posix #100598
Conversation
Summary: As Zephyr getopt is not really compatible with Posix getopt, rename Zephyr getopt to sys_getopt. Background: Zephyr getopt module was introduced in zephyrproject-rtos#31356 to be used by the shell. Zephyr's getopt is not the standard one. It has multiple APIs which make it more suited for a system like Zephyr where different components may want to use it for different purposes. Including APIs to init it, get and set its internal state etc. Several Zephyr modules (shell, net, wifi, ztest) use this getopt with these special APIs. The getopt module is bundled in the POSIX compatibility API subsystem (CONFIG_POSIX_C_LIB_EXT). Problem description: As it is not the standard getopt(), no C library can possibly provide a Zephyr compatible version (even if such C library were to provide a standard getopt()). As it is bundled in Zephyr's POSIX API in CONFIG_POSIX_C_LIB_EXT), multiple components that depend on it are selecting CONFIG_POSIX_C_LIB_EXT. Zephyr core components should not depend on the POSIX API in this way. Changes done in this commit: Rename the getopt*() APIs to sys_getopt*() and move them into a module under lib/utils with its own Kconfig option to enable it. Zephyr's users are changed to use this new component. The POSIX subsystem can continue providing getopt() by calling the new sys_getopt() and in that way retain backwards compatibility for external users. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no> (cherry picked from commit 22f9ef0)
Allow user to use the new sys_getopt API via the old non-Posix compliant getopt API. This is a temporary solution and the shim will be deprecated and eventually removed at some point. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no> (cherry picked from commit d164f8b)
|
@mmahadevan108 why the backport, the getopt renaming is not really a bug fix? |
|
@mmahadevan108 The linked issue in the description should be a bug issue, not the backport failure one. |
|
This was identified as an issue by our team developing Matter applications. Without this fix, building Matter applications fails due to macro redefinition errors. |



Backport d164f8b~2..d164f8b from #98845