posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
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
20#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
21#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
22
23#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
24
25#include <stddef.h>
26
27#include <zephyr/sys/clock.h>
28#include <zephyr/toolchain.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/* clock_t must be defined in the libc time.h */
35/* size_t must be defined in the libc stddef.h */
36/* time_t must be defined in the libc time.h */
37
38#if !defined(_CLOCKID_T_DECLARED) && !defined(__clockid_t_defined)
40typedef unsigned long clockid_t;
41#define _CLOCKID_T_DECLARED
42#define __clockid_t_defined
43#endif
44
45#if !defined(_TIMER_T_DECLARED) && !defined(__timer_t_defined)
47typedef unsigned long timer_t;
48#define _TIMER_T_DECLARED
49#define __timer_t_defined
50#endif
51
52#if !defined(_LOCALE_T_DECLARED) && !defined(__locale_t_defined)
53#ifdef CONFIG_NEWLIB_LIBC
54struct __locale_t;
56typedef struct __locale_t *locale_t;
57#else
59typedef void *locale_t;
60#endif
61#define _LOCALE_T_DECLARED
62#define __locale_t_defined
63#endif
64
65#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
67typedef int pid_t;
68#define _PID_T_DECLARED
69#define __pid_t_defined
70#endif
71
72struct sigevent;
73
74/* struct tm must be defined in the libc time.h */
75
76#if __STDC_VERSION__ >= 201112L
77/* struct timespec must be defined in the libc time.h */
78#else
79#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
84struct timespec {
85 time_t tv_sec;
86 long tv_nsec;
87};
88#define _TIMESPEC_DECLARED
89#define __timespec_defined
90#endif
91#endif
92
93#if !defined(_ITIMERSPEC_DECLARED) && !defined(__itimerspec_defined)
99#define _ITIMERSPEC_DECLARED
100#define __itimerspec_defined
101#endif
102
103/* NULL must be defined in the libc stddef.h */
104
106#ifndef CLOCK_REALTIME
107#define CLOCK_REALTIME ((clockid_t)SYS_CLOCK_REALTIME)
108#endif
109
111#ifndef CLOCKS_PER_SEC
112#if defined(_XOPEN_SOURCE)
113#define CLOCKS_PER_SEC 1000000
114#else
115#define CLOCKS_PER_SEC CONFIG_SYS_CLOCK_TICKS_PER_SEC
116#endif
117#endif
118
119#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
121#ifndef CLOCK_PROCESS_CPUTIME_ID
122#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t)2)
123#endif
124#endif
125
126#if defined(_POSIX_THREAD_CPUTIME) || defined(__DOXYGEN__)
128#ifndef CLOCK_THREAD_CPUTIME_ID
129#define CLOCK_THREAD_CPUTIME_ID ((clockid_t)3)
130#endif
131#endif
132
133#if defined(_POSIX_MONOTONIC_CLOCK) || defined(__DOXYGEN__)
135#ifndef CLOCK_MONOTONIC
136#define CLOCK_MONOTONIC ((clockid_t)SYS_CLOCK_MONOTONIC)
137#endif
138#endif
139
141#ifndef TIMER_ABSTIME
142#define TIMER_ABSTIME SYS_TIMER_ABSTIME
143#endif
144
145/* asctime() must be declared in the libc time.h */
146
147#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
156char *asctime_r(const struct tm *ZRESTRICT tm, char *ZRESTRICT buf);
157#endif
158
159/* clock() must be declared in the libc time.h */
160
161#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
171#endif
172
173#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
182int clock_getres(clockid_t clock_id, struct timespec *ts);
183
192int clock_gettime(clockid_t clock_id, struct timespec *ts);
193#endif
194
195#if defined(_POSIX_CLOCK_SELECTION) || defined(__DOXYGEN__)
206int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp,
207 struct timespec *rmtp);
208#endif
209
210#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
219int clock_settime(clockid_t clock_id, const struct timespec *ts);
220#endif
221
222/* ctime() must be declared in the libc time.h */
223
224#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
233char *ctime_r(const time_t *clock, char *buf);
234#endif
235
236/* difftime() must be declared in the libc time.h */
237
238#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
245struct tm *getdate(const char *string);
246#endif
247
248/* gmtime() must be declared in the libc time.h */
249#if __STDC_VERSION__ >= 202311L
250/* gmtime_r() must be declared in the libc time.h */
251#else
252#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
260struct tm *gmtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result);
261#endif
262#endif
263
264/* localtime() must be declared in the libc time.h */
265#if __STDC_VERSION__ >= 202311L
266/* localtime_r() must be declared in the libc time.h */
267#else
268#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
276struct tm *localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result);
277#endif
278#endif
279
280/* mktime() must be declared in the libc time.h */
281
282#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
291int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
292#endif
293
294/* strftime() must be declared in the libc time.h */
295
307size_t strftime_l(char *ZRESTRICT s, size_t maxsize, const char *ZRESTRICT format,
308 const struct tm *ZRESTRICT timeptr, locale_t locale);
309
310#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
321char *strptime(const char *ZRESTRICT s, const char *ZRESTRICT format, struct tm *ZRESTRICT tm);
322#endif
323
324/* time() must be declared in the libc time.h */
325
326#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
336int timer_create(clockid_t clockId, struct sigevent *ZRESTRICT evp, timer_t *ZRESTRICT timerid);
337
346
355
364int timer_gettime(timer_t timerid, struct itimerspec *its);
365
376int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
377 struct itimerspec *ovalue);
378#endif
379
380#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
383extern int daylight;
386extern long timezone;
387#endif
388
391extern char *tzname[];
392
393
394
395#ifdef __cplusplus
396}
397#endif
398
399#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
400
401#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_ */
int pid_t
Process ID type.
Definition fcntl.h:192
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
Get the CPU-time clock ID for a process.
char * asctime_r(const struct tm *ZRESTRICT tm, char *ZRESTRICT buf)
Convert broken-down time to a string (thread-safe version of asctime()).
struct tm * localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result)
Convert a time_t to local broken-down time (thread-safe version of localtime()).
char * ctime_r(const time_t *clock, char *buf)
Convert a time_t to a string (thread-safe version of ctime()).
struct tm * gmtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result)
Convert a time_t to UTC broken-down time (thread-safe version of gmtime()).
char * tzname[]
Timezone abbreviations; tzname[0] = std, tzname[1] = dst.
size_t strftime_l(char *ZRESTRICT s, size_t maxsize, const char *ZRESTRICT format, const struct tm *ZRESTRICT timeptr, locale_t locale)
Format broken-down time into a string using the specified locale.
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
High-resolution sleep against a specified clock.
int timer_gettime(timer_t timerid, struct itimerspec *its)
Get the time remaining until the next timer expiration.
int clock_gettime(clockid_t clock_id, struct timespec *ts)
Get the current time of a clock.
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Arm or disarm a per-process timer.
int clock_getres(clockid_t clock_id, struct timespec *ts)
Get the resolution of a clock.
int timer_create(clockid_t clockId, struct sigevent *ZRESTRICT evp, timer_t *ZRESTRICT timerid)
Create a per-process timer.
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
Sleep for a specified number of nanoseconds (high-resolution sleep).
int timer_delete(timer_t timerid)
Delete a per-process timer.
int timer_getoverrun(timer_t timerid)
Get the number of timer overruns since the last timer expiration notification.
int clock_settime(clockid_t clock_id, const struct timespec *ts)
Set the time of a clock.
long timezone
Offset in seconds from UTC for the current timezone.
char * strptime(const char *ZRESTRICT s, const char *ZRESTRICT format, struct tm *ZRESTRICT tm)
Parse a date/time string according to a format (XSI extension).
int daylight
Non-zero if Daylight Saving Time is in effect.
struct tm * getdate(const char *string)
Convert a date-time string to broken-down time (XSI extension).
int pid_t
Process ID type.
Definition posix_time.h:67
unsigned long clockid_t
Identifies a clock (e.g.
Definition posix_time.h:40
void * locale_t
Opaque locale object.
Definition posix_time.h:59
unsigned long timer_t
Opaque handle for a POSIX interval timer created with timer_create().
Definition posix_time.h:47
Interval timer specification used with timer_settime() and timer_gettime().
Definition posix_time.h:95
struct timespec it_interval
Timer interval (period); zero for a one-shot timer.
Definition posix_time.h:96
struct timespec it_value
Initial expiration time; zero to disarm.
Definition posix_time.h:97
Structure describing how to notify about an asynchronous event.
Time value with nanosecond resolution.
Definition aio.h:62
long tv_nsec
Nanoseconds [0, 999999999].
Definition aio.h:64
time_t tv_sec
Seconds.
Definition aio.h:63