X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetopt.c;h=ac0d6f3f78d10a96c5e529f1da58bb21d48b2c80;hb=880bff095c4a832c6ca0e899485da94a2fa34758;hp=812258ae3d73a4bbafbc0c8a7e2e00ab29c84ff9;hpb=b6ef595f1f04e8226ed6cf6071f3595c05d02603;p=gnulib.git diff --git a/lib/getopt.c b/lib/getopt.c index 812258ae3..ac0d6f3f7 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -27,14 +27,7 @@ #endif #ifdef HAVE_CONFIG_H -#if defined (emacs) || defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ #include -#else -#include "config.h" -#endif #endif #ifndef __STDC__ @@ -60,7 +53,7 @@ /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ +#if defined (__GNU_LIBRARY__) || defined (__sgi) /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ #include @@ -158,8 +151,11 @@ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; -#ifdef __GNU_LIBRARY__ +#if defined (__GNU_LIBRARY__) || defined (__sgi) /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work @@ -190,11 +186,12 @@ my_index (str, chr) /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ #ifndef __STDC__ -/* Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - Enable Emacs to compile on it. */ -#include -extern size_t strlen (const char *); +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); #endif /* not __STDC__ */ #endif /* __GNUC__ */ @@ -288,6 +285,8 @@ _getopt_initialize (optstring) nextchar = NULL; + posixly_correct = getenv ("POSIXLY_CORRECT"); + /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') @@ -300,7 +299,7 @@ _getopt_initialize (optstring) ordering = REQUIRE_ORDER; ++optstring; } - else if (getenv ("POSIXLY_CORRECT") != NULL) + else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; @@ -479,6 +478,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; +#ifdef lint /* Suppress `used before initialized' warning. */ + indfound = 0; +#endif + /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) @@ -604,8 +607,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { if (opterr) { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); } optopt = c; return '?';