changeset 6322:716071856296

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 <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.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 02 Oct 2005 22:38:45 +0000
parents 2b9ecd9439d4
children af09cfa36fd5
files 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
diffstat 12 files changed, 76 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/lib/.cppi-disable
+++ b/lib/.cppi-disable
@@ -5,6 +5,9 @@
 fnmatch_.h
 fts.c
 fts_.h
+getaddrinfo.h
+getdelim.h
+getline.h
 getndelim2.h
 getopt.c
 getopt.h
@@ -12,8 +15,11 @@
 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.h
 stat-time.h
 stdbool_.h
+strcase.h
 strdup.h
 strndup.h
+strnlen.h
+strnlen1.h
 strtoul.c
 time_r.h
 utimecmp.h
--- 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
--- 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 <config.h>
+#endif
+
 #include "cycle-check.h"
 #include "hash.h"
 
--- 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 <config.h>
 #endif
 
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -89,6 +89,8 @@
   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 @@
    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 @@
   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 @@
     {
       saved_errno = errno;
       free_cwd (&saved_cwd);
-      close (fd);
       errno = saved_errno;
       return NULL;
     }
@@ -130,12 +128,15 @@
     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.
--- 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);
--- a/lib/settime.c
+++ b/lib/settime.c
@@ -53,17 +53,15 @@
 #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;
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -26,6 +26,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #if HAVE_UTIME_H
 # include <utime.h>
@@ -113,11 +114,24 @@
 # 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;
     }
 
--- 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 @@
     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
--- 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_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) ;;
--- a/m4/ullong_max.m4
+++ b/m4/ullong_max.m4
@@ -11,36 +11,17 @@
 [
   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
 ])
--- a/m4/utimes.m4
+++ b/m4/utimes.m4
@@ -12,6 +12,8 @@
 # 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_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 @@
   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 @@
      && 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);
 }