Work around porting bugs reported by Dieter in
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Jan 2006 07:40:58 +0000 (07:40 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Jan 2006 07:40:58 +0000 (07:40 +0000)
<http://lists.gnu.org/archive/html/bug-bison/2006-01/msg00049.html>.
* lib/getopt.c (_NOPROTO): Remove; no longer needed.
Include <stdlib.h> and <unistd.h> in all environments; it's safe now.
Include "getopt.h" first, to check interface.
(getenv): Declare only if defined HAVE_DECL_GETENV &&
!HAVE_DECL_GETENV.
* lib/strndup.c [!_LIBC]: Include "strndup.h" to get prototype.
(__strndup): Revert to K&R-style function dfns, the glibc style.
* lib/strnlen.c: Don't claim it's taken from glibc; it's not.
(strnlen, __strnlen): Remove #defines and #undefs; not needed.
Include strnlen.h first, to get prototype properly.
(strnlen): Renamed from __strnlen.
Remove weak alias.
* m4/getopt.m4 (gl_PREREQ_GETOPT): Check for getenv decl.

lib/ChangeLog
lib/getopt.c
lib/strndup.c
lib/strnlen.c
m4/ChangeLog
m4/getopt.m4

index 9b37182..a5b07f9 100644 (file)
@@ -1,3 +1,27 @@
+2006-01-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Work around porting bugs reported by Dieter in
+       <http://lists.gnu.org/archive/html/bug-bison/2006-01/msg00049.html>.
+       * getopt.c (_NOPROTO): Remove; no longer needed.
+       Include <stdlib.h> and <unistd.h> in all environments; it's safe now.
+       Include "getopt.h" first, to check interface.
+       (getenv): Declare only if defined HAVE_DECL_GETENV &&
+       !HAVE_DECL_GETENV.
+       * strndup.c [!_LIBC]: Include "strndup.h" to get prototype.
+       (__strndup): Revert to K&R-style function dfns, the glibc style.
+       * strnlen.c: Don't claim it's taken from glibc; it's not.
+       (strnlen, __strnlen): Remove #defines and #undefs; not needed.
+       Include strnlen.h first, to get prototype properly.
+       (strnlen): Renamed from __strnlen.
+       Remove weak alias.
+
+2006-01-23  Ulrich Drepper  <drepper@redhat.com>
+
+       These changes imported from libc.
+       * getopt.c: Use __fxprintf instead of inline stream orientation
+       test and two separate function calls.
+       * strndup.c (__strndup): Add libc_hidden_def.
+
 2006-01-22  Bruno Haible  <bruno@clisp.org>
 
        * vasnprintf.c (VASNPRINTF): In the computation of the size of the
index bcb81c8..83bd6db 100644 (file)
@@ -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,2002,2003,2004
+   Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006
        Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 \f
-/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
-   Ditto for AIX 3.2 and <stdlib.h>.  */
-#ifndef _NO_PROTO
-# define _NO_PROTO
-#endif
-
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
-#include <stdio.h>
-
-/* 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.  */
-# include <stdlib.h>
-# include <unistd.h>
-#endif /* GNU C library.  */
+#include "getopt.h"
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #ifdef VMS
 # include <unixlib.h>
@@ -76,7 +64,6 @@
    GNU application programs can use a third alternative mode in which
    they can distinguish the relative order of options and other arguments.  */
 
-#include "getopt.h"
 #include "getopt_int.h"
 
 /* For communication from `getopt' to the caller.
@@ -118,16 +105,9 @@ int optopt = '?';
 static struct _getopt_data getopt_data;
 
 \f
-#ifndef __GNU_LIBRARY__
-
-/* Avoid depending on library functions or files
-   whose names are inconsistent.  */
-
-#ifndef getenv
+#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
 extern char *getenv ();
 #endif
-
-#endif /* not __GNU_LIBRARY__ */
 \f
 #ifdef _LIBC
 /* Stored original parameters.
@@ -556,10 +536,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                 if (_IO_fwide (stderr, 0) > 0)
-                   __fwprintf (stderr, L"%s", buf);
-                 else
-                   fputs (buf, stderr);
+                 __fxprintf (NULL, "%s", buf);
 
                  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                  _IO_funlockfile (stderr);
@@ -634,10 +611,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                          ((_IO_FILE *) stderr)->_flags2
                            |= _IO_FLAGS2_NOTCANCEL;
 
-                         if (_IO_fwide (stderr, 0) > 0)
-                           __fwprintf (stderr, L"%s", buf);
-                         else
-                           fputs (buf, stderr);
+                         __fxprintf (NULL, "%s", buf);
 
                          ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                          _IO_funlockfile (stderr);
@@ -674,10 +648,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                          ((_IO_FILE *) stderr)->_flags2
                            |= _IO_FLAGS2_NOTCANCEL;
 
-                         if (_IO_fwide (stderr, 0) > 0)
-                           __fwprintf (stderr, L"%s", buf);
-                         else
-                           fputs (buf, stderr);
+                         __fxprintf (NULL, "%s", buf);
 
                          ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                          _IO_funlockfile (stderr);
@@ -751,10 +722,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                 if (_IO_fwide (stderr, 0) > 0)
-                   __fwprintf (stderr, L"%s", buf);
-                 else
-                   fputs (buf, stderr);
+                 __fxprintf (NULL, "%s", buf);
 
                  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                  _IO_funlockfile (stderr);
@@ -817,10 +785,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-               if (_IO_fwide (stderr, 0) > 0)
-                 __fwprintf (stderr, L"%s", buf);
-               else
-                 fputs (buf, stderr);
+               __fxprintf (NULL, "%s", buf);
 
                ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                _IO_funlockfile (stderr);
@@ -868,10 +833,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                   if (_IO_fwide (stderr, 0) > 0)
-                     __fwprintf (stderr, L"%s", buf);
-                   else
-                     fputs (buf, stderr);
+                   __fxprintf (NULL, "%s", buf);
 
                    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                    _IO_funlockfile (stderr);
@@ -940,10 +902,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                   if (_IO_fwide (stderr, 0) > 0)
-                     __fwprintf (stderr, L"%s", buf);
-                   else
-                     fputs (buf, stderr);
+                   __fxprintf (NULL, "%s", buf);
 
                    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                    _IO_funlockfile (stderr);
@@ -985,10 +944,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                            ((_IO_FILE *) stderr)->_flags2
                              |= _IO_FLAGS2_NOTCANCEL;
 
-                           if (_IO_fwide (stderr, 0) > 0)
-                             __fwprintf (stderr, L"%s", buf);
-                           else
-                             fputs (buf, stderr);
+                           __fxprintf (NULL, "%s", buf);
 
                            ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                            _IO_funlockfile (stderr);
@@ -1027,10 +983,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                            ((_IO_FILE *) stderr)->_flags2
                              |= _IO_FLAGS2_NOTCANCEL;
 
-                           if (_IO_fwide (stderr, 0) > 0)
-                             __fwprintf (stderr, L"%s", buf);
-                           else
-                             fputs (buf, stderr);
+                           __fxprintf (NULL, "%s", buf);
 
                            ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                            _IO_funlockfile (stderr);
@@ -1101,10 +1054,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                        int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
                        ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                       if (_IO_fwide (stderr, 0) > 0)
-                         __fwprintf (stderr, L"%s", buf);
-                       else
-                         fputs (buf, stderr);
+                       __fxprintf (NULL, "%s", buf);
 
                        ((_IO_FILE *) stderr)->_flags2 = old_flags2;
                        _IO_funlockfile (stderr);
index 9ac2756..932a83e 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free
+   Software Foundation, Inc.
 
    NOTE: The canonical source of this file is maintained with the GNU C Library.
    Bugs can be reported to bug-glibc@prep.ai.mit.edu.
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
+#if !_LIBC
+# include "strndup.h"
+#endif
 
 #include <stdlib.h>
 #include <string.h>
 
-/* Get strnlen. */
-#include "strnlen.h"
+#if !_LIBC
+# include "strnlen.h"
+# ifndef __strnlen
+#  define __strnlen strnlen
+# endif
+#endif
 
 #undef __strndup
 #undef strndup
 #endif
 
 char *
-__strndup (const char *s, size_t n)
+__strndup (s, n)
+     const char *s;
+     size_t n;
 {
-  size_t len = strnlen (s, n);
+  size_t len = __strnlen (s, n);
   char *new = malloc (len + 1);
 
   if (new == NULL)
@@ -46,6 +56,9 @@ __strndup (const char *s, size_t n)
   new[len] = '\0';
   return memcpy (new, s, len);
 }
+#ifdef libc_hidden_def
+libc_hidden_def (__strndup)
+#endif
 #ifdef weak_alias
 weak_alias (__strndup, strndup)
 #endif
index 97a1f81..09ba788 100644 (file)
@@ -1,6 +1,6 @@
 /* Find the length of STRING, but scan at most MAXLEN characters.
-   Copyright (C) 1996, 1997, 1998, 2000-2003 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
 
    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
    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 General Public License along
-   with this program; if not, write to the Free Software Foundation,
+   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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#undef strnlen
 
-#include <string.h>
-
-#undef __strnlen
-#undef strnlen
-
-#ifndef _LIBC
-# define strnlen rpl_strnlen
-#endif
-
-#ifndef weak_alias
-# define __strnlen strnlen
-#endif
+#include "strnlen.h"
 
 /* Find the length of STRING, but scan at most MAXLEN characters.
    If no '\0' terminator is found in that many characters, return MAXLEN.  */
 
 size_t
-__strnlen (const char *string, size_t maxlen)
+strnlen (const char *string, size_t maxlen)
 {
   const char *end = memchr (string, '\0', maxlen);
   return end ? (size_t) (end - string) : maxlen;
 }
-#ifdef weak_alias
-weak_alias (__strnlen, strnlen)
-#endif
index 4f134b2..a63ba0f 100644 (file)
@@ -1,3 +1,7 @@
+2006-01-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * getopt.m4 (gl_PREREQ_GETOPT): Check for getenv decl.
+
 2006-01-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        * lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Use -Wl,-z,ignore
index 6b98782..e60b746 100644 (file)
@@ -1,5 +1,5 @@
-# getopt.m4 serial 11
-dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+# getopt.m4 serial 12
+dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -77,4 +77,7 @@ AC_DEFUN([gl_GETOPT_IFELSE],
 AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
 
 # Prerequisites of lib/getopt*.
-AC_DEFUN([gl_PREREQ_GETOPT], [:])
+AC_DEFUN([gl_PREREQ_GETOPT],
+[
+  AC_CHECK_DECLS_ONCE([getenv])
+])