diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-11-03 07:44:15 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-11-03 07:44:15 +0000 |
commit | 5a5367474b6808f488d4b0e74ba30bebfdc882f3 (patch) | |
tree | f52115c051496683e41fd9f7c1f9ad4935e66940 /lib | |
parent | 47bcfc54da3d26655f0c151f214a29cf58711765 (diff) | |
download | coreutils-5a5367474b6808f488d4b0e74ba30bebfdc882f3.tar.xz |
Sync from gnulib.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ChangeLog | 4 | ||||
-rw-r--r-- | lib/getdate.y | 7 | ||||
-rw-r--r-- | lib/getpass.c | 30 | ||||
-rw-r--r-- | lib/setenv.h | 12 | ||||
-rw-r--r-- | lib/xreadlink.c | 18 |
5 files changed, 49 insertions, 22 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index c54f4b9b9..5f64004f6 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2004-11-02 Paul Eggert <eggert@cs.ucla.edu> + + * getdate.y, getpass.c, setenv.h: Sync from gnulib. + 2004-10-29 Paul Eggert <eggert@cs.ucla.edu> * getdate.y, getpagesize.h, mktime.c: Sync from gnulib. diff --git a/lib/getdate.y b/lib/getdate.y index ec8c19250..d203c09ae 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -50,6 +50,7 @@ #include <ctype.h> #include <limits.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1307,8 +1308,8 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) int month = tm.tm_mon + pc.rel_month; int day = tm.tm_mday + pc.rel_day; if (((year < tm.tm_year) ^ (pc.rel_year < 0)) - | (month < tm.tm_mon) ^ (pc.rel_month < 0) - | (day < tm.tm_mday) ^ (pc.rel_day < 0)) + | ((month < tm.tm_mon) ^ (pc.rel_month < 0)) + | ((day < tm.tm_mday) ^ (pc.rel_day < 0))) goto fail; tm.tm_year = year; tm.tm_mon = month; @@ -1365,8 +1366,6 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) #if TEST -#include <stdio.h> - int main (int ac, char **av) { diff --git a/lib/getpass.c b/lib/getpass.c index 78f21e019..4f520aef3 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -58,16 +58,26 @@ #elif USE_UNLOCKED_IO # include "unlocked-io.h" #else -# undef fflush_unlocked -# define fflush_unlocked(x) fflush (x) -# undef flockfile -# define flockfile(x) ((void) 0) -# undef funlockfile -# define funlockfile(x) ((void) 0) -# undef fputs_unlocked -# define fputs_unlocked(str,stream) fputs (str, stream) -# undef putc_unlocked -# define putc_unlocked(c,stream) putc (c, stream) +# if !HAVE_DECL_FFLUSH_UNLOCKED +# undef fflush_unlocked +# define fflush_unlocked(x) fflush (x) +# endif +# if !HAVE_DECL_FLOCKFILE +# undef flockfile +# define flockfile(x) ((void) 0) +# endif +# if !HAVE_DECL_FUNLOCKFILE +# undef funlockfile +# define funlockfile(x) ((void) 0) +# endif +# if !HAVE_DECL_FPUTS_UNLOCKED +# undef fputs_unlocked +# define fputs_unlocked(str,stream) fputs (str, stream) +# endif +# if !HAVE_DECL_PUTC_UNLOCKED +# undef putc_unlocked +# define putc_unlocked(c,stream) putc (c, stream) +# endif #endif #if _LIBC diff --git a/lib/setenv.h b/lib/setenv.h index 1c69ac3e4..7ac5ae645 100644 --- a/lib/setenv.h +++ b/lib/setenv.h @@ -1,5 +1,5 @@ /* Setting environment variables. - Copyright (C) 2001-2003 Free Software Foundation, Inc. + Copyright (C) 2001-2004 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 @@ -34,7 +34,15 @@ extern int setenv (const char *name, const char *value, int replace); #endif -#if !HAVE_UNSETENV +#if HAVE_UNSETENV + +# if VOID_UNSETENV +/* On some systems, unsetenv() returns void. + This is the case for FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ +# define unsetenv(name) ((unsetenv)(name), 0) +# endif + +#else /* Remove the variable NAME from the environment. */ extern int unsetenv (const char *name); diff --git a/lib/xreadlink.c b/lib/xreadlink.c index 2e66c07f2..c38e2d3aa 100644 --- a/lib/xreadlink.c +++ b/lib/xreadlink.c @@ -41,6 +41,8 @@ # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) #endif +#define MAXSIZE (SIZE_MAX < SSIZE_MAX ? SIZE_MAX : SSIZE_MAX) + #include "xalloc.h" /* Call readlink to get the symbolic link value of FILENAME. @@ -56,14 +58,15 @@ xreadlink (char const *filename, size_t size) { /* The initial buffer size for the link value. A power of 2 detects arithmetic overflow earlier, but is not required. */ - size_t buf_size = size + 1; + size_t buf_size = size < MAXSIZE ? size + 1 : MAXSIZE; while (1) { char *buffer = xmalloc (buf_size); - ssize_t link_length = readlink (filename, buffer, buf_size); + ssize_t r = readlink (filename, buffer, buf_size); + size_t link_length = r; - if (link_length < 0) + if (r < 0) { int saved_errno = errno; free (buffer); @@ -71,15 +74,18 @@ xreadlink (char const *filename, size_t size) return NULL; } - if ((size_t) link_length < buf_size) + if (link_length < buf_size) { buffer[link_length] = 0; return buffer; } free (buffer); - buf_size *= 2; - if (! (0 < buf_size && buf_size <= SSIZE_MAX)) + if (buf_size <= MAXSIZE / 2) + buf_size *= 2; + else if (buf_size < MAXSIZE) + buf_size = MAXSIZE; + else xalloc_die (); } } |