From: Paul Eggert Date: Sun, 2 Oct 2005 22:38:45 +0000 (+0000) Subject: Sync from coreutils. X-Git-Tag: cvs-readonly~2864 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=9db27e416179e3b92ae18be230250d08ae6190f5;p=gnulib.git Sync from coreutils. * lib/.cppi-disable: Add getaddrinfo.h, getdelim.h, getline.h, getpass.c mbchar.h, mbuiter.h, strcase.h, strnlen.h, strnlen1.h. * lib/.cvsignore: Add fts.h, search.h, t-fpending. * lib/settime.c (settime): Fix { typo in previous patch. Also, don't bother returning ENOSYS if settimeofday or stime fails; just let them return whatever errno they want to return. * lib/utimens.c: Include unistd.h, for dup2. (futimens): Fix typo: HAVE_FUTIMESAT was misspelled in an #if. (futimens) [! HAVE_FUTIMESAT]: If !file, set errno before returning -1. * lib/fts-cycle.c [HAVE_CONFIG_H]: Include . * lib/openat-die.c: Use `#ifdef HAVE_CONFIG_H', not `#if HAVE_CONFIG_H'. * lib/openat.c (fdopendir): Do not define if HAVE_FDOPENDIR. Remove AT_FDCWD test. Do not consume the fd unless successful. * lib/openat.h (fdopendir): Do not define if HAVE_FDOPENDIR. * lib/settime.c (settime): Move the HAVE_STIME block `up' into an #elif block, so that we don't even try to compile it if settimeofday is available. This works around a compilation failure on OSF1 V5.1, due to stime requiring a `long int*' while tv_sec is `int'. * m4/openat.m4 (gl_FUNC_OPENAT): Check for fdopendir. * m4/ullong_max.m4 (gl_ULLONG_MAX): Simplify so that it merely defines ULONG_MAX_LT_ULLONG_MAX. Thomas M.Ott reports that ULLONG_MAX doesn't work with 2.7.2.1. * m4/utimes.m4 (gl_FUNC_UTIMES): Detect the version of utimes from glibc-2.2.5 that fails for read-only files. * m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Compare $gl_have_path... against `yes', rather than just testing for nonempty. --- diff --git a/lib/.cppi-disable b/lib/.cppi-disable index 61a099cd7..ce7e66446 100644 --- a/lib/.cppi-disable +++ b/lib/.cppi-disable @@ -5,6 +5,9 @@ exit.h fnmatch_.h fts.c fts_.h +getaddrinfo.h +getdelim.h +getline.h getndelim2.h getopt.c getopt.h @@ -12,8 +15,11 @@ getopt1.c getopt_.h getopt_int.h getpagesize.h +getpass.c gettext.h localcharset.h +mbchar.h +mbuiter.h md5.h obstack.h printf-args.h @@ -25,8 +31,11 @@ regex_internal.c regex_internal.h stat-time.h stdbool_.h +strcase.h strdup.h strndup.h +strnlen.h +strnlen1.h strtoul.c time_r.h utimecmp.h diff --git a/lib/.cvsignore b/lib/.cvsignore index 39cda9a18..5afaa5942 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -2,15 +2,18 @@ Makefile alloca.h charset.alias +fnmatch.h +fts.h getdate.c getdate.tab.c getopt.h -fnmatch.h lstat.c poll.h ref-add.sed ref-del.sed +search.h stat.c stdbool.h sysexit.h +t-fpending unlocked-io.h diff --git a/lib/fts-cycle.c b/lib/fts-cycle.c index 8c09fb948..13b43dbdd 100644 --- a/lib/fts-cycle.c +++ b/lib/fts-cycle.c @@ -18,6 +18,10 @@ 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 + #include "cycle-check.h" #include "hash.h" diff --git a/lib/openat-die.c b/lib/openat-die.c index f7cc15dbc..e274ff6e1 100644 --- a/lib/openat-die.c +++ b/lib/openat-die.c @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if HAVE_CONFIG_H +#ifdef HAVE_CONFIG_H # include #endif diff --git a/lib/openat.c b/lib/openat.c index f7eb39d0e..929d26492 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -89,6 +89,8 @@ rpl_openat (int fd, char const *file, int flags, ...) return new_fd; } +#if !HAVE_FDOPENDIR + /* Replacement for Solaris' function by the same name. Simulate it by doing save_cwd/fchdir/opendir(".")/restore_cwd. @@ -100,7 +102,7 @@ rpl_openat (int fd, char const *file, int flags, ...) W A R N I N G: Unlike the other fd-related functions here, this one effectively consumes its FD parameter. The caller should not - close or otherwise manipulate FD after calling this function. */ + close or otherwise manipulate FD if this function returns successfully. */ DIR * fdopendir (int fd) { @@ -108,9 +110,6 @@ fdopendir (int fd) int saved_errno; DIR *dir; - if (fd == AT_FDCWD) - return opendir ("."); - if (save_cwd (&saved_cwd) != 0) openat_save_fail (errno); @@ -118,7 +117,6 @@ fdopendir (int fd) { saved_errno = errno; free_cwd (&saved_cwd); - close (fd); errno = saved_errno; return NULL; } @@ -130,12 +128,15 @@ fdopendir (int fd) openat_restore_fail (errno); free_cwd (&saved_cwd); - close (fd); + if (dir) + close (fd); errno = saved_errno; return dir; } +#endif + /* Replacement for Solaris' function by the same name. Simulate it by doing save_cwd/fchdir/(stat|lstat)/restore_cwd. diff --git a/lib/openat.h b/lib/openat.h index 5aa693c4d..4c2a2e0b7 100644 --- a/lib/openat.h +++ b/lib/openat.h @@ -46,7 +46,9 @@ # define __OPENAT_ID(y) __OPENAT_XCONCAT (__OPENAT_PREFIX, y) # define openat __OPENAT_ID (openat) int openat (int fd, char const *file, int flags, /* mode_t mode */ ...); -# define fdopendir __OPENAT_ID (fdopendir) +# if ! HAVE_FDOPENDIR +# define fdopendir __OPENAT_ID (fdopendir) +# endif DIR *fdopendir (int fd); # define fstatat __OPENAT_ID (fstatat) int fstatat (int fd, char const *file, struct stat *st, int flag); diff --git a/lib/settime.c b/lib/settime.c index 76bf70632..1d4098730 100644 --- a/lib/settime.c +++ b/lib/settime.c @@ -53,17 +53,15 @@ settime (struct timespec const *ts) #if HAVE_SETTIMEOFDAY { struct timeval tv; - int r; tv.tv_sec = ts->tv_sec; tv.tv_usec = ts->tv_nsec / 1000; - r = settimeofday (&tv, 0); - if (r == 0 || errno == EPERM) - return r; + return settimeofday (&tv, 0); } -#endif - -#if HAVE_STIME +#elif HAVE_STIME + /* This fails to compile on OSF1 V5.1, due to stime requiring + a `long int*' and tv_sec is `int'. But that system does provide + settimeofday. */ return stime (&ts->tv_sec); #else errno = ENOSYS; diff --git a/lib/utimens.c b/lib/utimens.c index b60ec879a..7f88f2fa9 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -26,6 +26,7 @@ #include #include +#include #if HAVE_UTIME_H # include @@ -113,11 +114,24 @@ futimens (int fd ATTRIBUTE_UNUSED, # endif #endif -#if ! HAVE_FUTIMES_AT +#if ! HAVE_FUTIMESAT if (!file) { +# if ! (HAVE_WORKING_UTIMES && HAVE_FUTIMES) errno = ENOSYS; +# endif + + /* Prefer EBADF to ENOSYS if both error numbers apply. */ + if (errno == ENOSYS) + { + int fd2 = dup (fd); + int dup_errno = errno; + if (0 <= fd2) + close (fd2); + errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS); + } + return -1; } diff --git a/m4/chdir-long.m4 b/m4/chdir-long.m4 index 9e9e35f98..0f22e382c 100644 --- a/m4/chdir-long.m4 +++ b/m4/chdir-long.m4 @@ -1,4 +1,4 @@ -#serial 5 +#serial 6 # Use Gnulib's robust chdir function. # It can handle arbitrarily long directory names, which means @@ -27,7 +27,7 @@ have_path_max_definition gl_have_path_max_definition=yes, gl_have_path_max_definition=no)]) - if test $gl_have_path_max_definition; then + if test $gl_have_path_max_definition = yes; then AC_LIBOBJ([chdir-long]) gl_PREREQ_CHDIR_LONG fi diff --git a/m4/openat.m4 b/m4/openat.m4 index 0f0156e95..15085c97f 100644 --- a/m4/openat.m4 +++ b/m4/openat.m4 @@ -1,4 +1,4 @@ -#serial 4 +#serial 6 # See if we need to use our replacement for Solaris' openat function. dnl Copyright (C) 2004, 2005 Free Software Foundation, Inc. @@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_OPENAT], AC_LIBSOURCES([openat.c, openat.h, openat-die.c]) AC_LIBOBJ([openat-die]) AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_CHECK_FUNCS_ONCE([fdopendir]) AC_REPLACE_FUNCS(openat) case $ac_cv_func_openat in yes) ;; diff --git a/m4/ullong_max.m4 b/m4/ullong_max.m4 index 49fc3402d..61fdce25e 100644 --- a/m4/ullong_max.m4 +++ b/m4/ullong_max.m4 @@ -11,36 +11,17 @@ AC_DEFUN([gl_ULLONG_MAX], [ dnl Avoid _AC_COMPUTE_INT-related macros, as they may not work with dnl types wider than long int, due to problems with expr. - AC_CACHE_CHECK([for ULLONG_MAX], gl_cv_ullong_max, - [gl_cv_ullong_max=no - AC_EGREP_CPP([ULLONG_MAX is defined], - [ - #include - #ifdef ULLONG_MAX - "ULLONG_MAX is defined" - #endif - ], - [gl_cv_ullong_max=yes]) - case $gl_cv_ullong_max in - no) - for gl_expr in \ - 18446744073709551615ULL \ - 4722366482869645213695ULL \ - 340282366920938463463374607431768211455ULL - do - AC_TRY_COMPILE([], - [char test[$gl_expr == (unsigned long long int) -1 ? 1 : -1]; - static unsigned long long int i = $gl_expr; - return i && test;], - [gl_cv_ullong_max=$gl_expr]) - test $gl_cv_ullong_max != no && break - done - esac]) - case $gl_cv_ullong_max in - yes | no) ;; - *) - AC_DEFINE_UNQUOTED([ULLONG_MAX], [$gl_cv_ullong_max], - [Define as the maximum value of the type 'unsigned long long int', - if the system doesn't define it, and if the system has that type.]);; - esac + AC_CACHE_CHECK([whether ULONG_MAX < ULLONG_MAX], + [gl_cv_ulong_max_lt_ullong_max], + [AC_COMPILE_IFELSE( + [AC_LANG_BOOL_COMPILE_TRY( + [AC_INCLUDES_DEFAULT], + [[(unsigned long int) -1 < (unsigned long long int) -1]])], + [gl_cv_ulong_max_lt_ullong_max=yes], + [gl_cv_ulong_max_lt_ullong_max=no])]) + if test $gl_cv_ulong_max_lt_ullong_max = yes; then + AC_DEFINE([ULONG_MAX_LT_ULLONG_MAX], 1, + [Define if ULONG_MAX < ULLONG_MAX, even if your compiler does not + support ULLONG_MAX.]) + fi ]) diff --git a/m4/utimes.m4 b/m4/utimes.m4 index ba74b3f6e..7efb2b026 100644 --- a/m4/utimes.m4 +++ b/m4/utimes.m4 @@ -12,6 +12,8 @@ dnl with or without modifications, as long as this notice is preserved. # Then, there was code to round rather than truncate. # Then, there was an implementation (sparc64, Linux-2.4.28, glibc-2.3.3) # that didn't honor the NULL-means-set-to-current-time semantics. +# Finally, there was also a version of utimes that failed on read-only +# files, while utime worked fine (linux-2.2.20, glibc-2.2.5). # # From Jim Meyering, with suggestions from Paul Eggert. @@ -23,6 +25,7 @@ AC_DEFUN([gl_FUNC_UTIMES], AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include +#include #include #include #include @@ -38,6 +41,7 @@ main () char const *file = "conftest.utimes"; FILE *f; time_t now; + int fd; int ok = ((f = fopen (file, "w")) && fclose (f) == 0 @@ -58,6 +62,13 @@ main () && now - sbuf.st_atime <= 2 && now - sbuf.st_mtime <= 2); unlink (file); + if (!ok) + exit (1); + + ok = (0 <= (fd = open (file, O_WRONLY|O_CREAT, 0444)) + && close (fd) == 0 + && utimes (file, NULL) == 0); + unlink (file); exit (!ok); }