448ee4f664f60d70d229af5462ef349240af8d7f — Ben Brown 1 year, 2 days ago bda92ab
Reset optind to 0

POSIX states that setting this to 0 is unspecified however setting it
to 1 is causing issues on certain versions of glibc.
M builtin/alias.c => builtin/alias.c +1 -1
@@ 17,7 17,7 @@ static void print_alias_iterator(const char *key, void *_value,
 }
 
 int builtin_alias(struct mrsh_state *state, int argc, char *argv[]) {
-	optind = 1;
+	optind = 0;
 	if (getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "alias: unknown option -- %c\n", optopt);
 		fprintf(stderr, alias_usage);

M builtin/cd.c => builtin/cd.c +1 -1
@@ 36,7 36,7 @@ static int isdir(char *path) {
 }
 
 int builtin_cd(struct mrsh_state *state, int argc, char *argv[]) {
-	optind = 1;
+	optind = 0;
 	int opt;
 	while ((opt = getopt(argc, argv, ":LP")) != -1) {
 		switch (opt) {

M builtin/getopts.c => builtin/getopts.c +1 -1
@@ 12,7 12,7 @@
 static const char getopts_usage[] = "usage: getopts optstring name [arg...]\n";
 
 int builtin_getopts(struct mrsh_state *state, int argc, char *argv[]) {
-	optind = 1;
+	optind = 0;
 	if (getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "getopts: unknown option -- %c\n", optopt);
 		fprintf(stderr, getopts_usage);

M builtin/pwd.c => builtin/pwd.c +1 -1
@@ 8,7 8,7 @@
 static const char pwd_usage[] = "usage: pwd [-L|-P]\n";
 
 int builtin_pwd(struct mrsh_state *state, int argc, char *argv[]) {
-	optind = 1;
+	optind = 0;
 	int opt;
 	while ((opt = getopt(argc, argv, ":LP")) != -1) {
 		switch (opt) {

M builtin/read.c => builtin/read.c +1 -1
@@ 14,7 14,7 @@ static const char read_usage[] = "usage: read [-r] var...\n";
 int builtin_read(struct mrsh_state *state, int argc, char *argv[]) {
 	bool raw = false;
 
-	optind = 1;
+	optind = 0;
 	int opt;
 	while ((opt = getopt(argc, argv, ":r")) != -1) {
 		switch (opt) {

M builtin/type.c => builtin/type.c +1 -1
@@ 9,7 9,7 @@
 static const char type_usage[] = "usage: type name...\n";
 
 int builtin_type(struct mrsh_state *state, int argc, char *argv[]) {
-	optind = 1;
+	optind = 0;
 	if (getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "type: unknown option -- %c\n", optopt);
 		fprintf(stderr, type_usage);

M builtin/unalias.c => builtin/unalias.c +1 -1
@@ 15,7 15,7 @@ static void delete_alias_iterator(const char *key, void *_value, void *user_data
 int builtin_unalias(struct mrsh_state *state, int argc, char *argv[]) {
 	bool all = false;
 
-	optind = 1;
+	optind = 0;
 	int opt;
 	while ((opt = getopt(argc, argv, ":a")) != -1) {
 		switch (opt) {

M builtin/unset.c => builtin/unset.c +1 -1
@@ 11,7 11,7 @@ static const char unset_usage[] = "usage: unset [-fv] name...\n";
 int builtin_unset(struct mrsh_state *state, int argc, char *argv[]) {
 	bool funcs = false;
 
-	optind = 1;
+	optind = 0;
 	int opt;
 	while ((opt = getopt(argc, argv, ":fv")) != -1) {
 		switch (opt) {