diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2002-08-07 09:10:36 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2002-08-07 09:10:36 +0000 |
commit | f7a75bc37a8d5a027f3c2a4519a4db42b5fab7d9 (patch) | |
tree | 6940ba29f50bcfb3a5965a33c638bdbd1ce28c03 /lib | |
parent | eb2b167bece3a06cdfea7d956796a89931e5813c (diff) | |
download | diffutils-f7a75bc37a8d5a027f3c2a4519a4db42b5fab7d9.tar.gz |
Snapshot before syncing with gnulib again.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getopt.c | 65 | ||||
-rw-r--r-- | lib/getopt.h | 24 | ||||
-rw-r--r-- | lib/getopt1.c | 11 |
3 files changed, 35 insertions, 65 deletions
diff --git a/lib/getopt.c b/lib/getopt.c index ed32692..dc07cb3 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -2,7 +2,7 @@ NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! - Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 + Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -30,14 +30,6 @@ # include <config.h> #endif -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -# ifndef const -# define const -# endif -#endif - #include <stdio.h> /* Comment out all this code if we are using the GNU C Library, and are not @@ -59,14 +51,12 @@ #ifndef ELIDE_CODE -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ +#if HAVE_STDLIB_H || defined __GNU_LIBRARY__ # include <stdlib.h> +#endif +#if HAVE_UNISTD_H || defined __GNU_LIBRARY__ # include <unistd.h> -#endif /* GNU C library. */ +#endif #ifdef VMS # include <unixlib.h> @@ -189,30 +179,18 @@ static enum /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; -#ifdef __GNU_LIBRARY__ -/* 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 - in GCC. */ +#if HAVE_STRING_H || defined __GNU_LIBRARY__ # include <string.h> -# define my_index strchr #else - -# if HAVE_STRING_H -# include <string.h> -# else +# if HAVE_STRINGS_H # include <strings.h> # endif - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -#ifndef getenv -extern char *getenv (); #endif +#if !HAVE_STRCHR && !defined strchr && !defined __GNU_LIBRARY__ +# define strchr my_strchr static char * -my_index (str, chr) +strchr (str, chr) const char *str; int chr; { @@ -224,20 +202,11 @@ my_index (str, chr) } return 0; } +#endif -/* 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. */ -# if (!defined __STDC__ || !__STDC__) && !defined strlen -/* 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__ */ - -#endif /* not __GNU_LIBRARY__ */ +#if !HAVE_DECL_GETENV && !defined getenv && !defined __GNU_LIBRARY__ +char *getenv (); +#endif /* Handle permutation of arguments. */ @@ -646,7 +615,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (longopts != NULL && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + || (long_only && (argv[optind][2] || !strchr (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; @@ -761,7 +730,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) + || strchr (optstring, *nextchar) == NULL) { if (print_errors) { @@ -785,7 +754,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { char c = *nextchar++; - char *temp = my_index (optstring, c); + char *temp = strchr (optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') diff --git a/lib/getopt.h b/lib/getopt.h index 18e1026..cc70194 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -1,5 +1,8 @@ /* Declarations for getopt. - Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. + + Copyright (C) 1989-1994, 1996-1999, 2001, 2002 Free Software Foundation, + Inc. + This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -26,11 +29,16 @@ 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 + not defined, include <stdlib.h>, which will pull in <features.h> for us + if it's from glibc (and will declare getopt). Fall back on <ctype.h> if + <stdlib.h> might not exist. (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> +# if HAVE_STDLIB_H || STDC_HEADERS +# include <stdlib.h> +# else +# include <ctype.h> +# endif #endif #ifdef __cplusplus @@ -137,14 +145,16 @@ struct option `getopt'. */ #if (defined __STDC__ && __STDC__) || defined __cplusplus -# ifdef __GNU_LIBRARY__ +# if defined HAVE_DECL_GETOPT && !HAVE_DECL_GETOPT +# ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ extern int getopt (int __argc, char *const *__argv, const char *__shortopts); -# else /* not __GNU_LIBRARY__ */ +# else /* not __GNU_LIBRARY__ */ extern int getopt (); -# endif /* __GNU_LIBRARY__ */ +# endif /* __GNU_LIBRARY__ */ +# endif /* defined HAVE_DECL_GETOPT && !HAVE_DECL_GETOPT */ # ifndef __need_getopt extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, diff --git a/lib/getopt1.c b/lib/getopt1.c index 62c55cf..eb4188a 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -22,15 +22,6 @@ #endif #include "getopt.h" - -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - #include <stdio.h> /* Comment out all this code if we are using the GNU C Library, and are not |