KallistiOS
git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1
/* KallistiOS ##version##
2
3
kos/time.h
4
Copyright (C) 2023 Lawrence Sebald
5
Copyright (C) 2024 Falco Girgis
6
*/
7
8
/** \file kos/time.h
9
\brief KOS-implementation of select C11 and POSIX extensions
10
11
Add select POSIX extensions, C11, and C23 functionality to time.h which are not
12
present within Newlib.
13
14
\remark
15
This will probably go away at some point in the future, if/when Newlib gets
16
an implementation of this function. But for now, it's here.
17
18
\todo
19
- Implement _POSIX_TIMERS, which requires POSIX signals back-end.
20
- Implement thread-specific CPU time
21
22
\author Lawrence Sebald
23
\author Falco Girgis
24
*/
25
26
#ifndef _TIME_H_
27
#error "Do not include this file directly. Use <time.h> instead."
28
#endif
/* !_TIME_H_ */
29
30
#ifndef __KOS_TIME_H
31
#define __KOS_TIME_H
32
33
#include <
kos/cdefs.h
>
34
35
__BEGIN_DECLS
36
37
/** \cond */
38
39
/* Required definition for a fully C23-compliant <time.h> */
40
#define __STDC_VERSION_TIME_H__ 202311L
41
42
/* Microsecond resolution for clock(), per POSIX standard.. */
43
#define CLOCKS_PER_SEC 1000000
44
45
/* =============== Enable the following for >=c11, >=c++17 =================== */
46
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
47
(defined(__cplusplus) && (__cplusplus >= 201703L))
48
49
/* Only supported base time in C11. */
50
#define TIME_UTC 1
51
52
/* C11 nanosecond-resolution timing. */
53
struct
timespec;
54
extern
int
timespec_get(
struct
timespec *ts,
int
base);
55
#endif
56
57
/* ============ Enable the following for >=C2x, >C++20+, KOS ============== */
58
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202000L)) || \
59
(defined(__cplusplus) && (__cplusplus > 202002L)) || \
60
defined(__KOS_LIBC)
61
62
/* New POSIX-equivalent base times in C23. */
63
#define TIME_MONOTONIC 2
64
#define TIME_ACTIVE 3
65
#define TIME_THREAD_ACTIVE 4
66
67
/* Query for the resolution of a time base. */
68
extern
int
timespec_getres(
struct
timespec *ts,
int
base);
69
#endif
70
71
/* ===================== Enable the following for >=c2y ================== */
72
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202300L)
73
74
/* Deprecate legacy time formatters with static internal state. */
75
struct
tm;
76
[[deprecated]]
extern
char
*asctime(
const
struct
tm *timeptr);
77
[[deprecated]]
extern
char
*ctime(
const
__time_t
*timer);
78
#endif
79
80
/* =========== Enable the following for >=c2y, >c++20, KOS ============== */
81
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202300L)) || \
82
(defined(__cplusplus) && (__cplusplus > 202002L)) || \
83
defined(__KOS_LIBC)
84
85
/* POSIX reentrant equivalents of gmtime and localtime added to C23. */
86
struct
tm;
87
extern
struct
tm *gmtime_r(
const
__time_t
*timer,
struct
tm *timeptr);
88
extern
struct
tm *localtime_r(
const
__time_t
*timer,
struct
tm *timeptr);
89
90
/* C23 added POSIX gmtime() for UTC broken-down time to a Unix timestamp. */
91
extern
__time_t
timegm(
struct
tm *timeptr);
92
93
#endif
94
95
/* =========== Enable the following for POSIX POSIX.1b (1993) =========== */
96
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
97
98
/* We do not support POSIX timers!
99
#ifndef _POSIX_TIMERS
100
#define _POSIX_TIMERS 1
101
#endif */
102
103
#ifndef _POSIX_MONOTONIC_CLOCK
104
#define _POSIX_MONOTONIC_CLOCK 1
105
#endif
106
107
#ifndef _POSIX_CPUTIME
108
#define _POSIX_CPUTIME 1
109
#endif
110
111
#ifndef _POSIX_THREAD_CPUTIME
112
#define _POSIX_THREAD_CPUTIME 1
113
#endif
114
115
/* Explicitly provided function declarations for POSIX clock API, since
116
getting them from Newlib requires supporting the rest of the _POSIX_TIMERS
117
API, which is not implemented yet. */
118
extern
int
clock_settime(
__clockid_t
clock_id,
const
struct
timespec *ts);
119
extern
int
clock_gettime(
__clockid_t
clock_id,
struct
timespec *ts);
120
extern
int
clock_getres(
__clockid_t
clock_id,
struct
timespec *res);
121
122
extern
int
nanosleep(
const
struct
timespec *req,
struct
timespec *rem);
123
124
#endif
125
126
/** \endcond */
127
128
__END_DECLS
129
130
#endif
/* !__KOS_TIME_H */
cdefs.h
Definitions for builtin attributes and compiler directives.
__clockid_t
_CLOCKID_T_ __clockid_t
Definition
_types.h:151
__time_t
_TIME_T_ __time_t
Definition
_types.h:145
include
kos
time.h
Generated by
1.12.0