Sync from coreutils.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 2 Oct 2005 22:38:45 +0000 (22:38 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 2 Oct 2005 22:38:45 +0000 (22:38 +0000)
* 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 <config.h>.
* 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.

12 files changed:
lib/.cppi-disable
lib/.cvsignore
lib/fts-cycle.c
lib/openat-die.c
lib/openat.c
lib/openat.h
lib/settime.c
lib/utimens.c
m4/chdir-long.m4
m4/openat.m4
m4/ullong_max.m4
m4/utimes.m4

index 61a099cd7a96c397e848d8279beddff6eb5daec0..ce7e664460f70a66d0fed240be55137134e7fab8 100644 (file)
@@ -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
index 39cda9a1813715fa9d785fa6609d88c3f359e530..5afaa5942eb34d7854bc48b6e65a66a03ec3debe 100644 (file)
@@ -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
index 8c09fb94885c7e20e1353865b7deade9bac26a14..13b43dbdd13c97f2dd5fa23f0883702a432dae98 100644 (file)
    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
+
 #include "cycle-check.h"
 #include "hash.h"
 
index f7cc15dbcdc6487bd2ad9e0de763e3ec0b9f1f6b..e274ff6e1b0e4c9935fc91aabe162e45dc4d6e78 100644 (file)
@@ -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 <config.h>
 #endif
 
index f7eb39d0ec5035997692246a0b6e900e85a8062f..929d264924c4cf93fe38ec0031044ddc15099ec0 100644 (file)
@@ -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.
    <http://www.google.com/search?q=fdopendir+site:docs.sun.com>
    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.
    <http://www.google.com/search?q=fstatat+site:docs.sun.com>
    Simulate it by doing save_cwd/fchdir/(stat|lstat)/restore_cwd.
index 5aa693c4d437b230595c26a0b7cb3921e69fcbea..4c2a2e0b771fe07a568fbb923d5656e0cd6cb529 100644 (file)
@@ -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);
index 76bf7063250823cfd13a25d64a493ee52a587feb..1d40987305e4abf30b4a0d5819ed0614f5b7aa5b 100644 (file)
@@ -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;
index b60ec879a3a158c6820c42789bb43582e85ad926..7f88f2fa960cd63d14d7283ebfcd7546759d4457 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #if HAVE_UTIME_H
 # include <utime.h>
@@ -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;
     }
 
index 9e9e35f9824eacadcc4bc02e8b343f308a4c9117..0f22e382ca913be1c43f6de7f3e71c7620d41f4d 100644 (file)
@@ -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
index 0f0156e95245037dede31bc334c1ec6d98fba5f9..15085c97f967928196de396041bee9a788e24f4f 100644 (file)
@@ -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) ;;
index 49fc3402d4d9706117c2b53afe123b6f8821b304..61fdce25e28fbd7aaa2bf58cd2b16600e0c18407 100644 (file)
@@ -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 <limits.h>
-       #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
 ])
index ba74b3f6e3a4d6becd406df6eb20cdc6f4b67fd4..7efb2b026c9ddf2bf9b4075ff1672e299f24d7ec 100644 (file)
@@ -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 <sys/types.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include <sys/time.h>
 #include <time.h>
 #include <unistd.h>
@@ -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);
 }