]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
add support for setting timestamps with ns resolution. utimensat and
authorBjörn Jacke <bjacke@gmail.com>
Fri, 6 Nov 2009 11:42:45 +0000 (06:42 -0500)
committerBjörn Jacke <bjacke@gmail.com>
Fri, 6 Nov 2009 11:42:45 +0000 (06:42 -0500)
futimens are defined in POSIX.1-2008. They are available on Linux since
glibc 2.6 and kernel 2.6.22.

SVN-Revision: 1583

CMakeLists.txt
configure.ac
libarchive/archive_write_disk.c

index d549c128804be7935787ba753dbbc96380dfe094..fed6ac40228001239b44108d6d6478b2077b1989 100644 (file)
@@ -381,6 +381,8 @@ CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET)
 CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV)
 CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME)
 CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES)
+CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS)
+CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT)
 CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK)
 CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB)
 CHECK_FUNCTION_EXISTS_GLIBC(wcscpy HAVE_WCSCPY)
index 21b3a7215dd5783b7d545109bbaf6da077c20585..d1084c65ce436e94b04705f384b6c383cba6f223 100644 (file)
@@ -355,7 +355,7 @@ AC_CHECK_FUNCS([lchflags lchmod lchown link lstat])
 AC_CHECK_FUNCS([lutimes memmove memset mkdir mkfifo mknod])
 AC_CHECK_FUNCS([nl_langinfo pipe poll readlink select setenv setlocale])
 AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])
-AC_CHECK_FUNCS([tzset unsetenv utime utimes vfork])
+AC_CHECK_FUNCS([tzset unsetenv utime futimens utimensat utimes vfork])
 AC_CHECK_FUNCS([wcrtomb wcscpy wcslen wctomb wmemcmp wmemcpy])
 # detects cygwin-1.7, as opposed to older versions
 AC_CHECK_FUNCS([cygwin_conv_path])
index 36853370e007c4503cfce89f9292c26bb16b689a..7722196579ae48ac9100788595363412bd3a050a 100644 (file)
@@ -1829,11 +1829,31 @@ set_ownership(struct archive_write_disk *a)
        return (ARCHIVE_WARN);
 }
 
-#ifdef HAVE_UTIMES
+
+#if defined(HAVE_UTIMENSAT) && defined(HAVE_FUTIMENS)
+/* 
+ * utimensat() and futimens() are defined in POSIX.1-2008. They provide ns
+ * resolution and setting times on fd and on symlinks, too.
+ */
+static int
+set_time(int fd, int mode, const char *name,
+    time_t atime, long atime_nsec,
+    time_t mtime, long mtime_nsec)
+{
+       struct timespec ts[2];
+       ts[0].tv_sec = atime;
+       ts[0].tv_nsec = atime_nsec;
+       ts[1].tv_sec = mtime;
+       ts[1].tv_nsec = mtime_nsec;
+       if (fd >= 0)
+               return futimens(fd, ts);
+       return utimensat(AT_FDCWD, name, ts, AT_SYMLINK_NOFOLLOW);
+}
+#elif HAVE_UTIMES
 /*
- * The utimes()-family functions provide high resolution and
+ * The utimes()-family functions provide µs-resolution and
  * a way to set time on an fd or a symlink.  We prefer them
- * when they're available.
+ * when they're available and utimensat/futimens aren't there.
  */
 static int
 set_time(int fd, int mode, const char *name,