about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/getopt.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/posix/getopt.c b/posix/getopt.c
index 24da4d3aa9..fdc19c5a7f 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -569,6 +569,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 		     argv[0], argv[optind]);
 	  nextchar += strlen (nextchar);
 	  optind++;
+	  optopt = 0;
 	  return '?';
 	}
 
@@ -597,6 +598,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 		     argv[0], argv[optind - 1][0], pfound->name);
 
 		  nextchar += strlen (nextchar);
+
+		  optopt = pfound->val;
 		  return '?';
 		}
 	    }
@@ -611,6 +614,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 			   _("%s: option `%s' requires an argument\n"),
 			   argv[0], argv[optind - 1]);
 		  nextchar += strlen (nextchar);
+		  optopt = pfound->val;
 		  return optstring[0] == ':' ? ':' : '?';
 		}
 	    }
@@ -645,6 +649,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 	    }
 	  nextchar = (char *) "";
 	  optind++;
+	  optopt = 0;
 	  return '?';
 	}
     }