Sync with diffutils.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Aug 2002 14:25:03 +0000 (14:25 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Aug 2002 14:25:03 +0000 (14:25 +0000)
lib/error.c
lib/getopt.c
lib/getopt.h
lib/getopt1.c
lib/gettext.h
m4/malloc.m4
m4/realloc.m4

index 9c0700c..902519c 100644 (file)
@@ -3,20 +3,19 @@
    This file is part of the GNU C Library.  Its master source is NOT part of
    the C library, however.  The master source lives in /gd/gnu/lib.
 
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-   The GNU C Library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   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.  */
 
 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
 
@@ -54,6 +53,7 @@ void exit ();
 #endif
 
 #include "error.h"
+#include "unlocked-io.h"
 
 #ifndef _
 # define _(String) String
index 08ba35b..dc07cb3 100644 (file)
@@ -2,24 +2,23 @@
    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.
 
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-   The GNU C Library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   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.  */
 \f
 /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
    Ditto for AIX 3.2 and <stdlib.h>.  */
 # 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
 #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>
@@ -190,30 +179,18 @@ static enum
 /* Value of POSIXLY_CORRECT environment variable.  */
 static char *posixly_correct;
 \f
-#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;
 {
@@ -225,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
 \f
 /* Handle permutation of arguments.  */
 
@@ -647,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;
@@ -762,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)
            {
@@ -786,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')
index a1b8dd6..cc70194 100644 (file)
@@ -1,21 +1,23 @@
 /* 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.
 
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-   The GNU C Library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   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.  */
 
 #ifndef _GETOPT_H
 
    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
@@ -138,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,
index 22a7efb..eb4188a 100644 (file)
@@ -1,37 +1,27 @@
 /* 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.
 
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-   The GNU C Library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   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.  */
 \f
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #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
index ea67f30..de02c60 100644 (file)
@@ -1,20 +1,19 @@
 /* Convenience header for conditional use of GNU <libintl.h>.
    Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Library General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
    any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Library 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.  */
+   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.  */
 
 #ifndef _LIBGETTEXT_H
 #define _LIBGETTEXT_H 1
 
 #else
 
+/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
+   chokes if dcgettext is defined as a macro.  So include it now, to make
+   later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
+   as well because people using "gettext.h" will not include <libintl.h>,
+   and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
+   is OK.  */
+#if defined(__sun)
+# include <locale.h>
+#endif
+
 /* Disabled NLS.
    The casts to 'const char *' serve the purpose of producing warnings
    for invalid uses of the value returned from these functions.
index bb60947..f6d43c9 100644 (file)
@@ -1,4 +1,4 @@
-#serial 5
+#serial 7
 
 dnl From Jim Meyering.
 dnl Determine whether malloc accepts 0 as its argument.
@@ -12,7 +12,8 @@ AC_DEFUN([jm_FUNC_MALLOC],
  AC_DEFINE(HAVE_DONE_WORKING_MALLOC_CHECK, 1,
            [Define if the malloc check has been performed. ])
 
- AC_CACHE_CHECK([for working malloc], jm_cv_func_working_malloc,
+ AC_CACHE_CHECK([whether malloc(0) returns a non-NULL pointer],
+                jm_cv_func_working_malloc,
   [AC_TRY_RUN([
     char *malloc ();
     int
@@ -23,10 +24,15 @@ AC_DEFUN([jm_FUNC_MALLOC],
          ],
         jm_cv_func_working_malloc=yes,
         jm_cv_func_working_malloc=no,
-        dnl When crosscompiling, assume malloc is broken.
+        dnl When crosscompiling, assume malloc(0) returns NULL.
         jm_cv_func_working_malloc=no)
   ])
-  if test $jm_cv_func_working_malloc = no; then
+  if test $jm_cv_func_working_malloc = yes; then
+    AC_DEFINE([HAVE_MALLOC], 1,
+             [Define to 1 if your system has a working `malloc' function,
+              and to 0 otherwise.])
+  else
+    AC_DEFINE([HAVE_MALLOC], 0)
     AC_LIBOBJ(malloc)
     AC_DEFINE(malloc, rpl_malloc,
       [Define to rpl_malloc if the replacement function should be used.])
index c8a8237..966f0f5 100644 (file)
@@ -1,4 +1,4 @@
-#serial 5
+#serial 6
 
 dnl From Jim Meyering.
 dnl Determine whether realloc works when both arguments are 0.
@@ -12,7 +12,8 @@ AC_DEFUN([jm_FUNC_REALLOC],
  AC_DEFINE(HAVE_DONE_WORKING_REALLOC_CHECK, 1,
            [Define if the realloc check has been performed. ])
 
- AC_CACHE_CHECK([for working realloc], jm_cv_func_working_realloc,
+ AC_CACHE_CHECK([whether realloc(0,0) returns a non-NULL pointer],
+                jm_cv_func_working_realloc,
   [AC_TRY_RUN([
     char *realloc ();
     int
@@ -23,10 +24,15 @@ AC_DEFUN([jm_FUNC_REALLOC],
          ],
         jm_cv_func_working_realloc=yes,
         jm_cv_func_working_realloc=no,
-        dnl When crosscompiling, assume realloc is broken.
+        dnl When crosscompiling, assume realloc(0,0) returns NULL.
         jm_cv_func_working_realloc=no)
   ])
-  if test $jm_cv_func_working_realloc = no; then
+  if test $jm_cv_func_working_realloc = yes; then
+    AC_DEFINE([HAVE_REALLOC], 1,
+             [Define to 1 if your system has a working `realloc' function,
+              and to 0 otherwise.])
+  else
+    AC_DEFINE([HAVE_REALLOC], 0)
     AC_LIBOBJ(realloc)
     AC_DEFINE(realloc, rpl_realloc,
       [Define to rpl_realloc if the replacement function should be used.])