]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Merge from gnulib.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Nov 2004 01:59:29 +0000 (01:59 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Nov 2004 01:59:29 +0000 (01:59 +0000)
lib/ChangeLog
lib/getopt.c
lib/getopt1.c
lib/getopt_.h

index 09128a69b6f05bd340ab3c91d013b82c5e2838ff..f447f86cad36fd4c7fe967d9ced837bf02572390 100644 (file)
@@ -1,5 +1,14 @@
 2004-11-16  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Further getopt changes to make it more likely that glibc will
+       buy the changes back.
+       * getopt.c (POSIXLY_CORRECT): New constant.
+       (getopt): Use it, so to preserve glibc semantic
+       * getopt1.c (getopt_long, getopt_long_only): Arg is char * const *
+       when compiling for libc.
+       * getopt_.h (__getopt_argv_const): Bring it back.
+       (getopt_long, getopt_long_only): Use it.
+
        * getopt.c (_getopt_initialize, _getopt_internal_r, _getopt_internal):
        New arg POSIXLY_CORRECT.  All callers changed.
        (getopt): Argv is now char * const *, as per standard.
index 744f1156311593ada1deb34bcd1705ca2d787558..ef790b79e07af604046665d0187b1af4691ddb2f 100644 (file)
@@ -1154,10 +1154,19 @@ _getopt_internal (int argc, char **argv, const char *optstring,
   return result;
 }
 
+/* glibc gets a LSB-compliant getopt.
+   Standalone applications get a POSIX-compliant getopt.  */
+#if _LIBC
+enum { POSIXLY_CORRECT = 0 };
+#else
+enum { POSIXLY_CORRECT = 1 };
+#endif
+
 int
 getopt (int argc, char *const *argv, const char *optstring)
 {
-  return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0, 1);
+  return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0,
+                          POSIXLY_CORRECT);
 }
 
 \f
index 2ceff8ec8426a11911da42290ff19b068ffc8501..a7472371fa20a5071ea718a55ac7444b8b0efe50 100644 (file)
 #endif
 
 int
-getopt_long (int argc, char **argv, const char *options,
+getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
             const struct option *long_options, int *opt_index)
 {
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 0, 0);
+  return _getopt_internal (argc, (char **) argv, options, long_options,
+                          opt_index, 0, 0);
 }
 
 int
@@ -62,10 +63,12 @@ _getopt_long_r (int argc, char **argv, const char *options,
    instead.  */
 
 int
-getopt_long_only (int argc, char **argv, const char *options,
+getopt_long_only (int argc, char *__getopt_argv_const *argv,
+                 const char *options,
                  const struct option *long_options, int *opt_index)
 {
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 1, 0);
+  return _getopt_internal (argc, (char **) argv, options, long_options,
+                          opt_index, 1, 0);
 }
 
 int
index c5c836e6484b0ebb6b2e77c05c733fa0d6b4b05d..6eaa7eb91a69e35d083a55b8e7ca57de6f7e56b5 100644 (file)
 # define optopt __GETOPT_PREFIX##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).  */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# define __getopt_argv_const /* empty */
+#else
+# define __getopt_argv_const const
+#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
@@ -178,11 +189,11 @@ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
        __THROW;
 
 #ifndef __need_getopt
-extern int getopt_long (int ___argc, char **___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 **___argv,
+extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
                             const char *__shortopts,
                             const struct option *__longopts, int *__longind)
        __THROW;