20#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
21#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_
23#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
27#include <zephyr/sys/clock.h>
28#include <zephyr/toolchain.h>
38#if !defined(_CLOCKID_T_DECLARED) && !defined(__clockid_t_defined)
41#define _CLOCKID_T_DECLARED
42#define __clockid_t_defined
45#if !defined(_TIMER_T_DECLARED) && !defined(__timer_t_defined)
48#define _TIMER_T_DECLARED
49#define __timer_t_defined
52#if !defined(_LOCALE_T_DECLARED) && !defined(__locale_t_defined)
53#ifdef CONFIG_NEWLIB_LIBC
61#define _LOCALE_T_DECLARED
62#define __locale_t_defined
65#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
68#define _PID_T_DECLARED
69#define __pid_t_defined
76#if __STDC_VERSION__ >= 201112L
79#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
88#define _TIMESPEC_DECLARED
89#define __timespec_defined
93#if !defined(_ITIMERSPEC_DECLARED) && !defined(__itimerspec_defined)
99#define _ITIMERSPEC_DECLARED
100#define __itimerspec_defined
106#ifndef CLOCK_REALTIME
107#define CLOCK_REALTIME ((clockid_t)SYS_CLOCK_REALTIME)
111#ifndef CLOCKS_PER_SEC
112#if defined(_XOPEN_SOURCE)
113#define CLOCKS_PER_SEC 1000000
115#define CLOCKS_PER_SEC CONFIG_SYS_CLOCK_TICKS_PER_SEC
119#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
121#ifndef CLOCK_PROCESS_CPUTIME_ID
122#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t)2)
126#if defined(_POSIX_THREAD_CPUTIME) || defined(__DOXYGEN__)
128#ifndef CLOCK_THREAD_CPUTIME_ID
129#define CLOCK_THREAD_CPUTIME_ID ((clockid_t)3)
133#if defined(_POSIX_MONOTONIC_CLOCK) || defined(__DOXYGEN__)
135#ifndef CLOCK_MONOTONIC
136#define CLOCK_MONOTONIC ((clockid_t)SYS_CLOCK_MONOTONIC)
142#define TIMER_ABSTIME SYS_TIMER_ABSTIME
147#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
156char *
asctime_r(
const struct tm *ZRESTRICT tm,
char *ZRESTRICT buf);
161#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__)
173#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
195#if defined(_POSIX_CLOCK_SELECTION) || defined(__DOXYGEN__)
210#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
224#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
238#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
249#if __STDC_VERSION__ >= 202311L
252#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
260struct tm *
gmtime_r(
const time_t *ZRESTRICT timer,
struct tm *ZRESTRICT result);
265#if __STDC_VERSION__ >= 202311L
268#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__)
276struct tm *
localtime_r(
const time_t *ZRESTRICT timer,
struct tm *ZRESTRICT result);
282#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
307size_t strftime_l(
char *ZRESTRICT s,
size_t maxsize,
const char *ZRESTRICT format,
308 const struct tm *ZRESTRICT timeptr,
locale_t locale);
310#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
321char *
strptime(
const char *ZRESTRICT s,
const char *ZRESTRICT format,
struct tm *ZRESTRICT tm);
326#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__)
380#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
int pid_t
Process ID type.
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.
unsigned long clockid_t
Identifies a clock (e.g.
void * locale_t
Opaque locale object.
unsigned long timer_t
Opaque handle for a POSIX interval timer created with timer_create().
Interval timer specification used with timer_settime() and timer_gettime().
struct timespec it_interval
Timer interval (period); zero for a one-shot timer.
struct timespec it_value
Initial expiration time; zero to disarm.
Structure describing how to notify about an asynchronous event.
Time value with nanosecond resolution.
long tv_nsec
Nanoseconds [0, 999999999].