aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index f9a8de423..dc05f24b9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9872,7 +9872,8 @@ static int FAST_FUNC builtin_shift(char **argv)
9872#if ENABLE_HUSH_GETOPTS 9872#if ENABLE_HUSH_GETOPTS
9873static int FAST_FUNC builtin_getopts(char **argv) 9873static int FAST_FUNC builtin_getopts(char **argv)
9874{ 9874{
9875/* 9875/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html
9876
9876TODO: 9877TODO:
9877If an invalid option is seen, getopts places ? into VAR and, if 9878If an invalid option is seen, getopts places ? into VAR and, if
9878not silent, prints an error message and unsets OPTARG. If 9879not silent, prints an error message and unsets OPTARG. If
@@ -9886,6 +9887,8 @@ colon (:) is placed in VAR and OPTARG is set to the option
9886character found. 9887character found.
9887 9888
9888Test that VAR is a valid variable name? 9889Test that VAR is a valid variable name?
9890
9891"Whenever the shell is invoked, OPTIND shall be initialized to 1"
9889*/ 9892*/
9890 char cbuf[2]; 9893 char cbuf[2];
9891 const char *cp, *optstring, *var; 9894 const char *cp, *optstring, *var;
@@ -9920,14 +9923,20 @@ Test that VAR is a valid variable name?
9920 exitcode = EXIT_FAILURE; 9923 exitcode = EXIT_FAILURE;
9921 c = '?'; 9924 c = '?';
9922 } 9925 }
9923 if (optarg)
9924 set_local_var_from_halves("OPTARG", optarg);
9925 else
9926 unset_local_var("OPTARG");
9927 cbuf[0] = c; 9926 cbuf[0] = c;
9928 cbuf[1] = '\0'; 9927 cbuf[1] = '\0';
9929 set_local_var_from_halves(var, cbuf); 9928 set_local_var_from_halves(var, cbuf);
9930 set_local_var_from_halves("OPTIND", utoa(optind)); 9929 set_local_var_from_halves("OPTIND", utoa(optind));
9930
9931 /* Always set or unset, never left as-is, even on exit/error:
9932 * "If no option was found, or if the option that was found
9933 * does not have an option-argument, OPTARG shall be unset."
9934 */
9935 if (optarg)
9936 set_local_var_from_halves("OPTARG", optarg);
9937 else
9938 unset_local_var("OPTARG");
9939
9931 return exitcode; 9940 return exitcode;
9932} 9941}
9933#endif 9942#endif