From dce9582d2ca06a6c50165014b21d95654541e8da Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 13 Sep 2003 22:01:20 +0000 Subject: Update from gnulib. --- lib/strcspn.c | 12 ++---------- lib/strdup.c | 13 +++++-------- lib/strndup.c | 15 ++++----------- lib/strnlen.c | 16 +--------------- lib/strpbrk.c | 7 ++----- lib/strstr.c | 6 ++---- lib/strtod.c | 21 ++++----------------- lib/strtoimax.c | 16 +--------------- lib/tempname.c | 6 +----- lib/unicodeio.c | 6 +----- lib/userspec.c | 15 ++------------- lib/vasprintf.h | 28 ++++++++++++++-------------- lib/xgethostname.c | 2 +- lib/xreadlink.c | 4 +--- lib/xstrdup.c | 13 ++++--------- lib/xstrndup.c | 26 ++++++++++++++------------ lib/xstrndup.h | 24 +++++++++++++++++++++++- 17 files changed, 82 insertions(+), 148 deletions(-) (limited to 'lib') diff --git a/lib/strcspn.c b/lib/strcspn.c index 2bbd90664..33a662852 100644 --- a/lib/strcspn.c +++ b/lib/strcspn.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1994, 1996-1997, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1994, 1996-1997, 2002-2003 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@gnu.org. @@ -23,15 +23,7 @@ #endif #include - -#if defined _LIBC || HAVE_STRING_H -# include -#else -# include -# ifndef strchr -# define strchr index -# endif -#endif +#include #undef strcspn diff --git a/lib/strdup.c b/lib/strdup.c index d37207199..52667e98e 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -1,4 +1,6 @@ -/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003 Free Software + Foundation, Inc. + This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -19,13 +21,8 @@ # include #endif -#if defined _LIBC || defined STDC_HEADERS -# include -# include -#else -char *malloc (); -char *memcpy (); -#endif +#include +#include #undef __strdup #undef strdup diff --git a/lib/strndup.c b/lib/strndup.c index 136e51c73..f85627e87 100644 --- a/lib/strndup.c +++ b/lib/strndup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998, 2000, 2003 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. @@ -21,15 +21,8 @@ # include "config.h" #endif -#include -#include - -#if defined _LIBC || defined STDC_HEADERS -# include -# include -#else -char *malloc (); -#endif +#include +#include #ifndef HAVE_DECL_STRNLEN "this configure-time declaration test was not run" @@ -55,7 +48,7 @@ __strndup (const char *s, size_t n) return NULL; new[len] = '\0'; - return (char *) memcpy (new, s, len); + return memcpy (new, s, len); } #ifdef weak_alias weak_alias (__strndup, strndup) diff --git a/lib/strnlen.c b/lib/strnlen.c index 617b0aa18..c9f389845 100644 --- a/lib/strnlen.c +++ b/lib/strnlen.c @@ -21,21 +21,7 @@ #endif #undef strnlen -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#else -# include -#endif - -#ifndef HAVE_DECL_MEMCHR -"this configure-time declaration test was not run" -#endif -#if !HAVE_DECL_MEMCHR -char *memchr (); -#endif +#include #undef __strnlen #undef strnlen diff --git a/lib/strpbrk.c b/lib/strpbrk.c index 01d8df5a8..ce4399620 100644 --- a/lib/strpbrk.c +++ b/lib/strpbrk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1994, 2000, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1994, 2000, 2002-2003 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. @@ -21,10 +21,7 @@ #endif #include - -#if defined _LIBC || HAVE_STRING_H -# include -#endif +#include #undef strpbrk diff --git a/lib/strstr.c b/lib/strstr.c index 42ffcfa8e..dd4622297 100644 --- a/lib/strstr.c +++ b/lib/strstr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994, 1999, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1994, 1999, 2002-2003 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -28,9 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ # include #endif -#if defined _LIBC || defined HAVE_STRING_H -# include -#endif +#include typedef unsigned chartype; diff --git a/lib/strtod.c b/lib/strtod.c index 10edb5cfe..161f97a7b 100644 --- a/lib/strtod.c +++ b/lib/strtod.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1997, 1999, 2003 Free Software Foundation, Inc. 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 @@ -37,22 +37,9 @@ extern int errno; #include -#if HAVE_FLOAT_H -# include -#else -# define DBL_MAX 1.7976931348623159e+308 -# define DBL_MIN 2.2250738585072010e-308 -#endif - -#if STDC_HEADERS -# include -# include -#else -# define NULL 0 -# ifndef HUGE_VAL -# define HUGE_VAL HUGE -# endif -#endif +#include +#include +#include /* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the character after the last one used in the number is put in *ENDPTR. */ diff --git a/lib/strtoimax.c b/lib/strtoimax.c index 555f2d5b5..4ce741cfd 100644 --- a/lib/strtoimax.c +++ b/lib/strtoimax.c @@ -27,20 +27,12 @@ # include #endif -#if HAVE_STDLIB_H -# include -#endif +#include /* Verify a requirement at compile-time (unlike assert, which is runtime). */ #define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } #ifdef UNSIGNED -# ifndef HAVE_DECL_STRTOUL -"this configure-time declaration test was not run" -# endif -# if !HAVE_DECL_STRTOUL -unsigned long strtoul (char const *, char **, int); -# endif # ifndef HAVE_DECL_STRTOULL "this configure-time declaration test was not run" # endif @@ -50,12 +42,6 @@ unsigned long long strtoull (char const *, char **, int); #else -# ifndef HAVE_DECL_STRTOL -"this configure-time declaration test was not run" -# endif -# if !HAVE_DECL_STRTOL -long strtol (char const *, char **, int); -# endif # ifndef HAVE_DECL_STRTOLL "this configure-time declaration test was not run" # endif diff --git a/lib/tempname.c b/lib/tempname.c index 13a8204a4..b3d0874ce 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -44,12 +44,8 @@ #endif #include - -#if STDC_HEADERS || _LIBC -# include -#endif - #include +#include #if HAVE_FCNTL_H || _LIBC # include diff --git a/lib/unicodeio.c b/lib/unicodeio.c index 7b7f6f229..4f0792bb6 100644 --- a/lib/unicodeio.c +++ b/lib/unicodeio.c @@ -29,11 +29,7 @@ #include "unicodeio.h" #include -#if HAVE_STRING_H -# include -#else -# include -#endif +#include #include #ifndef errno diff --git a/lib/userspec.c b/lib/userspec.c index 19443ec91..6e58b486c 100644 --- a/lib/userspec.c +++ b/lib/userspec.c @@ -33,19 +33,8 @@ #endif #include - -#if HAVE_STRING_H -# include -#else -# include -# ifndef strchr -# define strchr index -# endif -#endif - -#if STDC_HEADERS -# include -#endif +#include +#include #if HAVE_UNISTD_H # include diff --git a/lib/vasprintf.h b/lib/vasprintf.h index 0ab75ccf4..fdd831f20 100644 --- a/lib/vasprintf.h +++ b/lib/vasprintf.h @@ -21,29 +21,29 @@ #if HAVE_VASPRINTF /* Get asprintf(), vasprintf() declarations. */ -# include +#include #else /* Get va_list. */ -# include +#include -# ifndef __attribute__ +#ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif /* The __-protected variants of `format' and `printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf # endif +#endif -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif /* Write formatted output to a string dynamically allocated with malloc(). If the memory allocation succeeds, store the address of the string in @@ -54,9 +54,9 @@ extern int asprintf (char **result, const char *format, ...) extern int vasprintf (char **result, const char *format, va_list args) __attribute__ ((__format__ (__printf__, 2, 0))); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif diff --git a/lib/xgethostname.c b/lib/xgethostname.c index 60ee91a13..494571ee1 100644 --- a/lib/xgethostname.c +++ b/lib/xgethostname.c @@ -47,7 +47,7 @@ int gethostname (); If malloc fails, exit. Upon any other failure, return NULL. */ char * -xgethostname () +xgethostname (void) { char *hostname; size_t size; diff --git a/lib/xreadlink.c b/lib/xreadlink.c index f5cce16eb..e8c677b44 100644 --- a/lib/xreadlink.c +++ b/lib/xreadlink.c @@ -31,9 +31,7 @@ extern int errno; #include #include -#if HAVE_STDLIB_H -# include -#endif +#include #if HAVE_UNISTD_H # include #endif diff --git a/lib/xstrdup.c b/lib/xstrdup.c index cb1efa8c2..1182c592a 100644 --- a/lib/xstrdup.c +++ b/lib/xstrdup.c @@ -1,5 +1,5 @@ /* xstrdup.c -- copy a string with out of memory checking - Copyright (C) 1990, 1996, 1998, 2001 Free Software Foundation, Inc. + Copyright (C) 1990, 1996, 1998, 2001, 2003 Free Software Foundation, Inc. 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 @@ -19,16 +19,11 @@ # include #endif -#if STDC_HEADERS || HAVE_STRING_H -# include -#else -# include -#endif - -#include - +/* Specification. */ #include "xalloc.h" +#include + /* Return a newly allocated copy of STRING. */ char * diff --git a/lib/xstrndup.c b/lib/xstrndup.c index a1e819efa..5addbf663 100644 --- a/lib/xstrndup.c +++ b/lib/xstrndup.c @@ -1,5 +1,5 @@ -/* A wrapper around xstrndup. - +/* Duplicate a bounded initial segment of a string, with out-of-memory + checking. Copyright (C) 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -16,22 +16,24 @@ 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 Jim Meyering. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" +#if HAVE_CONFIG_H +# include #endif +/* Specification. */ #include "xstrndup.h" -#include "xalloc.h" -char *strndup (char const *, size_t); +#include "strndup.h" +#include "xalloc.h" +/* Return a newly allocated copy of at most N bytes of STRING. + In other words, return a copy of the initial segment of length N of + STRING. */ char * -xstrndup (char const *s, size_t n) +xstrndup (const char *string, size_t n) { - char *new = strndup (s, n); - if (new == NULL) + char *s = strndup (string, n); + if (! s) xalloc_die (); - return (char *) new; + return s; } diff --git a/lib/xstrndup.h b/lib/xstrndup.h index 27afc401d..b09a2fc0b 100644 --- a/lib/xstrndup.h +++ b/lib/xstrndup.h @@ -1,2 +1,24 @@ +/* Duplicate a bounded initial segment of a string, with out-of-memory + checking. + Copyright (C) 2003 Free Software Foundation, Inc. + + 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 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, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #include -char *xstrndup (char const *s, size_t n); + +/* Return a newly allocated copy of at most N bytes of STRING. + In other words, return a copy of the initial segment of length N of + STRING. */ +extern char *xstrndup (const char *string, size_t n); -- cgit v1.2.3-54-g00ecf