2018-03-05 22:25:00 +00:00
|
|
|
/* Helpers for utimes/utimens conversions.
|
2021-01-02 19:32:25 +00:00
|
|
|
Copyright (C) 2015-2021 Free Software Foundation, Inc.
|
2018-03-05 22:25:00 +00:00
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2018-03-05 22:25:00 +00:00
|
|
|
|
|
|
|
#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
|
2018-03-05 23:13:54 +00:00
|
|
|
hurd_futimes (const file_t port, const struct timeval tvp[2])
|
2018-03-05 22:25:00 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2018-03-05 23:13:54 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|