diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 6 | ||||
-rw-r--r-- | lib/Makefile.in | 4 | ||||
-rw-r--r-- | lib/exclude.c | 13 | ||||
-rw-r--r-- | lib/getcwd.c | 81 | ||||
-rw-r--r-- | lib/obstack.c | 13 | ||||
-rw-r--r-- | lib/obstack.h | 12 | ||||
-rw-r--r-- | lib/regex_internal.h | 5 | ||||
-rw-r--r-- | lib/strcasecmp.c | 9 | ||||
-rw-r--r-- | lib/strncasecmp.c | 11 |
9 files changed, 85 insertions, 69 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 4ab24b9..215d4b6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -152,6 +152,12 @@ libgnu_a_SOURCES += strstr.h ## end gnulib module strstr +## begin gnulib module verify + +libgnu_a_SOURCES += verify.h + +## end gnulib module verify + ## begin gnulib module xalloc-die libgnu_a_SOURCES += xalloc-die.c diff --git a/lib/Makefile.in b/lib/Makefile.in index 242b7c3..a8c82c7 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -158,6 +158,8 @@ GENCAT = @GENCAT@ GETOPT_H = @GETOPT_H@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ +GL_COND_LIBTOOL_FALSE = @GL_COND_LIBTOOL_FALSE@ +GL_COND_LIBTOOL_TRUE = @GL_COND_LIBTOOL_TRUE@ GMSGFMT = @GMSGFMT@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ @@ -251,7 +253,7 @@ AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies noinst_LIBRARIES = libgnu.a libgnu_a_SOURCES = basename.c stripslash.c exit.h gettext.h mbchar.h \ mbuiter.h strcase.h strnlen1.h strnlen1.c strpbrk.h strsep.h \ - strstr.h xalloc-die.c + strstr.h verify.h xalloc-die.c libgnu_a_LIBADD = @LIBOBJS@ @ALLOCA@ EXTRA_DIST = alloca_.h fnmatch_.h fnmatch_loop.c getopt_.h \ getopt_int.h inttostr.c stdbool_.h diff --git a/lib/exclude.c b/lib/exclude.c index de1a5c3..6a0c149 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -37,6 +37,7 @@ #include "fnmatch.h" #include "strcase.h" #include "xalloc.h" +#include "verify.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -54,9 +55,6 @@ is_space (unsigned char c) return IN_CTYPE_DOMAIN (c) && isspace (c); } -/* Verify a requirement at compile-time (unlike assert, which is runtime). */ -#define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } - /* Non-GNU systems lack these options, so we don't need to check them. */ #ifndef FNM_CASEFOLD # define FNM_CASEFOLD 0 @@ -65,11 +63,10 @@ is_space (unsigned char c) # define FNM_LEADING_DIR 0 #endif -verify (EXCLUDE_macros_do_not_collide_with_FNM_macros, - (((EXCLUDE_ANCHORED | EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS) - & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR - | FNM_CASEFOLD)) - == 0)); +verify (((EXCLUDE_ANCHORED | EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS) + & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR + | FNM_CASEFOLD)) + == 0); /* An exclude pattern-options pair. The options are fnmatch options ORed with EXCLUDE_* options. */ diff --git a/lib/getcwd.c b/lib/getcwd.c index 3bc6e9a..ec1771b 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -201,6 +201,8 @@ __getcwd (char *buf, size_t size) ino_t dotino; bool mount_point; int parent_status; + size_t dirroom; + size_t namlen; /* Look at the parent directory. */ #ifdef AT_FDCWD @@ -241,11 +243,20 @@ __getcwd (char *buf, size_t size) goto lose; dotlist[dotlen++] = '/'; #endif - /* Clear errno to distinguish EOF from error if readdir returns - NULL. */ - __set_errno (0); - while ((d = __readdir (dirstream)) != NULL) + for (;;) { + /* Clear errno to distinguish EOF from error if readdir returns + NULL. */ + __set_errno (0); + d = __readdir (dirstream); + if (d == NULL) + { + if (errno == 0) + /* EOF on dirstream, which means that the current directory + has been removed. */ + __set_errno (ENOENT); + goto lose; + } if (d->d_name[0] == '.' && (d->d_name[1] == '\0' || (d->d_name[1] == '.' && d->d_name[2] == '\0'))) @@ -303,48 +314,38 @@ __getcwd (char *buf, size_t size) break; } } - if (d == NULL) - { - if (errno == 0) - /* EOF on dirstream, which means that the current directory - has been removed. */ - __set_errno (ENOENT); - goto lose; - } - else - { - size_t dirroom = dirp - dir; - size_t namlen = _D_EXACT_NAMLEN (d); - if (dirroom <= namlen) + dirroom = dirp - dir; + namlen = _D_EXACT_NAMLEN (d); + + if (dirroom <= namlen) + { + if (size != 0) { - if (size != 0) - { - __set_errno (ERANGE); - goto lose; - } - else - { - char *tmp; - size_t oldsize = allocated; + __set_errno (ERANGE); + goto lose; + } + else + { + char *tmp; + size_t oldsize = allocated; - allocated += MAX (allocated, namlen); - if (allocated < oldsize - || ! (tmp = realloc (dir, allocated))) - goto memory_exhausted; + allocated += MAX (allocated, namlen); + if (allocated < oldsize + || ! (tmp = realloc (dir, allocated))) + goto memory_exhausted; - /* Move current contents up to the end of the buffer. - This is guaranteed to be non-overlapping. */ - dirp = memcpy (tmp + allocated - (oldsize - dirroom), - tmp + dirroom, - oldsize - dirroom); - dir = tmp; - } + /* Move current contents up to the end of the buffer. + This is guaranteed to be non-overlapping. */ + dirp = memcpy (tmp + allocated - (oldsize - dirroom), + tmp + dirroom, + oldsize - dirroom); + dir = tmp; } - dirp -= namlen; - memcpy (dirp, d->d_name, namlen); - *--dirp = '/'; } + dirp -= namlen; + memcpy (dirp, d->d_name, namlen); + *--dirp = '/'; thisdev = dotdev; thisino = dotino; diff --git a/lib/obstack.c b/lib/obstack.c index f3ca2c2..6df0611 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -51,10 +51,6 @@ # endif #endif -#if defined _LIBC && defined USE_IN_LIBIO -# include <wchar.h> -#endif - #include <stddef.h> #ifndef ELIDE_CODE @@ -433,12 +429,11 @@ print_and_abort (void) happen because the "memory exhausted" message appears in other places like this and the translation should be reused instead of creating a very similar string which requires a separate translation. */ -# if defined _LIBC && defined USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"%s\n", _("memory exhausted")); - else +# ifdef _LIBC + (void) __fxprintf (NULL, "%s\n", _("memory exhausted")); +# else + fprintf (stderr, "%s\n", _("memory exhausted")); # endif - fprintf (stderr, "%s\n", _("memory exhausted")); exit (obstack_exit_failure); } diff --git a/lib/obstack.h b/lib/obstack.h index 940bc80..95dd438 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -1,11 +1,7 @@ /* obstack.h - object stack macros - Copyright (C) 1988-1994,1996-1999,2003,2004 Free Software Foundation, Inc. - - 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. - - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. + Copyright (C) 1988-1994,1996-1999,2003,2004,2005 + 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 it under the terms of the GNU General Public License as published by @@ -464,7 +460,7 @@ __extension__ \ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)) # define obstack_int_grow_fast(h,aint) \ - (((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr)) + (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint)) # define obstack_blank(h,length) \ ( (h)->temp.tempint = (length), \ diff --git a/lib/regex_internal.h b/lib/regex_internal.h index a36ae4c..d10ba1e 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -182,6 +182,11 @@ typedef unsigned long int bitset_word; # if BITSET_WORD_BITS <= SBC_MAX # error "Invalid SBC_MAX" # endif +#elif BITSET_WORD_MAX == (0xffffffff + 2) * 0xffffffff +/* Work around a bug in PGC GNU/Linux x86-64 5.2-1 and 6.0-8 (and + probably other versions), where the preprocessor mishandles large + unsigned values and thinks they are signed. */ +# define BITSET_WORD_BITS 64 #else # error "Add case for new bitset_word size" #endif diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c index 71f2eca..c1bac0a 100644 --- a/lib/strcasecmp.c +++ b/lib/strcasecmp.c @@ -25,6 +25,7 @@ #include "strcase.h" #include <ctype.h> +#include <limits.h> #if HAVE_MBRTOWC # include "mbuiter.h" @@ -93,6 +94,12 @@ strcasecmp (const char *s1, const char *s2) } while (c1 == c2); - return c1 - c2; + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); } } diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c index 72ead01..0209c39 100644 --- a/lib/strncasecmp.c +++ b/lib/strncasecmp.c @@ -1,5 +1,5 @@ /* strncasecmp.c -- case insensitive string comparator - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2005 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 @@ -23,6 +23,7 @@ #include "strcase.h" #include <ctype.h> +#include <limits.h> #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) @@ -54,5 +55,11 @@ strncasecmp (const char *s1, const char *s2, size_t n) } while (c1 == c2); - return c1 - c2; + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); } |