summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--sysdeps/mach/hurd/futimens.c37
-rw-r--r--sysdeps/mach/hurd/futimesat.c44
-rw-r--r--sysdeps/mach/hurd/lutimes.c2
-rw-r--r--sysdeps/mach/hurd/utime-helper.c72
-rw-r--r--sysdeps/mach/hurd/utimensat.c46
-rw-r--r--sysdeps/mach/hurd/utimes.c2
7 files changed, 181 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 989881e972..27ca1dcbfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2018-03-05  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+	* 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.
+
 2018-03-05  Flávio Cruz  <flaviocruz@gmail.com>
 
 	* sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW,
diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c
index 4a8b0f7fa4..4a3943e673 100644
--- a/sysdeps/mach/hurd/futimens.c
+++ b/sysdeps/mach/hurd/futimens.c
@@ -22,6 +22,8 @@
 #include <hurd.h>
 #include <hurd/fd.h>
 
+#include "utime-helper.c"
+
 /* Change the access time of FD to TSP[0] and
    the modification time of FD to TSP[1].  */
 int
@@ -30,20 +32,7 @@ __futimens (int fd, const struct timespec tsp[2])
   struct timespec atime, mtime;
   error_t err;
 
-  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];
-    }
+  utime_ts_from_tspec (tsp, &atime, &mtime);
 
   err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
 
@@ -51,25 +40,7 @@ __futimens (int fd, const struct timespec tsp[2])
     {
       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]));
-        }
+      utime_tvalue_from_tspec (tsp, &atim, &mtim);
 
       err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
   }
diff --git a/sysdeps/mach/hurd/futimesat.c b/sysdeps/mach/hurd/futimesat.c
new file mode 100644
index 0000000000..99c4c63633
--- /dev/null
+++ b/sysdeps/mach/hurd/futimesat.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stddef.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+
+#include "utime-helper.c"
+
+/* Change the access time of FILE relative to FD to TVP[0] and
+   the modification time of FILE to TVP[1].  */
+int
+futimesat (int fd, const char *file, const struct timeval tvp[2])
+{
+  error_t err;
+  file_t port;
+
+  port = __file_name_lookup_at (fd, 0, file, 0, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
+  err = hurd_futimes (port, tvp);
+
+  __mach_port_deallocate (__mach_task_self (), port);
+  if (err)
+    return __hurd_fail (err);
+  return 0;
+}
diff --git a/sysdeps/mach/hurd/lutimes.c b/sysdeps/mach/hurd/lutimes.c
index 23b00c1739..375ab3feb3 100644
--- a/sysdeps/mach/hurd/lutimes.c
+++ b/sysdeps/mach/hurd/lutimes.c
@@ -36,7 +36,7 @@ __lutimes (const char *file, const struct timeval tvp[2])
   if (port == MACH_PORT_NULL)
     return -1;
 
-  err = hurd_futimens (port, tvp);
+  err = hurd_futimes (port, tvp);
 
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
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;
+}
diff --git a/sysdeps/mach/hurd/utimensat.c b/sysdeps/mach/hurd/utimensat.c
new file mode 100644
index 0000000000..ac9bc534c8
--- /dev/null
+++ b/sysdeps/mach/hurd/utimensat.c
@@ -0,0 +1,46 @@
+/* Change access and modification times of open file.  Hurd version.
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stddef.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+
+#include "utime-helper.c"
+
+/* Change the access time of FILE to TSP[0] and
+   the modification time of FILE to TSP[1].  */
+int
+utimensat (int fd, const char *file, const struct timespec tsp[2],
+	   int flags)
+{
+  error_t err;
+  file_t port;
+
+  port = __file_name_lookup_at (fd, flags, file, 0, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
+  err = hurd_futimens (port, tsp);
+
+  __mach_port_deallocate (__mach_task_self (), port);
+  if (err)
+    return __hurd_fail (err);
+  return 0;
+}
diff --git a/sysdeps/mach/hurd/utimes.c b/sysdeps/mach/hurd/utimes.c
index 25e47539fe..fa8a79239b 100644
--- a/sysdeps/mach/hurd/utimes.c
+++ b/sysdeps/mach/hurd/utimes.c
@@ -34,7 +34,7 @@ __utimes (const char *file, const struct timeval tvp[2])
   if (port == MACH_PORT_NULL)
     return -1;
 
-  err = hurd_futimens (port, tvp);
+  err = hurd_futimes (port, tvp);
 
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)