X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetopt_.h;h=3c406e53dc47157ce978688c068575d20d48bda8;hb=7c3f8da8f075e3813ced160d5b53a28c6f7dfe78;hp=e6437ed3b18422563b60483f18c3d55c11fa924e;hpb=1c64ecc467eb219cc70be133d3b17cc6eeea1369;p=gnulib.git diff --git a/lib/getopt_.h b/lib/getopt_.h index e6437ed3b..3c406e53d 100644 --- a/lib/getopt_.h +++ b/lib/getopt_.h @@ -1,5 +1,5 @@ /* Declarations for getopt. - Copyright (C) 1989-1994,1996-1999,2001,2003,2004 + Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GETOPT_H @@ -25,16 +25,17 @@ /* Standalone applications should #define __GETOPT_PREFIX to an identifier that prefixes the external functions and variables - defined in this header. When this happens, include (the - standard header declaring getopt), so that it will not cause - confusion if it is included later. Then systematically rename + defined in this header. When this happens, include the + headers that might declare getopt so that they will not cause + confusion if included after this file. Then systematically rename identifiers so that they do not collide with the system functions and variables. Renaming avoids problems with some compilers and linkers. */ #if defined __GETOPT_PREFIX && !defined __need_getopt -# if HAVE_UNISTD_H -# include -# endif +# include +# include +# include +# undef __need_getopt # undef getopt # undef getopt_long # undef getopt_long_only @@ -42,13 +43,40 @@ # undef opterr # undef optind # undef optopt -# define getopt __GETOPT_PREFIX##getopt -# define getopt_long __GETOPT_PREFIX##getopt_long -# define getopt_long_only __GETOPT_PREFIX##getopt_long_only -# define optarg __GETOPT_PREFIX##optarg -# define opterr __GETOPT_PREFIX##opterr -# define optind __GETOPT_PREFIX##optind -# define optopt __GETOPT_PREFIX##optopt +# define __GETOPT_CONCAT(x, y) x ## y +# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) +# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) +# define getopt __GETOPT_ID (getopt) +# define getopt_long __GETOPT_ID (getopt_long) +# define getopt_long_only __GETOPT_ID (getopt_long_only) +# define optarg __GETOPT_ID (optarg) +# define opterr __GETOPT_ID (opterr) +# define optind __GETOPT_ID (optind) +# define optopt __GETOPT_ID (optopt) +#endif + +/* Standalone applications get correct prototypes for getopt_long and + getopt_long_only; they declare "char **argv". libc uses prototypes + with "char *const *argv" that are incorrect because getopt_long and + getopt_long_only can permute argv; this is required for backward + compatibility (e.g., for LSB 2.0.1). + + This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt', + but it caused redefinition warnings if both unistd.h and getopt.h were + included, since unistd.h includes getopt.h having previously defined + __need_getopt. + + The only place where __getopt_argv_const is used is in definitions + of getopt_long and getopt_long_only below, but these are visible + only if __need_getopt is not defined, so it is quite safe to rewrite + the conditional as follows: +*/ +#if !defined __need_getopt +# if defined __GETOPT_PREFIX +# define __getopt_argv_const /* empty */ +# else +# define __getopt_argv_const const +# endif #endif /* If __GNU_LIBRARY__ is not already defined, either we are being used @@ -117,7 +145,7 @@ extern int optopt; The field `has_arg' is: no_argument (or 0) if the option does not take an argument, required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. + optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but @@ -176,11 +204,11 @@ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) __THROW; #ifndef __need_getopt -extern int getopt_long (int ___argc, char *const *___argv, +extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) __THROW; -extern int getopt_long_only (int ___argc, char *const *___argv, +extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) __THROW;