2012-06-22 21:26:37 +00:00
|
|
|
/* stat-related time functions.
|
|
|
|
|
2019-01-01 00:59:58 +00:00
|
|
|
Copyright (C) 2005, 2007, 2009-2019 Free Software Foundation, Inc.
|
2012-06-22 21:26:37 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2017-09-13 09:07:03 +00:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2012-06-22 21:26:37 +00:00
|
|
|
|
|
|
|
/* Written by Paul Eggert. */
|
|
|
|
|
|
|
|
#ifndef STAT_TIME_H
|
|
|
|
#define STAT_TIME_H 1
|
|
|
|
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
#include "intprops.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
2012-06-22 21:26:37 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2013-09-19 21:40:08 +00:00
|
|
|
#ifndef _GL_INLINE_HEADER_BEGIN
|
|
|
|
#error "Please include config.h first."
|
|
|
|
#endif
|
2012-08-02 04:46:10 +00:00
|
|
|
_GL_INLINE_HEADER_BEGIN
|
|
|
|
#ifndef _GL_STAT_TIME_INLINE
|
|
|
|
# define _GL_STAT_TIME_INLINE _GL_INLINE
|
|
|
|
#endif
|
|
|
|
|
2017-03-19 20:07:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-06-22 21:26:37 +00:00
|
|
|
/* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
|
|
|
|
struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
|
|
|
|
ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
|
|
|
|
if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
|
|
|
|
for access, status change, data modification, or birth (creation)
|
|
|
|
time respectively.
|
|
|
|
|
|
|
|
These macros are private to stat-time.h. */
|
Merge from gnulib
This incorporates:
2017-05-13 largefile: Simplify
2017-05-13 largefile: Improve and document
2017-05-13 truncate: New module
2017-05-13 windows-stat-timespec: New module
2017-05-13 windows-stat-override: New module
2017-05-11 getopt-posix: port to mingw
2017-05-11 gettimeofday: Increase precision on mingw
2017-05-10 time: Fix missing initialization of HAVE_TIMEZONE_T
2017-05-10 Implement a way to opt out from MSVC support
2017-05-09 tzset: Expand comment about TZ problem on native Windows
* build-aux/config.guess, lib/dup2.c, lib/fcntl.c, lib/fsync.c:
* lib/getdtablesize.c, lib/getopt.c, lib/gettimeofday.c:
* lib/mktime.c, lib/stat-time.h, lib/sys_stat.in.h, lib/unistd.in.h:
* lib/utimens.c, m4/gettimeofday.m4, m4/largefile.m4:
* m4/sys_stat_h.m4, m4/sys_time_h.m4, m4/time_h.m4, m4/time_rz.m4:
* m4/unistd_h.m4: Copy from gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
2017-05-14 08:29:05 +00:00
|
|
|
#if _GL_WINDOWS_STAT_TIMESPEC || defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
|
|
|
|
# if _GL_WINDOWS_STAT_TIMESPEC || defined TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
|
2012-06-22 21:26:37 +00:00
|
|
|
# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
|
|
|
|
# else
|
|
|
|
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
|
|
|
|
# endif
|
|
|
|
#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
|
|
|
|
# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
|
|
|
|
#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
|
|
|
|
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
|
|
|
|
#elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
|
|
|
|
# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return the nanosecond component of *ST's access time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_atime_ns (struct stat const *st)
|
|
|
|
{
|
|
|
|
# if defined STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_atim).tv_nsec;
|
|
|
|
# elif defined STAT_TIMESPEC_NS
|
|
|
|
return STAT_TIMESPEC_NS (st, st_atim);
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the nanosecond component of *ST's status change time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_ctime_ns (struct stat const *st)
|
|
|
|
{
|
|
|
|
# if defined STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_ctim).tv_nsec;
|
|
|
|
# elif defined STAT_TIMESPEC_NS
|
|
|
|
return STAT_TIMESPEC_NS (st, st_ctim);
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the nanosecond component of *ST's data modification time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_mtime_ns (struct stat const *st)
|
|
|
|
{
|
|
|
|
# if defined STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_mtim).tv_nsec;
|
|
|
|
# elif defined STAT_TIMESPEC_NS
|
|
|
|
return STAT_TIMESPEC_NS (st, st_mtim);
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the nanosecond component of *ST's birth time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
|
Merge from Gnulib
This incorporates:
2018-01-05 maint: Add encoding marker for Emacs to non-ASCII sources
2018-01-04 update-copyright: Handle use of ©
2018-01-04 pthread_sigmask: Avoid compilation error on mingw
2018-01-02 stat-time: silence -Wunused-parameter regression
* build-aux/config.guess, build-aux/config.sub:
* build-aux/update-copyright, doc/misc/texinfo.tex, lib/gnulib.mk.in:
* lib/md5.c, lib/md5.h, lib/sha1.c, lib/sha1.h, lib/sha256.c:
* lib/sha256.h, lib/sha512.c, lib/sha512.h, lib/signal.in.h:
* lib/stat-time.h: Copy from Gnulib, or regenerate.
2018-01-09 23:21:44 +00:00
|
|
|
get_stat_birthtime_ns (struct stat const *st _GL_UNUSED)
|
2012-06-22 21:26:37 +00:00
|
|
|
{
|
|
|
|
# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
|
|
|
|
return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
|
|
|
|
# elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
|
|
|
|
return STAT_TIMESPEC_NS (st, st_birthtim);
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return *ST's access time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_atime (struct stat const *st)
|
|
|
|
{
|
|
|
|
#ifdef STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_atim);
|
|
|
|
#else
|
|
|
|
struct timespec t;
|
|
|
|
t.tv_sec = st->st_atime;
|
|
|
|
t.tv_nsec = get_stat_atime_ns (st);
|
|
|
|
return t;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return *ST's status change time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_ctime (struct stat const *st)
|
|
|
|
{
|
|
|
|
#ifdef STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_ctim);
|
|
|
|
#else
|
|
|
|
struct timespec t;
|
|
|
|
t.tv_sec = st->st_ctime;
|
|
|
|
t.tv_nsec = get_stat_ctime_ns (st);
|
|
|
|
return t;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return *ST's data modification time. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
2012-06-22 21:26:37 +00:00
|
|
|
get_stat_mtime (struct stat const *st)
|
|
|
|
{
|
|
|
|
#ifdef STAT_TIMESPEC
|
|
|
|
return STAT_TIMESPEC (st, st_mtim);
|
|
|
|
#else
|
|
|
|
struct timespec t;
|
|
|
|
t.tv_sec = st->st_mtime;
|
|
|
|
t.tv_nsec = get_stat_mtime_ns (st);
|
|
|
|
return t;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return *ST's birth time, if available; otherwise return a value
|
|
|
|
with tv_sec and tv_nsec both equal to -1. */
|
2014-12-12 07:16:37 +00:00
|
|
|
_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
|
Merge from Gnulib
This incorporates:
2018-01-05 maint: Add encoding marker for Emacs to non-ASCII sources
2018-01-04 update-copyright: Handle use of ©
2018-01-04 pthread_sigmask: Avoid compilation error on mingw
2018-01-02 stat-time: silence -Wunused-parameter regression
* build-aux/config.guess, build-aux/config.sub:
* build-aux/update-copyright, doc/misc/texinfo.tex, lib/gnulib.mk.in:
* lib/md5.c, lib/md5.h, lib/sha1.c, lib/sha1.h, lib/sha256.c:
* lib/sha256.h, lib/sha512.c, lib/sha512.h, lib/signal.in.h:
* lib/stat-time.h: Copy from Gnulib, or regenerate.
2018-01-09 23:21:44 +00:00
|
|
|
get_stat_birthtime (struct stat const *st _GL_UNUSED)
|
2012-06-22 21:26:37 +00:00
|
|
|
{
|
|
|
|
struct timespec t;
|
|
|
|
|
|
|
|
#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
|
|
|
|
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
|
|
|
|
t = STAT_TIMESPEC (st, st_birthtim);
|
|
|
|
#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
|
|
|
|
t.tv_sec = st->st_birthtime;
|
|
|
|
t.tv_nsec = st->st_birthtimensec;
|
Update from Gnulib
This incorporates:
2018-05-21 crypto: omit stream ops Emacs doesn’t need
2018-05-13 truncate: Fix compilation error on Android
2018-05-13 imaxdiv: Fix compilation error on Android
2018-05-13 Support selective inclusion of recent mingw.org headers
2018-05-13 Add cross-compilation guesses for Linux systems sans glibc
2018-05-13 stdioext: Fix compilation errors with newer Android headers
2018-05-07 af_alg: Pacify --enable-gcc-warnings
2018-05-06 af_alg: Fix bug with streams that are not at position 0
2018-05-06 Followup to 'af_alg: New module'
2018-05-05 crypto/{md5,sha1,sha256,sha512}: simplify
2018-05-05 af_alg: New module
2018-05-05 af_alg: Improve function signature
2018-04-28 md5sum: Use AF_ALG when available
2018-04-28 sha512sum: Use AF_ALG when available
2018-04-28 sha256sum: Use AF_ALG when available
2018-04-28 sha1sum: Use AF_ALG when available
2018-05-05 all: Replace more http URLs by https URLs
2018-05-03 maint: port more modules to GCC 8
2018-05-03 Simplify code; drop support for Borland C++ on Windows
* admin/merge-gnulib (GNULIB_MODULES): Use crypto/md5-buffer
rather than crypto/md5, since Emacs doesn’t use the stream
operations that in recent Gnulib pull in other stuff Emacs doesn’t
need. Similarly for crypto/sha1-buffer, crypto/sha256-buffer,
crypto/sha512-buffer.
* build-aux/config.guess, build-aux/config.sub, lib/dosname.h:
* lib/dup2.c, lib/errno.in.h, lib/euidaccess.c, lib/fcntl.c:
* lib/fcntl.in.h, lib/fpending.c, lib/fsync.c, lib/getdtablesize.c:
* lib/getopt.c, lib/gettimeofday.c, lib/inttypes.in.h, lib/md5.c:
* lib/md5.h, lib/open.c, lib/pipe2.c, lib/putenv.c, lib/sha1.c:
* lib/sha1.h, lib/sha256.c, lib/sha256.h, lib/sha512.c:
* lib/sha512.h, lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/stdlib.in.h, lib/sys_stat.in.h, lib/sys_types.in.h:
* lib/timespec.h, lib/unistd.in.h, lib/utimens.c, m4/c-strtod.m4:
* m4/gnulib-common.m4, m4/inttypes.m4, m4/lstat.m4, m4/nocrash.m4:
* m4/pselect.m4, m4/readlink.m4, m4/stdio_h.m4, m4/symlink.m4:
* m4/unistd_h.m4, m4/utimens.m4:
Copy from Gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
2018-05-21 18:42:18 +00:00
|
|
|
#elif defined _WIN32 && ! defined __CYGWIN__
|
2012-06-22 21:26:37 +00:00
|
|
|
/* Native Windows platforms (but not Cygwin) put the "file creation
|
|
|
|
time" in st_ctime (!). See
|
2017-04-27 22:21:34 +00:00
|
|
|
<https://msdn.microsoft.com/en-us/library/14h5k7ff(VS.80).aspx>. */
|
2017-05-14 19:39:26 +00:00
|
|
|
# if _GL_WINDOWS_STAT_TIMESPEC
|
|
|
|
t = st->st_ctim;
|
|
|
|
# else
|
2012-06-22 21:26:37 +00:00
|
|
|
t.tv_sec = st->st_ctime;
|
|
|
|
t.tv_nsec = 0;
|
2017-05-14 19:39:26 +00:00
|
|
|
# endif
|
2012-06-22 21:26:37 +00:00
|
|
|
#else
|
|
|
|
/* Birth time is not supported. */
|
|
|
|
t.tv_sec = -1;
|
|
|
|
t.tv_nsec = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
|
|
|
|
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
|
|
|
|
|| defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
|
|
|
|
/* FreeBSD and NetBSD sometimes signal the absence of knowledge by
|
|
|
|
using zero. Attempt to work around this problem. Alas, this can
|
2017-01-10 15:48:37 +00:00
|
|
|
report failure even for valid timestamps. Also, NetBSD
|
2012-06-22 21:26:37 +00:00
|
|
|
sometimes returns junk in the birth time fields; work around this
|
|
|
|
bug if it is detected. */
|
|
|
|
if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
|
|
|
|
{
|
|
|
|
t.tv_sec = -1;
|
|
|
|
t.tv_nsec = -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
/* If a stat-like function returned RESULT, normalize the timestamps
|
|
|
|
in *ST, in case this platform suffers from the Solaris 11 bug where
|
|
|
|
tv_nsec might be negative. Return the adjusted RESULT, setting
|
|
|
|
errno to EOVERFLOW if normalization overflowed. This function
|
|
|
|
is intended to be private to this .h file. */
|
|
|
|
_GL_STAT_TIME_INLINE int
|
Merge from Gnulib
This incorporates:
2018-01-05 maint: Add encoding marker for Emacs to non-ASCII sources
2018-01-04 update-copyright: Handle use of ©
2018-01-04 pthread_sigmask: Avoid compilation error on mingw
2018-01-02 stat-time: silence -Wunused-parameter regression
* build-aux/config.guess, build-aux/config.sub:
* build-aux/update-copyright, doc/misc/texinfo.tex, lib/gnulib.mk.in:
* lib/md5.c, lib/md5.h, lib/sha1.c, lib/sha1.h, lib/sha256.c:
* lib/sha256.h, lib/sha512.c, lib/sha512.h, lib/signal.in.h:
* lib/stat-time.h: Copy from Gnulib, or regenerate.
2018-01-09 23:21:44 +00:00
|
|
|
stat_time_normalize (int result, struct stat *st _GL_UNUSED)
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
{
|
|
|
|
#if defined __sun && defined STAT_TIMESPEC
|
|
|
|
if (result == 0)
|
|
|
|
{
|
Update from Gnulib
This incorporates:
2018-09-10 timespec: fix resolution confusion
2018-09-09 mktime: simplify in prep for glibc merge
2018-09-07 intprops: minor clarification of code
2018-09-06 stddef: Override max_align_t on NetBSD 8.0/x86
2018-09-06 fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku
2018-09-06 strtoll, strtoull: Rely on limits-h module
2018-09-06 limits-h: Provide numerical limits macros
2018-09-06 fcntl: Don't access nonexistent optional argument
2018-09-02 mktime: fix unlikely race+overflow bug
2018-08-31 mktime, timegm: simplify glibc time64_t
2018-08-31 mktime, timegm: simplify merge to glibc
* build-aux/config.guess, build-aux/config.sub:
* lib/dtotimespec.c, lib/fcntl.c, lib/intprops.h:
* lib/limits.in.h, lib/mktime-internal.h, lib/mktime.c:
* lib/stat-time.h, lib/strtol.c, lib/timegm.c:
* lib/timespec-add.c, lib/timespec-sub.c, lib/timespec.h:
* lib/utimens.c, m4/limits-h.m4, m4/stddef_h.m4:
Copy from Gnulib.
2018-09-11 04:16:03 +00:00
|
|
|
long int timespec_hz = 1000000000;
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
short int const ts_off[] = { offsetof (struct stat, st_atim),
|
|
|
|
offsetof (struct stat, st_mtim),
|
|
|
|
offsetof (struct stat, st_ctim) };
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
|
|
|
|
{
|
|
|
|
struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
|
Update from Gnulib
This incorporates:
2018-09-10 timespec: fix resolution confusion
2018-09-09 mktime: simplify in prep for glibc merge
2018-09-07 intprops: minor clarification of code
2018-09-06 stddef: Override max_align_t on NetBSD 8.0/x86
2018-09-06 fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku
2018-09-06 strtoll, strtoull: Rely on limits-h module
2018-09-06 limits-h: Provide numerical limits macros
2018-09-06 fcntl: Don't access nonexistent optional argument
2018-09-02 mktime: fix unlikely race+overflow bug
2018-08-31 mktime, timegm: simplify glibc time64_t
2018-08-31 mktime, timegm: simplify merge to glibc
* build-aux/config.guess, build-aux/config.sub:
* lib/dtotimespec.c, lib/fcntl.c, lib/intprops.h:
* lib/limits.in.h, lib/mktime-internal.h, lib/mktime.c:
* lib/stat-time.h, lib/strtol.c, lib/timegm.c:
* lib/timespec-add.c, lib/timespec-sub.c, lib/timespec.h:
* lib/utimens.c, m4/limits-h.m4, m4/stddef_h.m4:
Copy from Gnulib.
2018-09-11 04:16:03 +00:00
|
|
|
long int q = ts->tv_nsec / timespec_hz;
|
|
|
|
long int r = ts->tv_nsec % timespec_hz;
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
if (r < 0)
|
|
|
|
{
|
Update from Gnulib
This incorporates:
2018-09-10 timespec: fix resolution confusion
2018-09-09 mktime: simplify in prep for glibc merge
2018-09-07 intprops: minor clarification of code
2018-09-06 stddef: Override max_align_t on NetBSD 8.0/x86
2018-09-06 fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku
2018-09-06 strtoll, strtoull: Rely on limits-h module
2018-09-06 limits-h: Provide numerical limits macros
2018-09-06 fcntl: Don't access nonexistent optional argument
2018-09-02 mktime: fix unlikely race+overflow bug
2018-08-31 mktime, timegm: simplify glibc time64_t
2018-08-31 mktime, timegm: simplify merge to glibc
* build-aux/config.guess, build-aux/config.sub:
* lib/dtotimespec.c, lib/fcntl.c, lib/intprops.h:
* lib/limits.in.h, lib/mktime-internal.h, lib/mktime.c:
* lib/stat-time.h, lib/strtol.c, lib/timegm.c:
* lib/timespec-add.c, lib/timespec-sub.c, lib/timespec.h:
* lib/utimens.c, m4/limits-h.m4, m4/stddef_h.m4:
Copy from Gnulib.
2018-09-11 04:16:03 +00:00
|
|
|
r += timespec_hz;
|
Merge from Gnulib
This incorporates:
2017-11-23 stat: work around Solaris bug with tv_nsec < 0
2017-11-12 maint: shorten https://lists.gnu.org/archive/html/... links
* build-aux/config.sub, doc/misc/texinfo.tex, lib/allocator.h:
* lib/fstatat.c, lib/intprops.h, lib/lstat.c, lib/signal.in.h:
* lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h:
* lib/timespec.h, m4/alloca.m4, m4/extern-inline.m4:
* m4/faccessat.m4, m4/fstatat.m4, m4/gnulib-common.m4:
* m4/lstat.m4, m4/std-gnu11.m4, m4/sys_types_h.m4:
* m4/vararrays.m4:
Copy from Gnulib.
2017-11-26 06:28:31 +00:00
|
|
|
q--;
|
|
|
|
}
|
|
|
|
ts->tv_nsec = r;
|
|
|
|
/* Overflow is possible, as Solaris 11 stat can yield
|
|
|
|
tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.
|
|
|
|
INT_ADD_WRAPV is OK, since time_t is signed on Solaris. */
|
|
|
|
if (INT_ADD_WRAPV (q, ts->tv_sec, &ts->tv_sec))
|
|
|
|
{
|
|
|
|
errno = EOVERFLOW;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-19 20:07:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-02 04:46:10 +00:00
|
|
|
_GL_INLINE_HEADER_END
|
|
|
|
|
2012-06-22 21:26:37 +00:00
|
|
|
#endif
|