Skip to content
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

posix: getopt: cannot use getopt() in a standard way #52749

Closed
Tracked by #51211
cfriedt opened this issue Dec 2, 2022 · 0 comments · Fixed by #52766
Closed
Tracked by #51211

posix: getopt: cannot use getopt() in a standard way #52749

cfriedt opened this issue Dec 2, 2022 · 0 comments · Fixed by #52766
Assignees
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@cfriedt
Copy link
Member

cfriedt commented Dec 2, 2022

Describe the bug
Getopt should be defined in <unistd.h> according to the POSIX specification. Of course, in Zephyr, that header is available in <zephyr/posix/unistd.h>.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html

Please also mention any information which could help others to understand
the problem you're facing
:

  • What target platform are you using? all (aside from native_posix types)
  • What have you tried to diagnose or workaround this issue? Many, many things.
  • Is this a regression? If yes, have you been able to "git bisect" it to a
    specific commit?
    no, it's always been broken
  • ...

To Reproduce
Steps to reproduce the behavior:

  1. Compile the example program below
  2. see failure
#include <zephyr/posix/unistd.h>

void foo(void)
{
  int argc = 42;
  char *const argv[] = {"So", "long", "and", "thanks", "for", "all", "the", "fish" };
  getopt(argc, argv, "");
}

Expected behavior

Impact
It's a showstopper for anyone expecting to be able to use standard POSIX code portably

Logs and console output
The warning below is promoted to error when run in twister

west build -p auto -b qemu_cortex_a53 -t run tests/posix/getopt
...
/Users/cfriedt/workspace/zephyrproject/zephyr/tests/posix/getopt/src/foo.c: In function 'foo':
/Users/cfriedt/workspace/zephyrproject/zephyr/tests/posix/getopt/src/foo.c:7:9: warning: implicit declaration of function 'getopt' [-Wimplicit-function-declaration]
    7 |         getopt(argc, argv, "");
      |         ^~~~~~
twister -i -p qemu_cortex_a53 -T tests/posix/getopt
...
/Users/cfriedt/workspace/zephyrproject/zephyr/tests/posix/getopt/src/foo.c: In function 'foo':
/Users/cfriedt/workspace/zephyrproject/zephyr/tests/posix/getopt/src/foo.c:7:9: error: implicit declaration of function 'getopt'; did you mean 'getsubopt'? [-Werror=implicit-function-declaration]
    7 |         getopt(argc, argv, "");
      |         ^~~~~~
      |         getsubopt

Environment (please complete the following information):

  • OS: (e.g. Linux, MacOS, Windows): any
  • Toolchain (e.g Zephyr SDK, ...): Zephyr SDK 0.15.2
  • Commit SHA or Version used: dc26a61

Additional context

@cfriedt cfriedt added the bug The issue is a bug, or the PR is fixing a bug label Dec 2, 2022
@cfriedt cfriedt self-assigned this Dec 2, 2022
@cfriedt cfriedt added area: POSIX POSIX API Library priority: medium Medium impact/importance bug labels Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant