1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-21 14:53:53 +03:00

getopt: refactor long-option handling

There were two copies of the bulk of the code to handle long options.
Now there is only one.  (Yes, this is in aid of merging from gnulib.)

The change to bug-getopt4.c clarifies the error messages when the test
fails.

	* posix/getopt.c (process_long_option): New function split out
	from _getopt_internal_r.
	(_getopt_internal_r): Replace both copies of the long-option
	processing code with calls to process_long_option.
	* posix/bug-getopt4.c (one_test): Print argv[0] in error messages.
	(do_test): Differentiate argv[0] in the two subtests.
This commit is contained in:
Zack Weinberg
2017-04-01 16:19:50 -04:00
parent c1af8775f2
commit dfbea09f96
3 changed files with 223 additions and 309 deletions

View File

@@ -27,20 +27,20 @@ one_test (const char *fmt, int argc, char *argv[], int n, int expected[n])
int c = getopt_long (argc, argv, fmt, opts, NULL);
if (c != expected[i])
{
printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
fmt, i, expected[i], c);
printf ("%s: format '%s' test %d failed: expected '%c', got '%c'\n",
argv[0], fmt, i, expected[i], c);
res = 1;
}
else if (optarg != NULL)
{
printf ("format '%s' test %d failed: optarg is \"%s\", not NULL\n",
fmt, i, optarg);
printf ("%s: format '%s' test %d failed: optarg is \"%s\", not NULL\n",
argv[0], fmt, i, optarg);
res = 1;
}
if (ftell (stderr) != 0)
{
printf ("format '%s' test %d failed: printed to stderr\n",
fmt, i);
printf ("%s: format '%s' test %d failed: printed to stderr\n",
argv[0], fmt, i);
res = 1;
}
}
@@ -68,11 +68,11 @@ do_test (void)
remove (fname);
int ret = one_test ("W;", 2,
(char *[2]) { (char *) "bug-getopt4", (char *) "--a" },
(char *[2]) { (char *) "bug-getopt4a", (char *) "--a" },
1, (int [1]) { 'a' });
ret |= one_test ("W;", 3,
(char *[3]) { (char *) "bug-getopt4", (char *) "-W",
(char *[3]) { (char *) "bug-getopt4b", (char *) "-W",
(char *) "a" },
1, (int [1]) { 'a' });