summaryrefslogtreecommitdiffstats
path: root/src/include/stat.h
blob: 19398758e210de568e6c9907e757ba1c3c38355d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef CEPH_STAT_H
#define CEPH_STAT_H

#include <acconfig.h>

#include <sys/stat.h>

/*
 * Access time-related `struct stat` members.
 *
 * Note that for each of the stat member get/set functions below, setting a
 * high-res value (stat_set_*_nsec) on a platform without high-res support is
 * a no-op.
 */

#ifdef HAVE_STAT_ST_MTIM_TV_NSEC

static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
  return st->st_mtim.tv_nsec;
}

static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_mtim.tv_nsec = nsec;
}

static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
  return st->st_atim.tv_nsec;
}

static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_atim.tv_nsec = nsec;
}

static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
  return st->st_ctim.tv_nsec;
}

static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_ctim.tv_nsec = nsec;
}

#elif defined(HAVE_STAT_ST_MTIMESPEC_TV_NSEC)

static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
  return st->st_mtimespec.tv_nsec;
}

static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_mtimespec.tv_nsec = nsec;
}

static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
  return st->st_atimespec.tv_nsec;
}

static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_atimespec.tv_nsec = nsec;
}

static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
  return st->st_ctimespec.tv_nsec;
}

static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
  st->st_ctimespec.tv_nsec = nsec;
}

#else

static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
  return 0;
}

static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
}

static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
  return 0;
}

static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
}

static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
  return 0;
}

static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
}

#endif

/*
 * Access second-resolution `struct stat` members.
 */

static inline uint32_t stat_get_mtime_sec(struct stat *st)
{
  return st->st_mtime;
}

static inline void stat_set_mtime_sec(struct stat *st, uint32_t sec)
{
  st->st_mtime = sec;
}

static inline uint32_t stat_get_atime_sec(struct stat *st)
{
  return st->st_atime;
}

static inline void stat_set_atime_sec(struct stat *st, uint32_t sec)
{
  st->st_atime = sec;
}

static inline uint32_t stat_get_ctime_sec(struct stat *st)
{
  return st->st_ctime;
}

static inline void stat_set_ctime_sec(struct stat *st, uint32_t sec)
{
  st->st_ctime = sec;
}

#endif