Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
time.h
Go to the documentation of this file.
1 #ifndef _TIME_H_
2 #define _TIME_H_
3 
4 #include <_types/_time_t.h>
5 #include <stddef.h>
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #pragma mark - Types and Definitions -
12 
13 #define CLOCKS_PER_SEC 1000000L
14 
15 #define TIME_UTC 1
16 
17 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
18 #define __tm_gmtoff tm_gmtoff
19 #define __tm_zone tm_zone
20 #endif
21 
22 typedef int clockid_t;
23 typedef void* timer_t;
24 typedef unsigned long clock_t;
25 typedef unsigned useconds_t;
26 
27 #define _STRUCT_TIMESPEC
28 struct timespec
29 {
30  time_t tv_sec;
31  long tv_nsec;
32 };
33 
34 #define _STRUCT_TIMEVAL
35 struct timeval
36 {
37  time_t tv_sec;
38  suseconds_t tv_usec;
39 };
40 
41 struct tm
42 {
43  int tm_sec; /* seconds after the minute [0-60] */
44  int tm_min; /* minutes after the hour [0-59] */
45  int tm_hour; /* hours since midnight [0-23] */
46  int tm_mday; /* day of the month [1-31] */
47  int tm_mon; /* months since January [0-11] */
48  int tm_year; /* years since 1900 */
49  int tm_wday; /* days since Sunday [0-6] */
50  int tm_yday; /* days since January 1 [0-365] */
51  int tm_isdst; /* Daylight Savings Time flag */
52  long __tm_gmtoff; /* offset from CUT in seconds */
53  char* __tm_zone; /* timezone abbreviation */
54 };
55 
56 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
57  defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
58 #define CLOCK_REALTIME 0
59 #define CLOCK_MONOTONIC 1
60 #define CLOCK_PROCESS_CPUTIME_ID 2
61 #define CLOCK_THREAD_CPUTIME_ID 3
62 #define CLOCK_MONOTONIC_RAW 4
63 #define CLOCK_REALTIME_COARSE 5
64 #define CLOCK_MONOTONIC_COARSE 6
65 #define CLOCK_BOOTTIME 7
66 #define CLOCK_REALTIME_ALARM 8
67 #define CLOCK_BOOTTIME_ALARM 9
68 #define CLOCK_SGI_CYCLE 10
69 #define CLOCK_TAI 11
70 
71 #define TIMER_ABSTIME 1
72 
73 struct itimerspec
74 {
75  struct timespec it_interval;
76  struct timespec it_value;
77 };
78 
79 #endif
80 
81 #pragma mark - Functions -
82 
83 char* asctime(const struct tm*);
84 
85 #ifndef DISABLE_UNIMPLEMENTED_LIBC_APIS
86 clock_t clock(void);
87 time_t time(time_t*);
88 double difftime(time_t, time_t);
89 time_t mktime(struct tm*);
90 size_t strftime(char* __restrict, size_t, const char* __restrict, const struct tm* __restrict);
91 struct tm* gmtime(const time_t*);
92 struct tm* localtime(const time_t*);
93 
94 char* ctime(const time_t*);
95 
96 int timespec_get(struct timespec*, int);
97 #endif
98 
99 #if defined(_GNU_SOURCE) || defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
100  defined(_BSD_SOURCE)
101 char* asctime_r(const struct tm* __restrict, char* __restrict);
102 
103 #ifndef DISABLE_UNIMPLEMENTED_LIBC_APIS
104 struct tm* gmtime_r(const time_t* __restrict, struct tm* __restrict);
105 struct tm* localtime_r(const time_t* __restrict, struct tm* __restrict);
106 char* ctime_r(const time_t*, char*);
107 
108 int nanosleep(const struct timespec*, struct timespec*);
109 int clock_getres(clockid_t, struct timespec*);
110 int clock_gettime(clockid_t, struct timespec*);
111 int clock_settime(clockid_t, const struct timespec*);
112 int clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*);
113 // int clock_getcpuclockid(pid_t, clockid_t*);
114 
115 struct sigevent;
116 int timer_create(clockid_t, struct sigevent* __restrict, timer_t* __restrict);
117 int timer_delete(timer_t);
118 int timer_settime(timer_t, int, const struct itimerspec* __restrict, struct itimerspec* __restrict);
119 int timer_gettime(timer_t, struct itimerspec*);
120 int timer_getoverrun(timer_t);
121 
122 extern char* tzname[2];
123 #endif // DISABLE_UNIMPLEMENTED_LIBC_APIS
124 #endif
125 
126 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
127 #ifndef DISABLE_UNIMPLEMENTED_LIBC_APIS
128 char* strptime(const char* __restrict, const char* __restrict, struct tm* __restrict);
129 extern int daylight;
130 extern long timezone;
131 extern int getdate_err;
132 struct tm* getdate(const char*);
133 #endif // DISABLE_UNIMPLEMENTED_LIBC_APIS
134 #endif
135 
136 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
137 #ifndef DISABLE_UNIMPLEMENTED_LIBC_APIS
138 int stime(const time_t*);
139 time_t timegm(struct tm*);
140 #endif // DISABLE_UNIMPLEMENTED_LIBC_APIS
141 #endif
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* !_TIME_H_ */
Definition: time.h:28
Definition: time.h:35
int tm_hour
Definition: time.h:45
char * ctime(const time_t *)
int tm_sec
Definition: time.h:43
struct tm * gmtime(const time_t *)
int tm_mday
Definition: time.h:46
int clockid_t
Definition: time.h:22
time_t tv_sec
Definition: time.h:37
double difftime(time_t, time_t)
suseconds_t tv_usec
Definition: time.h:38
int timespec_get(struct timespec *, int)
time_t mktime(struct tm *)
long __tm_gmtoff
Definition: time.h:52
unsigned useconds_t
Definition: time.h:25
time_t time(time_t *)
unsigned long clock_t
Definition: time.h:24
long tv_nsec
Definition: time.h:31
int tm_mon
Definition: time.h:47
int tm_year
Definition: time.h:48
void * timer_t
Definition: time.h:23
char * __tm_zone
Definition: time.h:53
int tm_yday
Definition: time.h:50
int tm_wday
Definition: time.h:49
Definition: time.h:41
clock_t clock(void)
struct tm * localtime(const time_t *)
time_t tv_sec
Definition: time.h:30
char * asctime_r(const struct tm *restrict tm, char *restrict buf)
Definition: asctime_r.c:7
size_t strftime(char *__restrict, size_t, const char *__restrict, const struct tm *__restrict)
int tm_min
Definition: time.h:44
char * asctime(const struct tm *)
Definition: asctime.c:4
int tm_isdst
Definition: time.h:51