about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/utime-helper.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/utime-helper.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/utime-helper.c')
-rw-r--r--sysdeps/mach/hurd/utime-helper.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/utime-helper.c b/sysdeps/mach/hurd/utime-helper.c
new file mode 100644
index 0000000000..357dfe9705
--- /dev/null
+++ b/sysdeps/mach/hurd/utime-helper.c
@@ -0,0 +1,84 @@
+/* Helpers for utimes/utimens conversions.
+   Copyright (C) 2015-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 <errno.h>
+#include <hurd/hurd_types.h>
+#include <stddef.h>
+#include <sys/time.h>
+
+/* Initializes atime/mtime timespec structures from an array of timeval.  */
+static inline void
+utime_ts_from_tval (const struct timeval tvp[2],
+                    struct timespec *atime, struct timespec *mtime)
+{
+  if (tvp == 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
+    {
+      TIMEVAL_TO_TIMESPEC (&tvp[0], atime);
+      TIMEVAL_TO_TIMESPEC (&tvp[1], mtime);
+    }
+}
+
+/* Initializes atime/mtime time_value_t structures from an array of timeval.  */
+static inline void
+utime_tvalue_from_tval (const struct timeval tvp[2],
+                        time_value_t *atime, time_value_t *mtime)
+{
+  if (tvp == NULL)
+    /* Setting the number of microseconds to `-1' tells the
+       underlying filesystems to use the current time.  */
+    atime->microseconds = mtime->microseconds = -1;
+  else
+    {
+      atime->seconds = tvp[0].tv_sec;
+      atime->microseconds = tvp[0].tv_usec;
+      mtime->seconds = tvp[1].tv_sec;
+      mtime->microseconds = tvp[1].tv_usec;
+    }
+}
+
+/* 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])
+{
+  error_t err;
+  struct timespec atime, mtime;
+
+  utime_ts_from_tval (tvp, &atime, &mtime);
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tval (tvp, &atim, &mtim);
+
+      err = __file_utimes (port, atim, mtim);
+    }
+
+  return err;
+}