]> Savannah Git Hosting - gnulib.git/commitdiff
copy-file: Preserve sub-second time stamps.
authorBruno Haible <bruno@clisp.org>
Mon, 1 May 2017 11:27:57 +0000 (13:27 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 1 May 2017 11:27:57 +0000 (13:27 +0200)
* lib/copy-file.c: Include stat-time.h, utimens.h instead of <utime.h>.
(qcopy_file_preserving): Use 'struct timespec' and utimens() to
transport the time stamps from the original file to the destination
file.
* m4/copy-file.m4 (gl_COPY_FILE): Don't test for utime, utimes.
* modules/copy-file (Depends-on): Add stat-time, utimns instead of
utime-h.

ChangeLog
lib/copy-file.c
m4/copy-file.m4
modules/copy-file

index d268b9e31cc4660c99c28c38d09e201b8d62f6bb..2712adde2686e90613890d7ff223947d3eba3e08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2017-05-01  Bruno Haible  <bruno@clisp.org>
+
+       copy-file: Preserve sub-second time stamps.
+       * lib/copy-file.c: Include stat-time.h, utimens.h instead of <utime.h>.
+       (qcopy_file_preserving): Use 'struct timespec' and utimens() to
+       transport the time stamps from the original file to the destination
+       file.
+       * m4/copy-file.m4 (gl_COPY_FILE): Don't test for utime, utimes.
+       * modules/copy-file (Depends-on): Add stat-time, utimns instead of
+       utime-h.
+
 2017-05-01  Bruno Haible  <bruno@clisp.org>
 
        wctype: Fix problems if <wchar.h> gets included after <wctype.h>.
index b3f02a759cdf9dcfc23136ed263ddcdde3aabd01..462ea1cfd49a179cb7b70c6b1878177183b782d9 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 
-#if HAVE_UTIME || HAVE_UTIMES
-# include <utime.h>
-#endif
-
 #include "error.h"
 #include "ignore-value.h"
 #include "safe-read.h"
 #include "full-write.h"
+#include "stat-time.h"
+#include "utimens.h"
 #include "acl.h"
 #include "binary-io.h"
 #include "quote.h"
@@ -113,23 +111,13 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
 #endif
 
   /* Preserve the access and modification times.  */
-#if HAVE_UTIME
-  {
-    struct utimbuf ut;
-
-    ut.actime = statbuf.st_atime;
-    ut.modtime = statbuf.st_mtime;
-    utime (dest_filename, &ut);
-  }
-#elif HAVE_UTIMES
   {
-    struct timeval ut[2];
+    struct timespec ts[2];
 
-    ut[0].tv_sec = statbuf.st_atime; ut[0].tv_usec = 0;
-    ut[1].tv_sec = statbuf.st_mtime; ut[1].tv_usec = 0;
-    utimes (dest_filename, &ut);
+    ts[0] = get_stat_atime (&statbuf);
+    ts[1] = get_stat_mtime (&statbuf);
+    utimens (dest_filename, ts);
   }
-#endif
 
 #if HAVE_CHOWN
   /* Preserve the owner and group.  */
index 4b5db8a9eee847c996599b830f135bee3d2fe34d..c29f7930a7a3e592e5acd66acc830184d21ae2c9 100644 (file)
@@ -1,4 +1,4 @@
-# copy-file.m4 serial 4
+# copy-file.m4 serial 5
 dnl Copyright (C) 2003, 2009-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,5 +7,5 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_COPY_FILE],
 [
   AC_CHECK_HEADERS_ONCE([unistd.h])
-  AC_CHECK_FUNCS([chown utime utimes])
+  AC_CHECK_FUNCS([chown])
 ])
index 7238f55f6e9b0d23c2faf8469f11587a28013412..e94a22ca3c1cb0584678ec5ead978248aa9b6a54 100644 (file)
@@ -17,9 +17,10 @@ ignore-value
 open
 quote
 safe-read
+stat-time
 stdlib
 unistd
-utime-h
+utimens
 xalloc
 
 configure.ac: