|
Packit |
6c4009 |
/* Helpers for utimes/utimens conversions.
|
|
Packit |
6c4009 |
Copyright (C) 2015-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <hurd/hurd_types.h>
|
|
Packit |
6c4009 |
#include <stddef.h>
|
|
Packit |
6c4009 |
#include <sys/time.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Initializes atime/mtime timespec structures from an array of timeval. */
|
|
Packit |
6c4009 |
static inline void
|
|
Packit |
6c4009 |
utime_ts_from_tval (const struct timeval tvp[2],
|
|
Packit |
6c4009 |
struct timespec *atime, struct timespec *mtime)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (tvp == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Setting the number of nanoseconds to UTIME_NOW tells the
|
|
Packit |
6c4009 |
underlying filesystems to use the current time. */
|
|
Packit |
6c4009 |
atime->tv_sec = 0;
|
|
Packit |
6c4009 |
atime->tv_nsec = UTIME_NOW;
|
|
Packit |
6c4009 |
mtime->tv_sec = 0;
|
|
Packit |
6c4009 |
mtime->tv_nsec = UTIME_NOW;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
TIMEVAL_TO_TIMESPEC (&tvp[0], atime);
|
|
Packit |
6c4009 |
TIMEVAL_TO_TIMESPEC (&tvp[1], mtime);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Initializes atime/mtime time_value_t structures from an array of timeval. */
|
|
Packit |
6c4009 |
static inline void
|
|
Packit |
6c4009 |
utime_tvalue_from_tval (const struct timeval tvp[2],
|
|
Packit |
6c4009 |
time_value_t *atime, time_value_t *mtime)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (tvp == NULL)
|
|
Packit |
6c4009 |
/* Setting the number of microseconds to `-1' tells the
|
|
Packit |
6c4009 |
underlying filesystems to use the current time. */
|
|
Packit |
6c4009 |
atime->microseconds = mtime->microseconds = -1;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
atime->seconds = tvp[0].tv_sec;
|
|
Packit |
6c4009 |
atime->microseconds = tvp[0].tv_usec;
|
|
Packit |
6c4009 |
mtime->seconds = tvp[1].tv_sec;
|
|
Packit |
6c4009 |
mtime->microseconds = tvp[1].tv_usec;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Changes the access time of the file behind PORT using a timeval array. */
|
|
Packit |
6c4009 |
static inline error_t
|
|
Packit |
6c4009 |
hurd_futimes (const file_t port, const struct timeval tvp[2])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
error_t err;
|
|
Packit |
6c4009 |
struct timespec atime, mtime;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
utime_ts_from_tval (tvp, &atime, &mtime);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = __file_utimens (port, atime, mtime);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (err == MIG_BAD_ID || err == EOPNOTSUPP)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
time_value_t atim, mtim;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
utime_tvalue_from_tval (tvp, &atim, &mtim);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = __file_utimes (port, atim, mtim);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return err;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Initializes atime/mtime timespec structures from an array of timespec. */
|
|
Packit |
6c4009 |
static inline void
|
|
Packit |
6c4009 |
utime_ts_from_tspec (const struct timespec tsp[2],
|
|
Packit |
6c4009 |
struct timespec *atime, struct timespec *mtime)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (tsp == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Setting the number of nanoseconds to UTIME_NOW tells the
|
|
Packit |
6c4009 |
underlying filesystems to use the current time. */
|
|
Packit |
6c4009 |
atime->tv_sec = 0;
|
|
Packit |
6c4009 |
atime->tv_nsec = UTIME_NOW;
|
|
Packit |
6c4009 |
mtime->tv_sec = 0;
|
|
Packit |
6c4009 |
mtime->tv_nsec = UTIME_NOW;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
*atime = tsp[0];
|
|
Packit |
6c4009 |
*mtime = tsp[1];
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Initializes atime/mtime time_value_t structures from an array of timespec. */
|
|
Packit |
6c4009 |
static inline void
|
|
Packit |
6c4009 |
utime_tvalue_from_tspec (const struct timespec tsp[2],
|
|
Packit |
6c4009 |
time_value_t *atime, time_value_t *mtime)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (tsp == NULL)
|
|
Packit |
6c4009 |
/* Setting the number of microseconds to `-1' tells the
|
|
Packit |
6c4009 |
underlying filesystems to use the current time. */
|
|
Packit |
6c4009 |
atime->microseconds = mtime->microseconds = -1;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (tsp[0].tv_nsec == UTIME_NOW)
|
|
Packit |
6c4009 |
atime->microseconds = -1;
|
|
Packit |
6c4009 |
else if (tsp[0].tv_nsec == UTIME_OMIT)
|
|
Packit |
6c4009 |
atime->microseconds = -2;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
TIMESPEC_TO_TIME_VALUE (atime, &(tsp[0]));
|
|
Packit |
6c4009 |
if (tsp[1].tv_nsec == UTIME_NOW)
|
|
Packit |
6c4009 |
mtime->microseconds = -1;
|
|
Packit |
6c4009 |
else if (tsp[1].tv_nsec == UTIME_OMIT)
|
|
Packit |
6c4009 |
mtime->microseconds = -2;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
TIMESPEC_TO_TIME_VALUE (mtime, &(tsp[1]));
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Changes the access time of the file behind PORT using a timespec array. */
|
|
Packit |
6c4009 |
static inline error_t
|
|
Packit |
6c4009 |
hurd_futimens (const file_t port, const struct timespec tsp[2])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
error_t err;
|
|
Packit |
6c4009 |
struct timespec atime, mtime;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
utime_ts_from_tspec (tsp, &atime, &mtime);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = __file_utimens (port, atime, mtime);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (err == MIG_BAD_ID || err == EOPNOTSUPP)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
time_value_t atim, mtim;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
utime_tvalue_from_tspec (tsp, &atim, &mtim);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = __file_utimes (port, atim, mtim);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return err;
|
|
Packit |
6c4009 |
}
|