* libc/getopt.c (parse_long_options): Use fix from NetBSD's getopt
to avoid false ambiguities.
This commit is contained in:
		| @@ -1,3 +1,8 @@ | |||||||
|  | 2009-01-13  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* libc/getopt.c (parse_long_options): Use fix from NetBSD's getopt | ||||||
|  | 	to avoid false ambiguities. | ||||||
|  |  | ||||||
| 2009-01-12  Corinna Vinschen  <corinna@vinschen.de> | 2009-01-12  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* syscalls.cc (enum bin_status): New type. | 	* syscalls.cc (enum bin_status): New type. | ||||||
|   | |||||||
| @@ -170,10 +170,16 @@ parse_long_options(char * const *nargv, const char *options, | |||||||
| { | { | ||||||
| 	char *current_argv, *has_equal; | 	char *current_argv, *has_equal; | ||||||
| 	size_t current_argv_len; | 	size_t current_argv_len; | ||||||
| 	int i, match; | 	int i, ambiguous, match; | ||||||
|  |  | ||||||
|  | #define IDENTICAL_INTERPRETATION(_x, _y)                                \ | ||||||
|  | 	(long_options[(_x)].has_arg == long_options[(_y)].has_arg &&    \ | ||||||
|  | 	 long_options[(_x)].flag == long_options[(_y)].flag &&          \ | ||||||
|  | 	 long_options[(_x)].val == long_options[(_y)].val) | ||||||
|  |  | ||||||
| 	current_argv = place; | 	current_argv = place; | ||||||
| 	match = -1; | 	match = -1; | ||||||
|  | 	ambiguous = 0; | ||||||
|  |  | ||||||
| 	optind++; | 	optind++; | ||||||
|  |  | ||||||
| @@ -193,6 +199,7 @@ parse_long_options(char * const *nargv, const char *options, | |||||||
| 		if (strlen(long_options[i].name) == current_argv_len) { | 		if (strlen(long_options[i].name) == current_argv_len) { | ||||||
| 			/* exact match */ | 			/* exact match */ | ||||||
| 			match = i; | 			match = i; | ||||||
|  | 			ambiguous = 0; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		/* | 		/* | ||||||
| @@ -204,14 +211,16 @@ parse_long_options(char * const *nargv, const char *options, | |||||||
|  |  | ||||||
| 		if (match == -1)	/* partial match */ | 		if (match == -1)	/* partial match */ | ||||||
| 			match = i; | 			match = i; | ||||||
| 		else { | 		else if (!IDENTICAL_INTERPRETATION(i, match)) | ||||||
| 			/* ambiguous abbreviation */ | 			ambiguous = 1; | ||||||
| 			if (PRINT_ERROR) | 	} | ||||||
| 				warnx(ambig, (int)current_argv_len, | 	if (ambiguous) { | ||||||
| 				     current_argv); | 		/* ambiguous abbreviation */ | ||||||
| 			optopt = 0; | 		if (PRINT_ERROR) | ||||||
| 			return (BADCH); | 			warnx(ambig, (int)current_argv_len, | ||||||
| 		} | 			     current_argv); | ||||||
|  | 		optopt = 0; | ||||||
|  | 		return (BADCH); | ||||||
| 	} | 	} | ||||||
| 	if (match != -1) {		/* option found */ | 	if (match != -1) {		/* option found */ | ||||||
| 		if (long_options[match].has_arg == no_argument | 		if (long_options[match].has_arg == no_argument | ||||||
| @@ -276,6 +285,7 @@ parse_long_options(char * const *nargv, const char *options, | |||||||
| 		return (0); | 		return (0); | ||||||
| 	} else | 	} else | ||||||
| 		return (long_options[match].val); | 		return (long_options[match].val); | ||||||
|  | #undef IDENTICAL_INTERPRETATION | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user