about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/futimens.c
diff options
context:
space:
mode:
authorFlávio Cruz <flaviocruz@gmail.com>2018-03-05 23:25:00 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-03-05 23:30:50 +0100
commitbbe762d1e596d7f5a1cd560a229387cb856916e0 (patch)
treec1414f343ce2148395308ab455353484b833f761 /sysdeps/mach/hurd/futimens.c
parenta1ede3a40249ea2efe54e182998bd8519e37a31e (diff)
downloadglibc-bbe762d1e596d7f5a1cd560a229387cb856916e0.tar.gz
glibc-bbe762d1e596d7f5a1cd560a229387cb856916e0.tar.xz
glibc-bbe762d1e596d7f5a1cd560a229387cb856916e0.zip
hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC
	* sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW,
	UTIME_OMIT): New macros.
	* sysdeps/mach/hurd/futimens.c (__futimens): Try to use __file_utimens
	before reverting to converting time spec to time value and calling
	__file_utimes.
	* sysdeps/mach/hurd/utime-helper.c: New file.
	* sysdeps/mach/hurd/futimes.c: Include "utime-helper.c".
	(__futimes): Try to use utime_ts_from_tval and __file_utimens before
	reverting to utime_tvalue_from_tval and __file_utimes.
	* sysdeps/mach/hurd/lutimes.c: Include "utime-helper.c".
	(__lutimes): Just call hurd_futimens after lookup.
	* sysdeps/mach/hurd/utimes.c: Likewise.
Diffstat (limited to 'sysdeps/mach/hurd/futimens.c')
-rw-r--r--sysdeps/mach/hurd/futimens.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c
index 44ba7f15f1..4a8b0f7fa4 100644
--- a/sysdeps/mach/hurd/futimens.c
+++ b/sysdeps/mach/hurd/futimens.c
@@ -27,24 +27,53 @@
 int
 __futimens (int fd, const struct timespec tsp[2])
 {
-  time_value_t atime, mtime;
+  struct timespec atime, mtime;
   error_t err;
 
   if (tsp == NULL)
     {
-      /* Setting the number of microseconds to `-1' tells the
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      atime.microseconds = mtime.microseconds = -1;
+      atime.tv_sec = 0;
+      atime.tv_nsec = UTIME_NOW;
+      mtime.tv_sec = 0;
+      mtime.tv_nsec = UTIME_NOW;
     }
   else
     {
-      atime.seconds = tsp[0].tv_sec;
-      atime.microseconds = tsp[0].tv_nsec / 1000;
-      mtime.seconds = tsp[1].tv_sec;
-      mtime.microseconds = tsp[1].tv_nsec / 1000;
+      atime = tsp[0];
+      mtime = tsp[1];
     }
 
-  err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime));
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tsp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else
+        {
+          if (tsp[0].tv_nsec == UTIME_NOW)
+            atim.microseconds = -1;
+          else if (tsp[0].tv_nsec == UTIME_OMIT)
+            atim.microseconds = -2;
+          else
+            TIMESPEC_TO_TIME_VALUE (&atim, &(tsp[0]));
+          if (tsp[1].tv_nsec == UTIME_NOW)
+            mtim.microseconds = -1;
+          else if (tsp[1].tv_nsec == UTIME_OMIT)
+            mtim.microseconds = -2;
+          else
+            TIMESPEC_TO_TIME_VALUE (&mtim, &(tsp[1]));
+        }
+
+      err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
+  }
+
   return err ? __hurd_dfail (fd, err) : 0;
 }
 weak_alias (__futimens, futimens)