Commit 2e86ba7e authored by unknown's avatar unknown

Fixed a bug in my_getopt.


mysys/my_getopt.c:
  Fixed two bugs in my_getopt:
  - Didn't exit with error if a short option was not recognized. Fixed.
  - If unrecognized short option was not the first one in the list,
    printed "unknown option" error for wrong option. Fixed.
parent b379016d
...@@ -324,8 +324,9 @@ int handle_options(int *argc, char ***argv, ...@@ -324,8 +324,9 @@ int handle_options(int *argc, char ***argv,
} }
else /* must be short option */ else /* must be short option */
{ {
for (optend= cur_arg; *optend; optend++, opt_found= 0) for (optend= cur_arg; *optend; optend++)
{ {
opt_found= 0;
for (optp= longopts; optp->id; optp++) for (optp= longopts; optp->id; optp++)
{ {
if (optp->id == (int) (uchar) *optend) if (optp->id == (int) (uchar) *optend)
...@@ -379,7 +380,7 @@ int handle_options(int *argc, char ***argv, ...@@ -379,7 +380,7 @@ int handle_options(int *argc, char ***argv,
{ {
if (my_getopt_print_errors) if (my_getopt_print_errors)
fprintf(stderr, fprintf(stderr,
"%s: unknown option '-%c'\n", progname, *cur_arg); "%s: unknown option '-%c'\n", progname, *optend);
return EXIT_UNKNOWN_OPTION; return EXIT_UNKNOWN_OPTION;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment