Skip to content

Commit 87e11a8

Browse files
committed
tst_timer: Fix compilation on pre C11 compilers
The anonymous unions are supported since C11 and we have to still support at least gcc-4.4 which does not support C11 since the compiler is older than the standard. So this commit gives the union name however 99% of code is unchanged since we are using function to access the structure members anyways. Signed-off-by: Cyril Hrubis <[email protected]> Reported-by: Petr Vorel <[email protected]>
1 parent ce1ed5f commit 87e11a8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

include/tst_timer.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ enum tst_ts_type {
121121

122122
struct tst_ts {
123123
enum tst_ts_type type;
124-
union {
124+
union ts {
125125
struct timespec libc_ts;
126126
struct __kernel_old_timespec kern_old_ts;
127127
struct __kernel_timespec kern_ts;
128-
};
128+
} ts;
129129
};
130130

131131
/*
@@ -135,11 +135,11 @@ static inline long long tst_ts_get_sec(struct tst_ts ts)
135135
{
136136
switch (ts.type) {
137137
case TST_LIBC_TIMESPEC:
138-
return ts.libc_ts.tv_sec;
138+
return ts.ts.libc_ts.tv_sec;
139139
case TST_KERN_OLD_TIMESPEC:
140-
return ts.kern_old_ts.tv_sec;
140+
return ts.ts.kern_old_ts.tv_sec;
141141
case TST_KERN_TIMESPEC:
142-
return ts.kern_ts.tv_sec;
142+
return ts.ts.kern_ts.tv_sec;
143143
default:
144144
tst_brk(TBROK, "Invalid type: %d", ts.type);
145145
return -1;
@@ -153,11 +153,11 @@ static inline long long tst_ts_get_nsec(struct tst_ts ts)
153153
{
154154
switch (ts.type) {
155155
case TST_LIBC_TIMESPEC:
156-
return ts.libc_ts.tv_nsec;
156+
return ts.ts.libc_ts.tv_nsec;
157157
case TST_KERN_OLD_TIMESPEC:
158-
return ts.kern_old_ts.tv_nsec;
158+
return ts.ts.kern_old_ts.tv_nsec;
159159
case TST_KERN_TIMESPEC:
160-
return ts.kern_ts.tv_nsec;
160+
return ts.ts.kern_ts.tv_nsec;
161161
default:
162162
tst_brk(TBROK, "Invalid type: %d", ts.type);
163163
return -1;
@@ -171,13 +171,13 @@ static inline void tst_ts_set_sec(struct tst_ts *ts, long long sec)
171171
{
172172
switch (ts->type) {
173173
case TST_LIBC_TIMESPEC:
174-
ts->libc_ts.tv_sec = sec;
174+
ts->ts.libc_ts.tv_sec = sec;
175175
break;
176176
case TST_KERN_OLD_TIMESPEC:
177-
ts->kern_old_ts.tv_sec = sec;
177+
ts->ts.kern_old_ts.tv_sec = sec;
178178
break;
179179
case TST_KERN_TIMESPEC:
180-
ts->kern_ts.tv_sec = sec;
180+
ts->ts.kern_ts.tv_sec = sec;
181181
break;
182182
default:
183183
tst_brk(TBROK, "Invalid type: %d", ts->type);
@@ -191,13 +191,13 @@ static inline void tst_ts_set_nsec(struct tst_ts *ts, long long nsec)
191191
{
192192
switch (ts->type) {
193193
case TST_LIBC_TIMESPEC:
194-
ts->libc_ts.tv_nsec = nsec;
194+
ts->ts.libc_ts.tv_nsec = nsec;
195195
break;
196196
case TST_KERN_OLD_TIMESPEC:
197-
ts->kern_old_ts.tv_nsec = nsec;
197+
ts->ts.kern_old_ts.tv_nsec = nsec;
198198
break;
199199
case TST_KERN_TIMESPEC:
200-
ts->kern_ts.tv_nsec = nsec;
200+
ts->ts.kern_ts.tv_nsec = nsec;
201201
break;
202202
default:
203203
tst_brk(TBROK, "Invalid type: %d", ts->type);
@@ -211,8 +211,8 @@ static inline struct tst_ts tst_ts_from_timespec(struct timespec ts)
211211
{
212212
struct tst_ts t = {
213213
.type = TST_LIBC_TIMESPEC,
214-
.libc_ts.tv_sec = ts.tv_sec,
215-
.libc_ts.tv_nsec = ts.tv_nsec,
214+
.ts.libc_ts.tv_sec = ts.tv_sec,
215+
.ts.libc_ts.tv_nsec = ts.tv_nsec,
216216
};
217217

218218
return t;
@@ -223,7 +223,7 @@ static inline struct tst_ts tst_ts_from_timespec(struct timespec ts)
223223
*/
224224
static inline struct timespec tst_ts_to_timespec(struct tst_ts t)
225225
{
226-
return t.libc_ts;
226+
return t.ts.libc_ts;
227227
}
228228

229229
/*

0 commit comments

Comments
 (0)