Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
posix_time.h
Go to the documentation of this file.
1/*
2 * Copyright The Zephyr Project Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
8#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
9
10#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
11
12#include <stddef.h>
13
14#include <zephyr/sys/clock.h>
15#include <zephyr/toolchain.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* clock_t must be defined in the libc time.h */
22/* size_t must be defined in the libc stddef.h */
23/* time_t must be defined in the libc time.h */
24
25#if !defined(_CLOCKID_T_DECLARED) && !defined(__clockid_t_defined)
26typedef unsigned long clockid_t;
27#define _CLOCKID_T_DECLARED
28#define __clockid_t_defined
29#endif
30
31#if !defined(_TIMER_T_DECLARED) && !defined(__timer_t_defined)
32typedef unsigned long timer_t;
33#define _TIMER_T_DECLARED
34#define __timer_t_defined
35#endif
36
37#if !defined(_LOCALE_T_DECLARED) && !defined(__locale_t_defined)
38#ifdef CONFIG_NEWLIB_LIBC
39struct __locale_t;
40typedef struct __locale_t *locale_t;
41#else
42typedef void *locale_t;
43#endif
44#define _LOCALE_T_DECLARED
45#define __locale_t_defined
46#endif
47
48#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
49typedef int pid_t;
50#define _PID_T_DECLARED
51#define __pid_t_defined
52#endif
53
54#if defined(_POSIX_REALTIME_SIGNALS)
55struct sigevent;
56#endif
57
58/* struct tm must be defined in the libc time.h */
59
60#if __STDC_VERSION__ >= 201112L
61/* struct timespec must be defined in the libc time.h */
62#else
63#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
64typedef struct {
66 long tv_nsec;
68#define _TIMESPEC_DECLARED
69#define __timespec_defined
70#endif
71#endif
72
73#if !defined(_ITIMERSPEC_DECLARED) && !defined(__itimerspec_defined)
78#define _ITIMERSPEC_DECLARED
79#define __itimerspec_defined
80#endif
81
82/* NULL must be defined in the libc stddef.h */
83
84#ifndef CLOCK_REALTIME
85#define CLOCK_REALTIME ((clockid_t)SYS_CLOCK_REALTIME)
86#endif
87
88#ifndef CLOCKS_PER_SEC
89#if defined(_XOPEN_SOURCE)
90#define CLOCKS_PER_SEC 1000000
91#else
92#define CLOCKS_PER_SEC CONFIG_SYS_CLOCK_TICKS_PER_SEC
93#endif
94#endif
95
96#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
97#ifndef CLOCK_PROCESS_CPUTIME_ID
98#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t)2)
99#endif
100#endif
101
102#if defined(_POSIX_THREAD_CPUTIME) || defined(__DOXYGEN__)
103#ifndef CLOCK_THREAD_CPUTIME_ID
104#define CLOCK_THREAD_CPUTIME_ID ((clockid_t)3)
105#endif
106#endif
107
108#if defined(_POSIX_MONOTONIC_CLOCK) || defined(__DOXYGEN__)
109#ifndef CLOCK_MONOTONIC
110#define CLOCK_MONOTONIC ((clockid_t)SYS_CLOCK_MONOTONIC)
111#endif
112#endif
113
114#ifndef TIMER_ABSTIME
115#define TIMER_ABSTIME SYS_TIMER_ABSTIME
116#endif
117
118/* asctime() must be declared in the libc time.h */
119#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
120char *asctime_r(const struct tm *ZRESTRICT tm, char *ZRESTRICT buf);
121#endif
122/* clock() must be declared in the libc time.h */
123#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
125#endif
126#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
127int clock_getres(clockid_t clock_id, struct timespec *ts);
128int clock_gettime(clockid_t clock_id, struct timespec *ts);
129#endif
130#if defined(_POSIX_CLOCK_SELECTION) || defined(__DOXYGEN__)
131int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp,
132 struct timespec *rmtp);
133#endif
134#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
135int clock_settime(clockid_t clock_id, const struct timespec *ts);
136#endif
137/* ctime() must be declared in the libc time.h */
138#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
139char *ctime_r(const time_t *clock, char *buf);
140#endif
141/* difftime() must be declared in the libc time.h */
142#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
143struct tm *getdate(const char *string);
144#endif
145/* gmtime() must be declared in the libc time.h */
146#if __STDC_VERSION__ >= 202311L
147/* gmtime_r() must be declared in the libc time.h */
148#else
149#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
150struct tm *gmtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result);
151#endif
152#endif
153/* localtime() must be declared in the libc time.h */
154#if __STDC_VERSION__ >= 202311L
155/* localtime_r() must be declared in the libc time.h */
156#else
157#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
158struct tm *localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result);
159#endif
160#endif
161/* mktime() must be declared in the libc time.h */
162#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
163int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
164#endif
165/* strftime() must be declared in the libc time.h */
166size_t strftime_l(char *ZRESTRICT s, size_t maxsize, const char *ZRESTRICT format,
167 const struct tm *ZRESTRICT timeptr, locale_t locale);
168#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
169char *strptime(const char *ZRESTRICT s, const char *ZRESTRICT format, struct tm *ZRESTRICT tm);
170#endif
171/* time() must be declared in the libc time.h */
172#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
173int timer_create(clockid_t clockId, struct sigevent *ZRESTRICT evp, timer_t *ZRESTRICT timerid);
176int timer_gettime(timer_t timerid, struct itimerspec *its);
177int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
178 struct itimerspec *ovalue);
179#endif
180
181#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
182extern int daylight;
183extern long timezone;
184#endif
185
186extern char *tzname[];
187
188#ifdef __cplusplus
189}
190#endif
191
192#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
193
194#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa s
Definition asm-macro-32-bit-gnu.h:17
System clock APIs.
#define ZRESTRICT
Definition common.h:37
flags
Definition parser.h:97
long pid_t
Definition posix_signal.h:80
long time_t
Definition posix_signal.h:47
char * asctime_r(const struct tm *ZRESTRICT tm, char *ZRESTRICT buf)
int timer_gettime(timer_t timerid, struct itimerspec *its)
char * tzname[]
int clock_gettime(clockid_t clock_id, struct timespec *ts)
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
struct tm * localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result)
int clock_getres(clockid_t clock_id, struct timespec *ts)
long timezone
size_t strftime_l(char *ZRESTRICT s, size_t maxsize, const char *ZRESTRICT format, const struct tm *ZRESTRICT timeptr, locale_t locale)
char * strptime(const char *ZRESTRICT s, const char *ZRESTRICT format, struct tm *ZRESTRICT tm)
int timer_create(clockid_t clockId, struct sigevent *ZRESTRICT evp, timer_t *ZRESTRICT timerid)
unsigned long clockid_t
Definition posix_time.h:26
int daylight
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
void * locale_t
Definition posix_time.h:42
unsigned long timer_t
Definition posix_time.h:32
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
char * ctime_r(const time_t *clock, char *buf)
struct tm * getdate(const char *string)
int timer_delete(timer_t timerid)
int timer_getoverrun(timer_t timerid)
int clock_settime(clockid_t clock_id, const struct timespec *ts)
struct tm * gmtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result)
Definition posix_time.h:74
struct timespec it_interval
Definition posix_time.h:75
struct timespec it_value
Definition posix_time.h:76
Definition posix_time.h:64
time_t tv_sec
Definition posix_time.h:65
long tv_nsec
Definition posix_time.h:66
Definition posix_signal.h:53
Definition time.h:24
Macros to abstract toolchain specific capabilities.