diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-01-24 07:52:03 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-01-24 07:52:03 +0000 |
commit | a30a9a3ec41f93213f6813a50f664fcf79a14452 (patch) | |
tree | 2a329921b4ce5434d452550c51649e0fba3f916b /lib | |
parent | 529ecbddcc6814ae9fc8ebbecaa3d49ee2dd0d8d (diff) | |
download | coreutils-a30a9a3ec41f93213f6813a50f664fcf79a14452.tar.xz |
Import from gnulib.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ChangeLog | 24 | ||||
-rw-r--r-- | lib/getopt.c | 82 | ||||
-rw-r--r-- | lib/strndup.c | 23 | ||||
-rw-r--r-- | lib/strnlen.c | 27 |
4 files changed, 64 insertions, 92 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index a306f34be..1935fafb9 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -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-23 Jim Meyering <jim@meyering.net> * xalloc-die.c: Remove unused definition of N_. diff --git a/lib/getopt.c b/lib/getopt.c index bcb81c83f..83bd6db43 100644 --- 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 <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; -#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 @@ _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); diff --git a/lib/strndup.c b/lib/strndup.c index 9ac2756a2..932a83e4c 100644 --- 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 <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 @@ -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 @@ __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 diff --git a/lib/strnlen.c b/lib/strnlen.c index 97a1f810c..09ba788ab 100644 --- 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 <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 |