Skip to content

Conversation

@keith-packard
Copy link
Contributor

Replace the Zephyr-specific re-entrant getopt family APIs with those from newlib. This allows use of the newlib and picolibc native implementations and provides a cleaner re-entrant mechanism, using a local variable to hold the getopt state instead of having a thread-local variabled tucked away in the shell context.

This will require changing all re-entrant users of getopt, switching from the Zephyr-style interfaces to the newlib-style.

Replace the Zephyr-specific re-entrant getopt family APIs with those from
newlib. This allows use of the newlib and picolibc native implementations
and provides a cleaner re-entrant mechanism, using a local variable to hold
the getopt state instead of having a thread-local variabled tucked away in
the shell context.

This will require changing all re-entrant users of getopt, switching from
the Zephyr-style interfaces to the newlib-style.

This also adopts the glibc/picolibc convention where setting optind = 0
causes the getopt functions to re-initialize all parsing state. This lets
us test the non-reentrant API without needing getopt_init().

Signed-off-by: Keith Packard <keithp@keithp.com>
The code scanner appears to believe that cmd_buff is of size zero and
complains about it. Protect an assignment to cmd_buff[0] with a #if check.

Signed-off-by: Keith Packard <keithp@keithp.com>
This file is covered by the 2-Clause BSD license as described here:

	https://spdx.org/licenses/BSD-2-Clause.html

Signed-off-by: Keith Packard <keithp@keithp.com>
@sonarqubecloud
Copy link

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

Labels

area: CRC area: Networking area: POSIX POSIX API Library area: Samples Samples area: Shell Shell subsystem area: Tests Issues related to a particular existing or missing test area: Testsuite Testsuite area: Wi-Fi Wi-Fi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants