diff options
author | (GalaxyMaster) <galaxy4public@users.noreply.github.com> | 2023-01-31 18:24:55 +1100 |
---|---|---|
committer | Michal Domonkos <mdomonko@redhat.com> | 2023-03-13 15:32:25 +0100 |
commit | ee38497d72012828ce3ba0ee4a99dc41c6e4953f (patch) | |
tree | 2ef9572ea6a40b100dce11a3f1346cff81ffa919 | |
parent | 540e178782c884f2307324c73e0259fe4226dee3 (diff) | |
download | rpm-ee38497d72012828ce3ba0ee4a99dc41c6e4953f.tar.gz |
support for POSIX getopt() behaviour
[POSIX defines optarg only for options with arguments](https://pubs.opengroup.org/onlinepubs/000095399/functions/getopt.html) and callback() is expecting optarg to be NULL for options without arguments, however, at least on musl optarg will carry a pointer to the argument of the previous option with argument. This commit makes the behaviour deterministic and expected.
(cherry picked from commit 1f47b1cc0eddbb1921d81249a4bd604089c71495)
-rw-r--r-- | rpmio/rgetopt.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/rpmio/rgetopt.c b/rpmio/rgetopt.c index f789fa8fe..b14366a8a 100644 --- a/rpmio/rgetopt.c +++ b/rpmio/rgetopt.c @@ -28,6 +28,7 @@ int rgetopt(int argc, char * const argv[], const char *opts, optind = 0; #else optind = 1; + optarg = NULL; #endif while ((c = getopt(argc, argv, opts)) != -1) { @@ -39,6 +40,7 @@ int rgetopt(int argc, char * const argv[], const char *opts, rc = -1; break; } + optarg = NULL; } return (rc < 0) ? -optopt : optind; } |