[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] getopt: merge bug fixes from glibc
From: |
Eric Blake |
Subject: |
[PATCH 1/2] getopt: merge bug fixes from glibc |
Date: |
Sat, 10 Apr 2010 13:29:35 -0600 |
* lib/getopt.c (_getopt_internal_r): Use correct message for 'W;'
diagnostics. Honor '+:' correctly. Reject ';'.
Signed-off-by: Eric Blake <address@hidden>
---
I'm still testing this on a few more machines, so it will probably
be Monday or Tuesday before I push.
ChangeLog | 6 ++++++
lib/getopt.c | 37 ++++++++++++++++++++++---------------
2 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d347b26..fea598f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-04-10 Eric Blake <address@hidden>
+
+ getopt: merge bug fixes from glibc
+ * lib/getopt.c (_getopt_internal_r): Use correct message for 'W;'
+ diagnostics. Honor '+:' correctly. Reject ';'.
+
2010-04-10 Bruno Haible <address@hidden>
vasnprintf test: Reduce code duplication.
diff --git a/lib/getopt.c b/lib/getopt.c
index aaabc8d..738d998 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -348,8 +348,6 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
- if (optstring[0] == ':')
- print_errors = 0;
if (argc < 1)
return -1;
@@ -364,6 +362,10 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
posixly_correct);
d->__initialized = 1;
}
+ else if (optstring[0] == '-' || optstring[0] == '+')
+ optstring++;
+ if (optstring[0] == ':')
+ print_errors = 0;
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
@@ -633,8 +635,8 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
char *buf;
if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]) >= 0)
+%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@@ -651,8 +653,8 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
}
#else
fprintf (stderr,
- _("%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]);
+ _("%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@@ -742,7 +744,7 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
if (*d->__nextchar == '\0')
++d->optind;
- if (temp == NULL || c == ':')
+ if (temp == NULL || c == ':' || c == ';')
{
if (print_errors)
{
@@ -864,7 +866,10 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
pfound = p;
indfound = option_index;
}
- else
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
@@ -876,7 +881,7 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
char *buf;
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], argv[d->optind]) >= 0)
+ argv[0], d->optarg) >= 0)
{
_IO_flockfile (stderr);
@@ -892,7 +897,7 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
}
#else
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], argv[d->optind]);
+ argv[0], d->optarg);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@@ -955,8 +960,8 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
char *buf;
if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]) >= 0)
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@@ -972,15 +977,17 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
free (buf);
}
#else
- fprintf (stderr,
- _("%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]);
+ fprintf (stderr, _("\
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
+ else
+ d->optarg = NULL;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;
--
1.6.6.1
- [PATCH 1/2] getopt: merge bug fixes from glibc,
Eric Blake <=
- [PATCH 2/2] getopt: match recent glibc fixes and posix ruling, Eric Blake, 2010/04/10
- [PATCH 1/5] getopt-posix: avoid spurious failure on FreeBSD, Eric Blake, 2010/04/13
- [PATCH 2/5] getopt-posix: avoid spurious failure on Solaris, Eric Blake, 2010/04/13
- [PATCH 0/5] sync getopt to glibc, Eric Blake, 2010/04/13
- [PATCH 3/5] getopt-posix: detect MacOS bug, Eric Blake, 2010/04/13
- [PATCH 5/5] getopt-gnu: match recent glibc fixes and posix ruling, Eric Blake, 2010/04/13
- [PATCH 4/5] getopt: merge bug fixes from glibc, Eric Blake, 2010/04/13