projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
__assert_fail(): remove _Noreturn, to get proper stacktraces
[musl]
/
src
/
misc
/
getopt.c
diff --git
a/src/misc/getopt.c
b/src/misc/getopt.c
index
abf0e84
..
35880a0
100644
(file)
--- a/
src/misc/getopt.c
+++ b/
src/misc/getopt.c
@@
-3,10
+3,13
@@
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
+#include "libc.h"
char *optarg;
char *optarg;
-int optind=1, opterr=1, optopt;
-static int optpos;
+int optind=1, opterr=1, optopt, __optpos, __optreset=0;
+
+#define optpos __optpos
+weak_alias(__optreset, optreset);
int getopt(int argc, char * const argv[], const char *optstring)
{
int getopt(int argc, char * const argv[], const char *optstring)
{
@@
-15,6
+18,12
@@
int getopt(int argc, char * const argv[], const char *optstring)
int k, l;
char *optchar;
int k, l;
char *optchar;
+ if (!optind || __optreset) {
+ __optreset = 0;
+ __optpos = 0;
+ optind = 1;
+ }
+
if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
return -1;
if (argv[optind][1] == '-' && !argv[optind][2])
if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
return -1;
if (argv[optind][1] == '-' && !argv[optind][2])