about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/utime-helper.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-03-06 00:13:54 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-03-06 00:14:26 +0100
commitec1300cfc83c716f33ee3231bba0a6e270abfc73 (patch)
tree739118fdbbe5f662bbc00f29d0b9566e6b3fef70 /sysdeps/mach/hurd/utime-helper.c
parentbbe762d1e596d7f5a1cd560a229387cb856916e0 (diff)
downloadglibc-ec1300cfc83c716f33ee3231bba0a6e270abfc73.tar.gz
glibc-ec1300cfc83c716f33ee3231bba0a6e270abfc73.tar.xz
glibc-ec1300cfc83c716f33ee3231bba0a6e270abfc73.zip
hurd: Add futimesat and utimensat support
	* sysdeps/mach/hurd/utime-helper.c (hurd_futimens): Rename function to
	hurd_futimes.
	* sysdeps/mach/hurd/utimes.c (__utimes): Update call accordingly.
	* sysdeps/mach/hurd/lutimes.c (__lutimes): Likewise.
	* sysdeps/mach/hurd/futimens.c: Include "utime-helper.c".
	(__futimens): Move implementation to...
	* sysdeps/mach/hurd/utime-helper.c (utime_ts_from_tspec,
	utime_tvalue_from_tspec): ... new helper functions.
	(hurd_futimens): New function.
	* sysdeps/mach/hurd/futimesat.c: New file.
	* sysdeps/mach/hurd/utimensat.c: New file.
Diffstat (limited to 'sysdeps/mach/hurd/utime-helper.c')
-rw-r--r--sysdeps/mach/hurd/utime-helper.c72
1 files changed, 71 insertions, 1 deletions
diff --git a/sysdeps/mach/hurd/utime-helper.c b/sysdeps/mach/hurd/utime-helper.c
index 357dfe9705..6aed3316a7 100644
--- a/sysdeps/mach/hurd/utime-helper.c
+++ b/sysdeps/mach/hurd/utime-helper.c
@@ -62,7 +62,7 @@ utime_tvalue_from_tval (const struct timeval tvp[2],
 
 /* Changes the access time of the file behind PORT using a timeval array.  */
 static inline error_t
-hurd_futimens (const file_t port, const struct timeval tvp[2])
+hurd_futimes (const file_t port, const struct timeval tvp[2])
 {
   error_t err;
   struct timespec atime, mtime;
@@ -82,3 +82,73 @@ hurd_futimens (const file_t port, const struct timeval tvp[2])
 
   return err;
 }
+
+/* Initializes atime/mtime timespec structures from an array of timespec.  */
+static inline void
+utime_ts_from_tspec (const struct timespec tsp[2],
+                     struct timespec *atime, struct timespec *mtime)
+{
+  if (tsp == NULL)
+    {
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
+         underlying filesystems to use the current time.  */
+      atime->tv_sec = 0;
+      atime->tv_nsec = UTIME_NOW;
+      mtime->tv_sec = 0;
+      mtime->tv_nsec = UTIME_NOW;
+    }
+  else
+    {
+      *atime = tsp[0];
+      *mtime = tsp[1];
+    }
+}
+
+/* Initializes atime/mtime time_value_t structures from an array of timespec.  */
+static inline void
+utime_tvalue_from_tspec (const struct timespec tsp[2],
+                         time_value_t *atime, time_value_t *mtime)
+{
+  if (tsp == NULL)
+    /* Setting the number of microseconds to `-1' tells the
+       underlying filesystems to use the current time.  */
+    atime->microseconds = mtime->microseconds = -1;
+  else
+    {
+      if (tsp[0].tv_nsec == UTIME_NOW)
+	atime->microseconds = -1;
+      else if (tsp[0].tv_nsec == UTIME_OMIT)
+	atime->microseconds = -2;
+      else
+	TIMESPEC_TO_TIME_VALUE (atime, &(tsp[0]));
+      if (tsp[1].tv_nsec == UTIME_NOW)
+	mtime->microseconds = -1;
+      else if (tsp[1].tv_nsec == UTIME_OMIT)
+	mtime->microseconds = -2;
+      else
+	TIMESPEC_TO_TIME_VALUE (mtime, &(tsp[1]));
+    }
+}
+
+/* Changes the access time of the file behind PORT using a timespec array.  */
+static inline error_t
+hurd_futimens (const file_t port, const struct timespec tsp[2])
+{
+  error_t err;
+  struct timespec atime, mtime;
+
+  utime_ts_from_tspec (tsp, &atime, &mtime);
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tspec (tsp, &atim, &mtim);
+
+      err = __file_utimes (port, atim, mtim);
+    }
+
+  return err;
+}