bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

utimens and non-standardized futimesat [was: coreutils-6.11-1 in release


From: Eric Blake
Subject: utimens and non-standardized futimesat [was: coreutils-6.11-1 in release-2 area]
Date: Wed, 28 May 2008 21:49:48 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080421 Thunderbird/2.0.0.14 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 5/22/2008 6:51 AM:
| According to Jim Meyering on 5/22/2008 6:42 AM:
| |> |> No need to refer the dir by name:
| |> |>
| |> |>   futimens (dirfd. timespec);
| |> |
| |> | Btw., even if you don't consider the Posix 200x functions
| |> | futimens/utimensat, you don't need futimsat(dirfd, NULL, timeval):
| |> |
| |> |     futimes (dirfd, timeval);
| |> |
| |> | So, actually I think that using futimesat this way is a gratuitous
| |> | utilization of a glibc extension.
| |>
| |
| | Thanks for the write-up.
| | That sounds like the right way to go.
| | Do you feel like doing it?
|
| Yes, I'll be tackling this.
|

Tested on cygwin 1.7.0, where futimens and utimensat exist, and on cygwin
1.5.25, where those and futimesat are all missing.  OK to apply?  This
means that coreutils can now support nanosecond resolution on new enough
kernels for things like touch and cp -p.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg+J9wACgkQ84KuGfSFAYClKACeP+2if8mjgTGXIh9+Ox2j9ML1
gjgAoJKelMw7XPHmvb/672wpuJt8DDEb
=AjZ8
-----END PGP SIGNATURE-----
>From 3a7020399aa6a2847755e25f4803baa93e4a421d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 28 May 2008 21:29:02 -0600
Subject: [PATCH] Prefer new POSIX 200x interfaces over futimesat.

* m4/utimens.m4 (gl_UTIMENS): Check for futimens, utimensat.
* lib/utimens.c (gl_futimens): Use them for nanosecond resolution
when available.
[HAVE_BUGGY_NFS_TIME_STAMPS]: Allow C89 compilation.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog     |    8 ++++++++
 lib/utimens.c |   20 +++++++++++++++++---
 m4/utimens.m4 |    7 +++++--
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9644194..b32df35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-28  Eric Blake  <address@hidden>
+
+       Prefer new POSIX 200x interfaces over futimesat.
+       * m4/utimens.m4 (gl_UTIMENS): Check for futimens, utimensat.
+       * lib/utimens.c (gl_futimens): Use them for nanosecond resolution
+       when available.
+       [HAVE_BUGGY_NFS_TIME_STAMPS]: Allow C89 compilation.
+
 2008-05-28  Bruno Haible  <address@hidden>
 
        * modules/stpcpy (License): Change to LGPLv2+.
diff --git a/lib/utimens.c b/lib/utimens.c
index e128219..db53d6f 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -26,6 +26,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <unistd.h>
 
@@ -77,6 +78,11 @@ int
 gl_futimens (int fd ATTRIBUTE_UNUSED,
             char const *file, struct timespec const timespec[2])
 {
+#if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES
+  struct timeval timeval[2];
+  struct timeval const *t;
+#endif
+
   /* Some Linux-based NFS clients are buggy, and mishandle time stamps
      of files in NFS file systems in some cases.  We have no
      configure-time test for this, but please see
@@ -94,12 +100,20 @@ gl_futimens (int fd ATTRIBUTE_UNUSED,
     fsync (fd);
 #endif
 
-  /* There's currently no interface to set file timestamps with
+  /* POSIX 200x added two interfaces to set file timestamps with
+     nanosecond resolution.  */
+#if HAVE_UTIMENSAT
+  if (fd < 0)
+    return utimensat (AT_FDCWD, file, timespec, 0);
+#endif
+#if HAVE_FUTIMENS
+  return futimens (fd, timespec);
+#endif
+
+  /* The platform lacks an interface to set file timestamps with
      nanosecond resolution, so do the best we can, discarding any
      fractional part of the timestamp.  */
 #if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES
-  struct timeval timeval[2];
-  struct timeval const *t;
   if (timespec)
     {
       timeval[0].tv_sec = timespec[0].tv_sec;
diff --git a/m4/utimens.m4 b/m4/utimens.m4
index 9ac9c3e..01a3184 100644
--- a/m4/utimens.m4
+++ b/m4/utimens.m4
@@ -1,8 +1,11 @@
-dnl Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+dnl Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software
+dnl Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
+dnl serial 2
+
 AC_DEFUN([gl_UTIMENS],
 [
   AC_LIBOBJ([utimens])
@@ -11,5 +14,5 @@ AC_DEFUN([gl_UTIMENS],
   AC_REQUIRE([gl_FUNC_UTIMES])
   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
-  AC_CHECK_FUNCS_ONCE([futimes futimesat])
+  AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat])
 ])
-- 
1.5.5.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]