[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] getopt: allow compilation with C++
From: |
Eric Blake |
Subject: |
[PATCH 1/3] getopt: allow compilation with C++ |
Date: |
Fri, 16 Apr 2010 15:53:41 -0600 |
A C++ compiler complains that REQUIRE_ORDER is unknown if it is
buried inside the struct.
* lib/getopt_int.h (__ordering): Hoist enum declaration outside
struct.
* lib/getopt.c (_getopt_internal_r): Use correct type.
Reported by Dagobert Michelson, via Joel E. Denny.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++
lib/getopt.c | 2 +-
lib/getopt_int.h | 69 ++++++++++++++++++++++++++++-------------------------
3 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 09bece9..a86e305 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-04-16 Eric Blake <address@hidden>
+
+ getopt: allow compilation with C++
+ * lib/getopt_int.h (__ordering): Hoist enum declaration outside
+ struct.
+ * lib/getopt.c (_getopt_internal_r): Use correct type.
+ Reported by Dagobert Michelson, via Joel E. Denny.
+
2010-04-16 Bruno Haible <address@hidden>
Override netdb.h always.
diff --git a/lib/getopt.c b/lib/getopt.c
index 738d998..3791f12 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -738,7 +738,7 @@ _getopt_internal_r (int argc, char **argv, const char
*optstring,
{
char c = *d->__nextchar++;
- char *temp = strchr (optstring, c);
+ const char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*d->__nextchar == '\0')
diff --git a/lib/getopt_int.h b/lib/getopt_int.h
index 169def5..980b750 100644
--- a/lib/getopt_int.h
+++ b/lib/getopt_int.h
@@ -30,6 +30,40 @@ extern int _getopt_internal (int ___argc, char **___argv,
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+ If the caller did not specify anything,
+ the default is REQUIRE_ORDER if the environment variable
+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options;
+ stop option processing when the first non-option is seen.
+ This is what Unix does.
+ This mode of operation is selected by either setting the environment
+ variable POSIXLY_CORRECT, or using `+' as the first character
+ of the list of option characters, or by calling getopt.
+
+ PERMUTE is the default. We permute the contents of ARGV as we
+ scan, so that eventually all the non-options are at the end.
+ This allows options to be given in any order, even with programs
+ that were not written to expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were
+ written to expect options and other ARGV-elements in any order
+ and that care about the ordering of the two. We describe each
+ non-option ARGV-element as if it were the argument of an option
+ with character code 1. Using `-' as the first character of the
+ list of option characters selects this mode of operation.
+
+ The special argument `--' forces an end of option-scanning regardless
+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
+
+enum __ord
+ {
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+ };
+
/* Data type for reentrant functions. */
struct _getopt_data
{
@@ -54,39 +88,8 @@ struct _getopt_data
by advancing to the next ARGV-element. */
char *__nextchar;
- /* Describe how to deal with options that follow non-option ARGV-elements.
-
- If the caller did not specify anything,
- the default is REQUIRE_ORDER if the environment variable
- POSIXLY_CORRECT is defined, PERMUTE otherwise.
-
- REQUIRE_ORDER means don't recognize them as options;
- stop option processing when the first non-option is seen.
- This is what Unix does.
- This mode of operation is selected by either setting the environment
- variable POSIXLY_CORRECT, or using `+' as the first character
- of the list of option characters, or by calling getopt.
-
- PERMUTE is the default. We permute the contents of ARGV as we
- scan, so that eventually all the non-options are at the end.
- This allows options to be given in any order, even with programs
- that were not written to expect this.
-
- RETURN_IN_ORDER is an option available to programs that were
- written to expect options and other ARGV-elements in any order
- and that care about the ordering of the two. We describe each
- non-option ARGV-element as if it were the argument of an option
- with character code 1. Using `-' as the first character of the
- list of option characters selects this mode of operation.
-
- The special argument `--' forces an end of option-scanning regardless
- of the value of `ordering'. In the case of RETURN_IN_ORDER, only
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */
-
- enum
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- } __ordering;
+ /* See __ord above. */
+ enum __ord __ordering;
/* If the POSIXLY_CORRECT environment variable is set
or getopt was called. */
--
1.6.6.1
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Joel E. Denny, 2010/04/15
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Eric Blake, 2010/04/15
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Bruno Haible, 2010/04/15
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Paolo Bonzini, 2010/04/16
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Bruno Haible, 2010/04/16
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Eric Blake, 2010/04/16
- [PATCH 0/3] several C++ patches, Eric Blake, 2010/04/16
- [PATCH 2/3] stdint: allow test to pass with C++, Eric Blake, 2010/04/16
- [PATCH 1/3] getopt: allow compilation with C++,
Eric Blake <=
- [PATCH 3/3] setenv: allow compilation with C++, Eric Blake, 2010/04/16
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Joel E. Denny, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Dagobert Michelsen, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Eric Blake, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Joel E. Denny, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Eric Blake, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Joel E. Denny, 2010/04/20
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Paolo Bonzini, 2010/04/21
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Joel E. Denny, 2010/04/22
- Re: [GNU Bison 2.4.2] testsuite: Failing tests of bison 2.4.2 on Solaris 8+9 w/Sun Studio 11+12, Dagobert Michelsen, 2010/04/25