Skip to content

Conversation

@mmahadevan108
Copy link
Contributor

@mmahadevan108 mmahadevan108 commented Dec 5, 2025

Backport d164f8b~2..d164f8b from #98845

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)
@jukkar
Copy link
Member

jukkar commented Dec 5, 2025

@mmahadevan108 why the backport, the getopt renaming is not really a bug fix?

@JarmouniA
Copy link
Contributor

@mmahadevan108 The linked issue in the description should be a bug issue, not the backport failure one.

@JarmouniA JarmouniA linked an issue Dec 5, 2025 that may be closed by this pull request
@JarmouniA JarmouniA closed this Dec 5, 2025
@github-project-automation github-project-automation bot moved this from To do to Done in Backports Dec 5, 2025
@JarmouniA JarmouniA reopened this Dec 5, 2025
@github-project-automation github-project-automation bot moved this from Done to Needs more info in Backports Dec 5, 2025
@zephyrbot zephyrbot requested a review from thenguyenyf December 5, 2025 21:42
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2025

@mmahadevan108
Copy link
Contributor Author

@mmahadevan108 why the backport, the getopt renaming is not really a bug fix?

This was identified as an issue by our team developing Matter applications. Without this fix, building Matter applications fails due to macro redefinition errors.

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

Labels

area: Networking Backport Backport PR and backport failure issues

Projects

Status: Needs more info

Development

Successfully merging this pull request may close these issues.

[Backport v4.3-branch] Failed to backport #98845

5 participants