VSF Documented
time.h
Go to the documentation of this file.
1#ifndef __SIMPLE_LIBC_TIME_H__
2#define __SIMPLE_LIBC_TIME_H__
3
5
6#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED
7# if VSF_LINUX_USE_SIMPLE_LIBC == ENABLED
8# include "./stddef.h"
9# else
10# include <stddef.h>
11# endif
12// for time_t
13# include "../sys/types.h"
14// for sigevent
15# include "../signal.h"
16#else
17# include <stddef.h>
18// for time_t
19# include <sys/types.h>
20// for sigevent
21# include <signal.h>
22#endif
23
24// Note:
25// libc/time.h can not include timeval, so can not include sys/time.h,
26// or it will conflict with timeval in winsock.h.
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#if VSF_LINUX_LIBC_CFG_WRAPPER == ENABLED
33#define clock_gettime VSF_LINUX_LIBC_WRAPPER(clock_gettime)
34#define clock_settime VSF_LINUX_LIBC_WRAPPER(clock_settime)
35#define clock_getres VSF_LINUX_LIBC_WRAPPER(clock_getres)
36#define clock_nanosleep VSF_LINUX_LIBC_WRAPPER(clock_nanosleep)
37#define timer_create VSF_LINUX_LIBC_WRAPPER(timer_create)
38#define timer_settime VSF_LINUX_LIBC_WRAPPER(timer_settime)
39#define timer_gettime VSF_LINUX_LIBC_WRAPPER(timer_gettime)
40#define timer_delete VSF_LINUX_LIBC_WRAPPER(timer_delete)
41#define timer_getoverrun VSF_LINUX_LIBC_WRAPPER(timer_getoverrun)
42#define nanosleep VSF_LINUX_LIBC_WRAPPER(nanosleep)
43#define clock VSF_LINUX_LIBC_WRAPPER(clock)
44#define timespec_get VSF_LINUX_LIBC_WRAPPER(timespec_get)
45#define strftime VSF_LINUX_LIBC_WRAPPER(strftime)
46#define strptime VSF_LINUX_LIBC_WRAPPER(strptime)
47#define tzset VSF_LINUX_LIBC_WRAPPER(tzset)
48#endif
49
50#define TIMER_ABSTIME 1
51
52struct tm {
53 int tm_sec;
54 int tm_min;
57 int tm_mon;
62 long int tm_gmtoff;
63 const char *tm_zone;
64};
65
66struct timespec {
68 long tv_nsec;
69};
70
71struct itimerspec {
74};
75
76struct timespec64 {
78 long tv_nsec;
79};
80#ifdef __WIN__
81typedef struct timespec64 _timespec64;
82#endif
83
87};
88
89#if VSF_LINUX_APPLET_USE_LIBC_TIME == ENABLED
92
112
118
122# ifndef __VSF_APPLET__
124# endif
125#endif
126
127#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_LIBC_TIME_LIB__))\
128 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_APPLET_USE_LIBC_TIME == ENABLED
129
130#ifndef VSF_LINUX_APPLET_LIBC_TIME_VPLT
131# if VSF_LINUX_USE_APPLET == ENABLED
132# define VSF_LINUX_APPLET_LIBC_TIME_VPLT \
133 ((vsf_linux_libc_time_vplt_t *)(VSF_LINUX_APPLET_VPLT->libc_time_vplt))
134# else
135# define VSF_LINUX_APPLET_LIBC_TIME_VPLT \
136 ((vsf_linux_libc_time_vplt_t *)vsf_vplt((void *)0))
137# endif
138#endif
139
140#define VSF_LINUX_APPLET_LIBC_TIME_ENTRY(__NAME) \
141 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_LIBC_TIME_VPLT, __NAME)
142#define VSF_LINUX_APPLET_LIBC_TIME_IMP(...) \
143 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_LIBC_TIME_VPLT, __VA_ARGS__)
144
145VSF_LINUX_APPLET_LIBC_TIME_IMP(clock, clock_t, void) {
147 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock)();
148}
149VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_gettime, int, clockid_t clockid, struct timespec *ts) {
151 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_gettime)(clockid, ts);
152}
153VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_settime, int, clockid_t clockid, const struct timespec *ts) {
155 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_settime)(clockid, ts);
156}
157VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_getres, int, clockid_t clockid, struct timespec *res) {
159 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_getres)(clockid, res);
160}
161VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_nanosleep, int, clockid_t clockid, int flags, const struct timespec *request, struct timespec *remain) {
163 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_nanosleep)(clockid, flags, request, remain);
164}
165VSF_LINUX_APPLET_LIBC_TIME_IMP(time, time_t, time_t *t) {
167 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(time)(t);
168}
169VSF_LINUX_APPLET_LIBC_TIME_IMP(difftime, double, time_t time1, time_t time2) {
171 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(difftime)(time1, time2);
172}
173VSF_LINUX_APPLET_LIBC_TIME_IMP(asctime, char *, const struct tm *tm) {
175 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(asctime)(tm);
176}
177VSF_LINUX_APPLET_LIBC_TIME_IMP(asctime_r, char *, const struct tm *tm, char *buf) {
179 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(asctime_r)(tm, buf);
180}
181VSF_LINUX_APPLET_LIBC_TIME_IMP(ctime, char *, const time_t *t) {
183 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(ctime)(t);
184}
185VSF_LINUX_APPLET_LIBC_TIME_IMP(ctime_r, char *, const time_t *t, char *buf) {
187 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(ctime_r)(t, buf);
188}
189VSF_LINUX_APPLET_LIBC_TIME_IMP(gmtime, struct tm *, const time_t *t) {
191 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(gmtime)(t);
192}
193VSF_LINUX_APPLET_LIBC_TIME_IMP(gmtime_r, struct tm *, const time_t *t, struct tm *result) {
195 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(gmtime_r)(t, result);
196}
197VSF_LINUX_APPLET_LIBC_TIME_IMP(localtime, struct tm *, const time_t *t) {
199 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(localtime)(t);
200}
201VSF_LINUX_APPLET_LIBC_TIME_IMP(localtime_r, struct tm *, const time_t *t, struct tm *result) {
203 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(localtime_r)(t, result);
204}
205VSF_LINUX_APPLET_LIBC_TIME_IMP(mktime, time_t, struct tm *tm) {
207 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(mktime)(tm);
208}
209VSF_LINUX_APPLET_LIBC_TIME_IMP(strftime, size_t, char *str, size_t maxsize, const char *format, const struct tm *tm) {
211 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(strftime)(str, maxsize, format, tm);
212}
213VSF_LINUX_APPLET_LIBC_TIME_IMP(strptime, char *, const char *str, const char *format, struct tm *tm) {
215 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(strptime)(str, format, tm);
216}
217VSF_LINUX_APPLET_LIBC_TIME_IMP(nanosleep, int, const struct timespec *requested_time, struct timespec *remaining) {
219 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(nanosleep)(requested_time, remaining);
220}
221VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_create, int, clockid_t clockid, struct sigevent *sevp, timer_t *timerid) {
223 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_create)(clockid, sevp, timerid);
224}
225VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_delete, int, timer_t timerid) {
227 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_delete)(timerid);
228}
229VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_settime, int, timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) {
231 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_settime)(timerid, flags, new_value, old_value);
232}
233VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_gettime, int, timer_t timerid, struct itimerspec *curr_value) {
235 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_gettime)(timerid, curr_value);
236}
237VSF_LINUX_APPLET_LIBC_TIME_IMP(timespec_get, int, struct timespec *ts, int base) {
239 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timespec_get)(ts, base);
240}
241VSF_LINUX_APPLET_LIBC_TIME_IMP(tzset, void, void) {
243 VSF_LINUX_APPLET_LIBC_TIME_ENTRY(tzset)();
244}
245
246#else // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_TIME
247
248clock_t clock(void);
249int clock_gettime(clockid_t clockid, struct timespec *ts);
250int clock_settime(clockid_t clockid, const struct timespec *ts);
251int clock_getres(clockid_t clockid, struct timespec *res);
252int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request,
253 struct timespec *remain);
254
255int timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid);
256int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value,
257 struct itimerspec *old_value);
258int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
259int timer_getoverrun(timer_t timerid);
260int timer_delete(timer_t timerid);
261
262time_t time(time_t *t);
263double difftime(time_t time1, time_t time2);
264
265char *asctime(const struct tm *tm);
266char *asctime_r(const struct tm *tm, char *buf);
267
268char *ctime(const time_t *t);
269char *ctime_r(const time_t *t, char *buf);
270
271struct tm *gmtime(const time_t *t);
272struct tm *gmtime_r(const time_t *t, struct tm *result);
273
274struct tm *localtime(const time_t *t);
275struct tm *localtime_r(const time_t *t, struct tm *result);
276
277time_t mktime(struct tm *tm);
278size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *tm);
279char * strptime(const char *str, const char *format, struct tm *tm);
280
281int nanosleep(const struct timespec *requested_time, struct timespec *remaining);
282
283int timespec_get(struct timespec *ts, int base);
284void tzset(void);
285extern char *tzname[2];
286extern long timezong;
287extern int daylight;
288
289#endif // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_TIME
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif
__CLOCK_T clock_t
Definition types.h:132
clockid_t
Definition types.h:138
void * timer_t
Definition types.h:104
__TIME64_T time64_t
Definition types.h:127
__TIME_T time_t
Definition types.h:122
#define clock_nanosleep
Definition time.h:36
struct tm * gmtime(const time_t *t)
Definition vsf_linux_glibc_time.c:338
double difftime(time_t time1, time_t time2)
char * asctime_r(const struct tm *tm, char *buf)
Definition vsf_linux_glibc_time.c:266
#define clock_getres
Definition time.h:35
#define timer_getoverrun
Definition time.h:41
char * tzname[2]
Definition vsf_linux_glibc_time.c:44
struct tm * localtime_r(const time_t *t, struct tm *result)
Definition vsf_linux_glibc_time.c:343
#define clock_gettime
Definition time.h:33
struct tm * localtime(const time_t *t)
Definition vsf_linux_glibc_time.c:348
#define clock_settime
Definition time.h:34
#define clock
Definition time.h:43
#define tzset
Definition time.h:47
char * ctime(const time_t *t)
Definition vsf_linux_glibc_time.c:278
#define timer_create
Definition time.h:37
int daylight
Definition vsf_linux_glibc_time.c:46
long timezong
Definition vsf_linux_glibc_time.c:45
char * ctime_r(const time_t *t, char *buf)
Definition vsf_linux_glibc_time.c:283
#define nanosleep
Definition time.h:42
#define timer_delete
Definition time.h:40
#define timer_settime
Definition time.h:38
#define timer_gettime
Definition time.h:39
#define strftime
Definition time.h:45
struct tm * gmtime_r(const time_t *t, struct tm *result)
Definition vsf_linux_glibc_time.c:288
__VSF_VPLT_DECORATOR__ vsf_linux_libc_time_vplt_t vsf_linux_libc_time_vplt
Definition vsf_linux_glibc_time.c:635
time_t time(time_t *t)
Definition vsf_linux_glibc_time.c:89
#define strptime
Definition time.h:46
char * asctime(const struct tm *tm)
Definition vsf_linux_glibc_time.c:271
time_t mktime(struct tm *tm)
Definition vsf_linux_glibc_time.c:70
#define timespec_get
Definition time.h:44
Definition time.h:84
struct timespec64 it_interval
Definition time.h:85
struct timespec64 it_value
Definition time.h:86
Definition time.h:71
struct timespec it_interval
Definition time.h:72
struct timespec it_value
Definition time.h:73
Definition signal.h:57
Definition time.h:76
time64_t tv_sec
Definition time.h:77
long tv_nsec
Definition time.h:78
Definition time.h:66
long tv_nsec
Definition time.h:68
time_t tv_sec
Definition time.h:67
Definition time.h:52
int tm_mon
Definition time.h:57
const char * tm_zone
Definition time.h:63
int tm_year
Definition time.h:58
int tm_hour
Definition time.h:55
int tm_sec
Definition time.h:53
int tm_isdst
Definition time.h:61
int tm_yday
Definition time.h:60
long int tm_gmtoff
Definition time.h:62
int tm_mday
Definition time.h:56
int tm_min
Definition time.h:54
int tm_wday
Definition time.h:59
Definition time.h:90
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timespec_get)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(nanosleep)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timer_gettime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(asctime_r)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timer_getoverrun)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(clock_settime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(clock_getres)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(clock_nanosleep)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timer_delete)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timer_settime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(timer_create)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strptime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(localtime_r)
vsf_vplt_info_t info
Definition time.h:91
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(gmtime_r)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(difftime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(asctime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(strftime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(clock_gettime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(localtime)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(ctime_r)
Definition vsf_cfg.h:95
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165
SDL_PixelFormat format
Definition vsf_sdl2_pixelformat.c:32