summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--src/include/getopt.h17
-rw-r--r--src/libs/libgroff/getopt.c17
3 files changed, 32 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 982ecbf5..a8d52ce6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2001-04-21 Werner LEMBERG <wl@gnu.org
+2001-04-22 Werner LEMBERG <wl@gnu.org>
+
+ * src/libs/libgroff/getopt.c, src/include/getopt.h: Updating to
+ latest versions from glibc CVS archive.
+
+2001-04-21 Werner LEMBERG <wl@gnu.org>
* configure.in: Move check for mkstemp() to...
* aclocal.m4 (GROFF_MKSTEMP): This new function.
diff --git a/src/include/getopt.h b/src/include/getopt.h
index b0147e9d..c2f01804 100644
--- a/src/include/getopt.h
+++ b/src/include/getopt.h
@@ -1,5 +1,5 @@
/* Declarations for getopt.
- Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
+ Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -23,6 +23,17 @@
# define _GETOPT_H 1
#endif
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -82,7 +93,7 @@ extern int optopt;
struct option
{
-# if defined __STDC__ && __STDC__
+# if (defined __STDC__ && __STDC__) || defined __cplusplus
const char *name;
# else
char *name;
@@ -126,7 +137,7 @@ struct option
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
-#if defined __STDC__ && __STDC__
+#if (defined __STDC__ && __STDC__) || defined __cplusplus
# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
diff --git a/src/libs/libgroff/getopt.c b/src/libs/libgroff/getopt.c
index 4744e433..0ecad382 100644
--- a/src/libs/libgroff/getopt.c
+++ b/src/libs/libgroff/getopt.c
@@ -77,11 +77,12 @@
#endif
#ifndef _
-/* This is for other GNU distributions with internationalized messages.
- When compiling libc, the _ macro is predefined. */
-# ifdef HAVE_LIBINTL_H
+/* This is for other GNU distributions with internationalized messages. */
+# if defined HAVE_LIBINTL_H || defined _LIBC
# include <libintl.h>
-# define _(msgid) gettext (msgid)
+# ifndef _
+# define _(msgid) gettext (msgid)
+# endif
# else
# define _(msgid) (msgid)
# endif
@@ -521,6 +522,9 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (optstring[0] == ':')
print_errors = 0;
+ if (argc < 1)
+ return -1;
+
optarg = NULL;
if (optind == 0 || !__getopt_initialized)
@@ -670,7 +674,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
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;
}