1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* stat-related time functions.
5 Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Written by Paul Eggert. */
28 _GL_INLINE_HEADER_BEGIN
29 #ifndef _GL_STAT_TIME_INLINE
30 # define _GL_STAT_TIME_INLINE _GL_INLINE
33 /* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
34 struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
35 ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
36 if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
37 for access, status change, data modification, or birth (creation)
40 These macros are private to stat-time.h. */
41 #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
42 # ifdef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
43 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
45 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
47 #elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
48 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
49 #elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
50 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
51 #elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
52 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
55 /* Return the nanosecond component of *ST's access time. */
56 _GL_STAT_TIME_INLINE long int
57 get_stat_atime_ns (struct stat const *st)
59 # if defined STAT_TIMESPEC
60 return STAT_TIMESPEC (st, st_atim).tv_nsec;
61 # elif defined STAT_TIMESPEC_NS
62 return STAT_TIMESPEC_NS (st, st_atim);
68 /* Return the nanosecond component of *ST's status change time. */
69 _GL_STAT_TIME_INLINE long int
70 get_stat_ctime_ns (struct stat const *st)
72 # if defined STAT_TIMESPEC
73 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
74 # elif defined STAT_TIMESPEC_NS
75 return STAT_TIMESPEC_NS (st, st_ctim);
81 /* Return the nanosecond component of *ST's data modification time. */
82 _GL_STAT_TIME_INLINE long int
83 get_stat_mtime_ns (struct stat const *st)
85 # if defined STAT_TIMESPEC
86 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
87 # elif defined STAT_TIMESPEC_NS
88 return STAT_TIMESPEC_NS (st, st_mtim);
94 /* Return the nanosecond component of *ST's birth time. */
95 _GL_STAT_TIME_INLINE long int
96 get_stat_birthtime_ns (struct stat const *st)
98 # if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
99 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
100 # elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
101 return STAT_TIMESPEC_NS (st, st_birthtim);
103 /* Avoid a "parameter unused" warning. */
109 /* Return *ST's access time. */
110 _GL_STAT_TIME_INLINE struct timespec
111 get_stat_atime (struct stat const *st)
114 return STAT_TIMESPEC (st, st_atim);
117 t.tv_sec = st->st_atime;
118 t.tv_nsec = get_stat_atime_ns (st);
123 /* Return *ST's status change time. */
124 _GL_STAT_TIME_INLINE struct timespec
125 get_stat_ctime (struct stat const *st)
128 return STAT_TIMESPEC (st, st_ctim);
131 t.tv_sec = st->st_ctime;
132 t.tv_nsec = get_stat_ctime_ns (st);
137 /* Return *ST's data modification time. */
138 _GL_STAT_TIME_INLINE struct timespec
139 get_stat_mtime (struct stat const *st)
142 return STAT_TIMESPEC (st, st_mtim);
145 t.tv_sec = st->st_mtime;
146 t.tv_nsec = get_stat_mtime_ns (st);
151 /* Return *ST's birth time, if available; otherwise return a value
152 with tv_sec and tv_nsec both equal to -1. */
153 _GL_STAT_TIME_INLINE struct timespec
154 get_stat_birthtime (struct stat const *st)
158 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
159 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
160 t = STAT_TIMESPEC (st, st_birthtim);
161 #elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
162 t.tv_sec = st->st_birthtime;
163 t.tv_nsec = st->st_birthtimensec;
164 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
165 /* Native Windows platforms (but not Cygwin) put the "file creation
166 time" in st_ctime (!). See
167 <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>. */
168 t.tv_sec = st->st_ctime;
171 /* Birth time is not supported. */
174 /* Avoid a "parameter unused" warning. */
178 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
179 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
180 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
181 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by
182 using zero. Attempt to work around this problem. Alas, this can
183 report failure even for valid time stamps. Also, NetBSD
184 sometimes returns junk in the birth time fields; work around this
185 bug if it is detected. */
186 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
196 _GL_INLINE_HEADER_END