~ubuntu-branches/ubuntu/utopic/patch/utopic-security

« back to all changes in this revision

Viewing changes to lib/stat-time.h

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2013-01-03 17:34:45 UTC
  • mfrom: (1.2.3)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20130103173445-i46hggipf8rfteiz
Tags: 2.7.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* stat-related time functions.
2
2
 
3
 
   Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc.
 
3
   Copyright (C) 2005, 2007, 2009-2012 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
6
6
   it under the terms of the GNU General Public License as published by
23
23
#include <sys/stat.h>
24
24
#include <time.h>
25
25
 
 
26
_GL_INLINE_HEADER_BEGIN
 
27
#ifndef _GL_STAT_TIME_INLINE
 
28
# define _GL_STAT_TIME_INLINE _GL_INLINE
 
29
#endif
 
30
 
26
31
/* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
27
32
   struct timespec, if available.  If not, then STAT_TIMESPEC_NS (ST,
28
33
   ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
46
51
#endif
47
52
 
48
53
/* Return the nanosecond component of *ST's access time.  */
49
 
static inline long int
 
54
_GL_STAT_TIME_INLINE long int
50
55
get_stat_atime_ns (struct stat const *st)
51
56
{
52
57
# if defined STAT_TIMESPEC
59
64
}
60
65
 
61
66
/* Return the nanosecond component of *ST's status change time.  */
62
 
static inline long int
 
67
_GL_STAT_TIME_INLINE long int
63
68
get_stat_ctime_ns (struct stat const *st)
64
69
{
65
70
# if defined STAT_TIMESPEC
72
77
}
73
78
 
74
79
/* Return the nanosecond component of *ST's data modification time.  */
75
 
static inline long int
 
80
_GL_STAT_TIME_INLINE long int
76
81
get_stat_mtime_ns (struct stat const *st)
77
82
{
78
83
# if defined STAT_TIMESPEC
85
90
}
86
91
 
87
92
/* Return the nanosecond component of *ST's birth time.  */
88
 
static inline long int
 
93
_GL_STAT_TIME_INLINE long int
89
94
get_stat_birthtime_ns (struct stat const *st)
90
95
{
91
96
# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
100
105
}
101
106
 
102
107
/* Return *ST's access time.  */
103
 
static inline struct timespec
 
108
_GL_STAT_TIME_INLINE struct timespec
104
109
get_stat_atime (struct stat const *st)
105
110
{
106
111
#ifdef STAT_TIMESPEC
114
119
}
115
120
 
116
121
/* Return *ST's status change time.  */
117
 
static inline struct timespec
 
122
_GL_STAT_TIME_INLINE struct timespec
118
123
get_stat_ctime (struct stat const *st)
119
124
{
120
125
#ifdef STAT_TIMESPEC
128
133
}
129
134
 
130
135
/* Return *ST's data modification time.  */
131
 
static inline struct timespec
 
136
_GL_STAT_TIME_INLINE struct timespec
132
137
get_stat_mtime (struct stat const *st)
133
138
{
134
139
#ifdef STAT_TIMESPEC
142
147
}
143
148
 
144
149
/* Return *ST's birth time, if available; otherwise return a value
145
 
   with negative tv_nsec.  */
146
 
static inline struct timespec
 
150
   with tv_sec and tv_nsec both equal to -1.  */
 
151
_GL_STAT_TIME_INLINE struct timespec
147
152
get_stat_birthtime (struct stat const *st)
148
153
{
149
154
  struct timespec t;
155
160
  t.tv_sec = st->st_birthtime;
156
161
  t.tv_nsec = st->st_birthtimensec;
157
162
#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
158
 
  /* Woe32 native platforms (but not Cygwin) put the "file creation
 
163
  /* Native Windows platforms (but not Cygwin) put the "file creation
159
164
     time" in st_ctime (!).  See
160
165
     <http://msdn2.microsoft.com/de-de/library/14h5k7ff(VS.80).aspx>.  */
161
166
  t.tv_sec = st->st_ctime;
162
167
  t.tv_nsec = 0;
163
168
#else
164
 
  /* Birth time is not supported.  Set tv_sec to avoid undefined behavior.  */
 
169
  /* Birth time is not supported.  */
165
170
  t.tv_sec = -1;
166
171
  t.tv_nsec = -1;
167
172
  /* Avoid a "parameter unused" warning.  */
175
180
     using zero.  Attempt to work around this problem.  Alas, this can
176
181
     report failure even for valid time stamps.  Also, NetBSD
177
182
     sometimes returns junk in the birth time fields; work around this
178
 
     bug if it it is detected.  There's no need to detect negative
179
 
     tv_nsec junk as negative tv_nsec already indicates an error.  */
180
 
  if (t.tv_sec == 0 || 1000000000 <= t.tv_nsec)
181
 
    t.tv_nsec = -1;
 
183
     bug if it is detected.  */
 
184
  if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
 
185
    {
 
186
      t.tv_sec = -1;
 
187
      t.tv_nsec = -1;
 
188
    }
182
189
#endif
183
190
 
184
191
  return t;
185
192
}
186
193
 
 
194
_GL_INLINE_HEADER_END
 
195
 
187
196
#endif