Skip to content

Commit ce8b3b0

Browse files
committed
posix: struct timespec: Move definition to sys/_timespec.h
POSIX subsys defines struct timespec in <time.h> (as POSIX public API requires), but newlib defines in in sys/_timespec.h, which inevitably leads to inclusion order and redifinition conflicts. Follow newlib way and define it in single place, sys/_timespec.h, which belongs to libc namespace. Thus, we move current definition to minimal libc, and will use either minlibc's or newlib's definition, instead of trying to redefine it. This is similar to the introduction of sys/_timeval.h done earlier. Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 0873eee commit ce8b3b0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

include/posix/time.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
extern "C" {
1111
#endif
1212

13-
14-
#ifndef __timespec_defined
15-
#define __timespec_defined
16-
struct timespec {
17-
signed int tv_sec;
18-
signed int tv_nsec;
19-
};
20-
#endif
13+
#include <sys/_timespec.h>
2114

2215
/* Older newlib's like 2.{0-2}.0 don't define any newlib version defines, only
2316
* __NEWLIB_H__ so we use that to decide if itimerspec was defined in
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/types.h>
11+
12+
struct timespec {
13+
time_t tv_sec;
14+
long tv_nsec;
15+
};
16+
17+
#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ */

0 commit comments

Comments
 (0)