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#define timegm VSF_LINUX_LIBC_WRAPPER(timegm)
49#endif
50
51#define TIMER_ABSTIME 1
52
53struct tm {
54 int tm_sec;
55 int tm_min;
58 int tm_mon;
63 long int tm_gmtoff;
64 const char *tm_zone;
65};
66
67struct timespec {
69 long tv_nsec;
70};
71
76
81#ifdef __WIN__
82typedef struct timespec64 _timespec64;
83#endif
84
89
90#if VSF_LINUX_APPLET_USE_LIBC_TIME == ENABLED
125# ifndef __VSF_APPLET__
127# endif
128#endif
129
130#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_LIBC_TIME_LIB__))\
131 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_APPLET_USE_LIBC_TIME == ENABLED
132
133#ifndef VSF_LINUX_APPLET_LIBC_TIME_VPLT
134# if VSF_LINUX_USE_APPLET == ENABLED
135# define VSF_LINUX_APPLET_LIBC_TIME_VPLT \
136 ((vsf_linux_libc_time_vplt_t *)(VSF_LINUX_APPLET_VPLT->libc_time_vplt))
137# else
138# define VSF_LINUX_APPLET_LIBC_TIME_VPLT \
139 ((vsf_linux_libc_time_vplt_t *)vsf_vplt((void *)0))
140# endif
141#endif
142
143#define VSF_LINUX_APPLET_LIBC_TIME_ENTRY(__NAME) \
144 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_LIBC_TIME_VPLT, __NAME)
145#define VSF_LINUX_APPLET_LIBC_TIME_IMP(...) \
146 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_LIBC_TIME_VPLT, __VA_ARGS__)
147
148VSF_LINUX_APPLET_LIBC_TIME_IMP(clock, clock_t, void) {
150 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock)();
151}
152VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_gettime, int, clockid_t clockid, struct timespec *ts) {
154 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_gettime)(clockid, ts);
155}
156VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_settime, int, clockid_t clockid, const struct timespec *ts) {
158 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_settime)(clockid, ts);
159}
160VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_getres, int, clockid_t clockid, struct timespec *res) {
162 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_getres)(clockid, res);
163}
164VSF_LINUX_APPLET_LIBC_TIME_IMP(clock_nanosleep, int, clockid_t clockid, int flags, const struct timespec *request, struct timespec *remain) {
166 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(clock_nanosleep)(clockid, flags, request, remain);
167}
168VSF_LINUX_APPLET_LIBC_TIME_IMP(time, time_t, time_t *t) {
170 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(time)(t);
171}
172VSF_LINUX_APPLET_LIBC_TIME_IMP(difftime, double, time_t time1, time_t time2) {
174 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(difftime)(time1, time2);
175}
176VSF_LINUX_APPLET_LIBC_TIME_IMP(asctime, char *, const struct tm *tm) {
178 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(asctime)(tm);
179}
180VSF_LINUX_APPLET_LIBC_TIME_IMP(asctime_r, char *, const struct tm *tm, char *buf) {
182 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(asctime_r)(tm, buf);
183}
184VSF_LINUX_APPLET_LIBC_TIME_IMP(ctime, char *, const time_t *t) {
186 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(ctime)(t);
187}
188VSF_LINUX_APPLET_LIBC_TIME_IMP(ctime_r, char *, const time_t *t, char *buf) {
190 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(ctime_r)(t, buf);
191}
192VSF_LINUX_APPLET_LIBC_TIME_IMP(gmtime, struct tm *, const time_t *t) {
194 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(gmtime)(t);
195}
196VSF_LINUX_APPLET_LIBC_TIME_IMP(gmtime_r, struct tm *, const time_t *t, struct tm *result) {
198 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(gmtime_r)(t, result);
199}
200VSF_LINUX_APPLET_LIBC_TIME_IMP(localtime, struct tm *, const time_t *t) {
202 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(localtime)(t);
203}
204VSF_LINUX_APPLET_LIBC_TIME_IMP(localtime_r, struct tm *, const time_t *t, struct tm *result) {
206 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(localtime_r)(t, result);
207}
208VSF_LINUX_APPLET_LIBC_TIME_IMP(mktime, time_t, struct tm *tm) {
210 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(mktime)(tm);
211}
212VSF_LINUX_APPLET_LIBC_TIME_IMP(strftime, size_t, char *str, size_t maxsize, const char *format, const struct tm *tm) {
214 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(strftime)(str, maxsize, format, tm);
215}
216VSF_LINUX_APPLET_LIBC_TIME_IMP(strptime, char *, const char *str, const char *format, struct tm *tm) {
218 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(strptime)(str, format, tm);
219}
220VSF_LINUX_APPLET_LIBC_TIME_IMP(nanosleep, int, const struct timespec *requested_time, struct timespec *remaining) {
222 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(nanosleep)(requested_time, remaining);
223}
224VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_create, int, clockid_t clockid, struct sigevent *sevp, timer_t *timerid) {
226 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_create)(clockid, sevp, timerid);
227}
228VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_delete, int, timer_t timerid) {
230 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_delete)(timerid);
231}
232VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_settime, int, timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) {
234 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_settime)(timerid, flags, new_value, old_value);
235}
236VSF_LINUX_APPLET_LIBC_TIME_IMP(timer_gettime, int, timer_t timerid, struct itimerspec *curr_value) {
238 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timer_gettime)(timerid, curr_value);
239}
240VSF_LINUX_APPLET_LIBC_TIME_IMP(timespec_get, int, struct timespec *ts, int base) {
242 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timespec_get)(ts, base);
243}
244VSF_LINUX_APPLET_LIBC_TIME_IMP(tzset, void, void) {
246 VSF_LINUX_APPLET_LIBC_TIME_ENTRY(tzset)();
247}
248VSF_LINUX_APPLET_LIBC_TIME_IMP(timegm, time_t, struct tm *tm) {
250 return VSF_LINUX_APPLET_LIBC_TIME_ENTRY(timegm)(tm);
251}
252
253#else // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_TIME
254
255clock_t clock(void);
256int clock_gettime(clockid_t clockid, struct timespec *ts);
257int clock_settime(clockid_t clockid, const struct timespec *ts);
258int clock_getres(clockid_t clockid, struct timespec *res);
259int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request,
260 struct timespec *remain);
261
262int timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid);
263int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value,
264 struct itimerspec *old_value);
265int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
266int timer_getoverrun(timer_t timerid);
267int timer_delete(timer_t timerid);
268
269time_t time(time_t *t);
270double difftime(time_t time1, time_t time2);
271
272char *asctime(const struct tm *tm);
273char *asctime_r(const struct tm *tm, char *buf);
274
275char *ctime(const time_t *t);
276char *ctime_r(const time_t *t, char *buf);
277
278struct tm *gmtime(const time_t *t);
279struct tm *gmtime_r(const time_t *t, struct tm *result);
280
281time_t timegm(struct tm *tm);
282
283struct tm *localtime(const time_t *t);
284struct tm *localtime_r(const time_t *t, struct tm *result);
285
286time_t mktime(struct tm *tm);
287size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *tm);
288char * strptime(const char *str, const char *format, struct tm *tm);
289
290int nanosleep(const struct timespec *requested_time, struct timespec *remaining);
291
292int timespec_get(struct timespec *ts, int base);
293void tzset(void);
294extern char *tzname[2];
295extern long timezong;
296extern int daylight;
297
298#endif // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_TIME
299
300#ifdef __cplusplus
301}
302#endif
303
304#endif
__CLOCK_T clock_t
Definition types.h:162
clockid_t
Definition types.h:168
void * timer_t
Definition types.h:133
__TIME64_T time64_t
Definition types.h:157
__TIME_T time_t
Definition types.h:152
#define clock_nanosleep
Definition time.h:36
struct tm * gmtime(const time_t *t)
Definition vsf_linux_glibc_time.c:366
double difftime(time_t time1, time_t time2)
struct vsf_linux_libc_time_vplt_t vsf_linux_libc_time_vplt_t
char * asctime_r(const struct tm *tm, char *buf)
Definition vsf_linux_glibc_time.c:294
#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:371
#define clock_gettime
Definition time.h:33
struct tm * localtime(const time_t *t)
Definition vsf_linux_glibc_time.c:376
#define clock_settime
Definition time.h:34
#define clock
Definition time.h:43
#define tzset
Definition time.h:47
#define timegm
Definition time.h:48
char * ctime(const time_t *t)
Definition vsf_linux_glibc_time.c:306
#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:311
#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:316
__VSF_VPLT_DECORATOR__ vsf_linux_libc_time_vplt_t vsf_linux_libc_time_vplt
Definition vsf_linux_glibc_time.c:687
time_t time(time_t *t)
Definition vsf_linux_glibc_time.c:112
#define strptime
Definition time.h:46
char * asctime(const struct tm *tm)
Definition vsf_linux_glibc_time.c:299
time_t mktime(struct tm *tm)
Definition vsf_linux_glibc_time.c:86
#define timespec_get
Definition time.h:44
Definition time.h:85
struct timespec64 it_interval
Definition time.h:86
struct timespec64 it_value
Definition time.h:87
Definition time.h:72
struct timespec it_interval
Definition time.h:73
struct timespec it_value
Definition time.h:74
Definition signal.h:57
Definition time.h:77
time64_t tv_sec
Definition time.h:78
long tv_nsec
Definition time.h:79
Definition time.h:67
long tv_nsec
Definition time.h:69
time_t tv_sec
Definition time.h:68
Definition time.h:53
int tm_mon
Definition time.h:58
const char * tm_zone
Definition time.h:64
int tm_year
Definition time.h:59
int tm_hour
Definition time.h:56
int tm_sec
Definition time.h:54
int tm_isdst
Definition time.h:62
int tm_yday
Definition time.h:61
long int tm_gmtoff
Definition time.h:63
int tm_mday
Definition time.h:57
int tm_min
Definition time.h:55
int tm_wday
Definition time.h:60
Definition time.h:91
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_MOD_DEF(libc_time)
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:92
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
Generated from commit: vsfteam/vsf@2a137b0