# HG changeset patch # User Paul Eggert # Date 1138088458 0 # Node ID 453776fca04b37193ae99411ae1a41213bba0b6c # Parent ba8c810f22a8a83f1dc95c3129efd819022e0bf3 Work around porting bugs reported by Dieter in . * lib/getopt.c (_NOPROTO): Remove; no longer needed. Include and 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. diff --git a/lib/ChangeLog b/lib/ChangeLog --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,27 @@ +2006-01-23 Paul Eggert + + Work around porting bugs reported by Dieter in + . + * getopt.c (_NOPROTO): Remove; no longer needed. + Include and 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 + + 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 * vasnprintf.c (VASNPRINTF): In the computation of the size of the diff --git a/lib/getopt.c b/lib/getopt.c --- 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,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. @@ -20,28 +20,16 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* This tells Alpha OSF/1 not to define a getopt prototype in . - Ditto for AIX 3.2 and . */ -#ifndef _NO_PROTO -# define _NO_PROTO -#endif - #ifdef HAVE_CONFIG_H # include #endif -#include +#include "getopt.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 -# include -#endif /* GNU C library. */ - +#include +#include #include +#include #ifdef VMS # include @@ -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 @@ static struct _getopt_data getopt_data; -#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__ */ #ifdef _LIBC /* Stored original parameters. @@ -556,10 +536,7 @@ 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 @@ ((_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 @@ ((_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 @@ 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 @@ 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 @@ 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 @@ 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 @@ ((_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 @@ ((_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 @@ 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); diff --git a/lib/strndup.c b/lib/strndup.c --- a/lib/strndup.c +++ b/lib/strndup.c @@ -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. @@ -20,12 +21,19 @@ #ifdef HAVE_CONFIG_H # include #endif +#if !_LIBC +# include "strndup.h" +#endif #include #include -/* Get strnlen. */ -#include "strnlen.h" +#if !_LIBC +# include "strnlen.h" +# ifndef __strnlen +# define __strnlen strnlen +# endif +#endif #undef __strndup #undef strndup @@ -35,9 +43,11 @@ #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 @@ 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 diff --git a/lib/strnlen.c b/lib/strnlen.c --- a/lib/strnlen.c +++ b/lib/strnlen.c @@ -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 @@ -12,37 +12,22 @@ 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 #endif -#undef strnlen -#include - -#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 diff --git a/m4/ChangeLog b/m4/ChangeLog --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2006-01-23 Paul Eggert + + * getopt.m4 (gl_PREREQ_GETOPT): Check for getenv decl. + 2006-01-20 Paul Eggert * lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Use -Wl,-z,ignore diff --git a/m4/getopt.m4 b/m4/getopt.m4 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -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], [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]) +])