1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

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.
This commit is contained in:
Samuel Thibault
2018-03-06 00:13:54 +01:00
parent bbe762d1e5
commit ec1300cfc8
7 changed files with 181 additions and 36 deletions

View File

@@ -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;
}