Skip to content

posix: time.h: move definitions to time.h of the minimal libc #94308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/zephyr/posix/posix_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
#define _POSIX_MESSAGE_PASSING _POSIX_VERSION
#endif

#ifdef CONFIG_POSIX_MONOTONIC_CLOCK
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
#endif
// #ifdef CONFIG_POSIX_MONOTONIC_CLOCK

Check failure on line 93 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:93 do not use C99 // comments

Check failure on line 93 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:93 do not use C99 // comments
// #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION

Check failure on line 94 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:94 do not use C99 // comments

Check failure on line 94 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:94 do not use C99 // comments
// #endif

Check failure on line 95 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:95 do not use C99 // comments

Check failure on line 95 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:95 do not use C99 // comments

/* #define _POSIX_PRIORITIZED_IO (-1L) */

Expand Down Expand Up @@ -177,9 +177,9 @@
#define _POSIX_TIMEOUTS _POSIX_VERSION
#endif

#ifdef CONFIG_POSIX_TIMERS
#define _POSIX_TIMERS _POSIX_VERSION
#endif
// #ifdef CONFIG_POSIX_TIMERS

Check failure on line 180 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:180 do not use C99 // comments

Check failure on line 180 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:180 do not use C99 // comments
// #define _POSIX_TIMERS _POSIX_VERSION

Check failure on line 181 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:181 do not use C99 // comments

Check failure on line 181 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:181 do not use C99 // comments
// #endif

Check failure on line 182 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:182 do not use C99 // comments

Check failure on line 182 in include/zephyr/posix/posix_features.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

include/zephyr/posix/posix_features.h:182 do not use C99 // comments

/* #define _POSIX_TRACE (-1L) */
/* #define _POSIX_TRACE_EVENT_FILTER (-1L) */
Expand Down
8 changes: 7 additions & 1 deletion include/zephyr/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ typedef unsigned long blkcnt_t;
#endif

#if !defined(CONFIG_ARCMWDT_LIBC)
typedef int pid_t;

#if (!defined(_PID_T_DECLARED) && !defined(__pid_t_defined)) || defined(__DOXYGEN__)
typedef long pid_t;
#define _PID_T_DECLARED
#define __pid_t_defined
#endif

#endif

#ifndef __useconds_t_defined
Expand Down
108 changes: 1 addition & 107 deletions include/zephyr/posix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,6 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
#define ZEPHYR_INCLUDE_POSIX_TIME_H_

/* Read standard header. This may find <posix/time.h> since they
* refer to the same file when include/posix is in the search path.
*/
#include <time.h>

#ifdef CONFIG_NEWLIB_LIBC
/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
#include <newlib.h>

#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/timespec.h>
#else /* __NEWLIB__ */
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
* so mimic it here.
*/
#include <sys/types.h>
#ifndef __timespec_defined

#ifdef __cplusplus
extern "C" {
#endif

struct timespec {
time_t tv_sec;
long tv_nsec;
};

struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};

#ifdef __cplusplus
}
#endif

#endif /* __timespec_defined */
#endif /* __NEWLIB__ */

#else /* CONFIG_NEWLIB_LIBC */
/* Not Newlib */
# if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
# include <bits/types/struct_timespec.h>
# include <bits/types/struct_itimerspec.h>
# else
# include <sys/timespec.h>
# endif
#endif /* CONFIG_NEWLIB_LIBC */

#include <zephyr/kernel.h>
#include <errno.h>
#include <zephyr/posix/posix_types.h>
#include <zephyr/posix/signal.h>
#include <zephyr/sys/clock.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
#endif

#ifndef CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID 2
#endif

#ifndef CLOCK_THREAD_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID 3
#endif

#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC
#endif

#ifndef TIMER_ABSTIME
#define TIMER_ABSTIME SYS_TIMER_ABSTIME
#endif

int clock_gettime(clockid_t clock_id, struct timespec *ts);
int clock_getres(clockid_t clock_id, struct timespec *ts);
int clock_settime(clockid_t clock_id, const struct timespec *ts);
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
/* Timer APIs */
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
int timer_delete(timer_t timerid);
struct itimerspec;
int timer_gettime(timer_t timerid, struct itimerspec *its);
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
struct itimerspec *ovalue);
int timer_getoverrun(timer_t timerid);
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
int clock_nanosleep(clockid_t clock_id, int flags,
const struct timespec *rqtp, struct timespec *rmtp);

#ifdef __cplusplus
}
#endif

#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
/* Read the toolchain header when <posix/time.h> finds itself on the
* first attempt.
*/
/* TODO: Deprecate including this header */
#include_next <time.h>
#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
Loading
Loading