Skip to content

Commit 0173d86

Browse files
pfalcongalak
authored andcommitted
lib: posix, minlibc: struct itimerspec is defined by sys/timespec.h
Newlib has it defined in sys/timespec.h, and thus per the established conventions, everything else relies on it being there. Specifically, minimal libc acquires sys/timespec.h with a similar definition, and POSIX headers rely on that header. Still with a workaround for old Newlib version as used by Xtensa (but all infrastructure for that is already there; actually, this patch removes duplicate similar-infra, which apparently didn't work as expected by now, so now we have a single workaround, not 2 different once). To emphasize a point, now there 2 headers: sys/_timespec.h, defining struct timespec, and sys/timespec.h, defining struct itimerspec That's how Newlib has it, and what we faithfully embrace and follow, because otherwise, there will be header conflicts depending on various libc and POSIX subsys options. Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent ae5a7bb commit 0173d86

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

include/posix/time.h

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#ifdef __NEWLIB__
1414
/* Newever Newlib 3.x+ */
15-
#include <sys/_timespec.h>
15+
#include <sys/timespec.h>
1616
#else /* __NEWLIB__ */
1717
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
1818
* so mimic it here.
@@ -29,6 +29,11 @@ struct timespec {
2929
long tv_nsec;
3030
};
3131

32+
struct itimerspec {
33+
struct timespec it_interval; /* Timer interval */
34+
struct timespec it_value; /* Timer expiration */
35+
};
36+
3237
#ifdef __cplusplus
3338
}
3439
#endif
@@ -38,33 +43,9 @@ struct timespec {
3843

3944
#else /* CONFIG_NEWLIB_LIBC */
4045
/* Not Newlib */
41-
#include <sys/_timespec.h>
46+
#include <sys/timespec.h>
4247
#endif /* CONFIG_NEWLIB_LIBC */
4348

44-
/* Older newlib's like 2.{0-2}.0 don't define any newlib version defines, only
45-
* __NEWLIB_H__ so we use that to decide if itimerspec was defined in
46-
* sys/types.h w/o any protection. It appears sometime in the 2.3.0 version
47-
* of newlib did itimerspec move out of sys/types.h, however version 2.3.0
48-
* seems to report itself as __NEWLIB_MINOR__ == 2, where as 2.2.0 doesn't
49-
* even define __NEWLIB_MINOR__ or __NEWLIB__
50-
*/
51-
#if !defined(__NEWLIB_H__) || (__NEWLIB__ >= 3) || \
52-
(__NEWLIB__ == 2 && __NEWLIB_MINOR__ >= 2)
53-
54-
#ifdef __cplusplus
55-
extern "C" {
56-
#endif
57-
58-
struct itimerspec {
59-
struct timespec it_interval; /* Timer interval */
60-
struct timespec it_value; /* Timer expiration */
61-
};
62-
#ifdef __cplusplus
63-
}
64-
#endif
65-
66-
#endif
67-
6849
#include <kernel.h>
6950
#include <errno.h>
7051
#include "posix_types.h"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_
8+
#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_
9+
10+
#include <sys/_timespec.h>
11+
12+
struct itimerspec {
13+
struct timespec it_interval; /* Timer interval */
14+
struct timespec it_value; /* Timer expiration */
15+
};
16+
17+
#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_ */

0 commit comments

Comments
 (0)