Skip to content

Commit 05616c5

Browse files
lyakhdanieldegrasse
authored andcommitted
posix: fix posix clock undefined type
When built with the minimal libc while using POSIX clocks, Zephyr compilation breaks with "error: unknown type name 'clockid_t'." Use int instead of clockid_t to eliminate the dependency. Suggested-by: Chris Friedt <cfriedt@tenstorrent.com> Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 99b988b commit 05616c5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/posix/options/posix_clock.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
#define ZEPHYR_LIB_POSIX_POSIX_CLOCK_H_
1010

1111
#include <stdbool.h>
12-
#include <stddef.h>
1312
#include <stdint.h>
1413
#include <time.h>
1514

16-
#include <zephyr/sys_clock.h>
17-
#include <zephyr/sys/__assert.h>
1815
#include <zephyr/posix/sys/time.h>
16+
#include <zephyr/sys/clock.h>
1917
#include <zephyr/sys/timeutil.h>
2018

2119
#ifdef __cplusplus
@@ -59,7 +57,7 @@ static inline bool tp_diff_in_range_ns(const struct timespec *a, const struct ti
5957
return diff >= lo && diff < hi;
6058
}
6159

62-
uint32_t timespec_to_timeoutms(clockid_t clock_id, const struct timespec *abstime);
60+
uint32_t timespec_to_timeoutms(int clock_id, const struct timespec *abstime);
6361

6462
/** INTERNAL_HIDDEN @endcond */
6563

lib/posix/options/timespec_to_timeout.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
#include <limits.h>
1010
#include <stdint.h>
11+
#include <time.h>
1112

12-
#include <zephyr/posix/time.h>
13+
#include <zephyr/sys/clock.h>
1314
#include <zephyr/sys/util.h>
1415

15-
uint32_t timespec_to_timeoutms(clockid_t clock_id, const struct timespec *abstime)
16+
uint32_t timespec_to_timeoutms(int clock_id, const struct timespec *abstime)
1617
{
1718
struct timespec curtime;
1819

19-
if (clock_gettime(clock_id, &curtime) < 0) {
20+
if (sys_clock_gettime(clock_id, &curtime) < 0) {
2021
return 0;
2122
}
2223

0 commit comments

Comments
 (0)