shell: devmem: address cmd_dump
multiple call problem
Call `getopt_init()` to reset `state->optind` instead of directly setting `optind = 1`. The `getopt()` function uses `getopt_state` from `getopt_state_get` for state handling, so `getopt_init()` should be called to correctly run the command again. Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit is contained in:
parent
93ee60fe87
commit
557ad8e45c
2 changed files with 8 additions and 1 deletions
|
@ -48,7 +48,7 @@ struct option {
|
|||
int val;
|
||||
};
|
||||
|
||||
/* Function intializes getopt_state structure for current thread */
|
||||
/* Function initializes getopt_state structure for current thread */
|
||||
void getopt_init(void);
|
||||
|
||||
/* Function returns getopt_state structure for the current thread. */
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#include <zephyr/shell/shell.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#ifndef CONFIG_NATIVE_LIBC
|
||||
extern void getopt_init(void);
|
||||
#endif
|
||||
|
||||
static inline bool is_ascii(uint8_t data)
|
||||
{
|
||||
return (data >= 0x30 && data <= 0x39) || (data >= 0x61 && data <= 0x66) ||
|
||||
|
@ -101,6 +105,9 @@ static int cmd_dump(const struct shell *sh, size_t argc, char **argv)
|
|||
mem_addr_t addr = -1;
|
||||
|
||||
optind = 1;
|
||||
#ifndef CONFIG_NATIVE_LIBC
|
||||
getopt_init();
|
||||
#endif
|
||||
while ((rv = getopt(argc, argv, "a:s:w:")) != -1) {
|
||||
switch (rv) {
|
||||
case 'a':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue