The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
sys/types.h
>
4
5
/**
6
* @file time.h
7
* @brief clocks, sleeping and calendar time (UTC only: there are no time
8
* zones, so local time is UTC).
9
*
10
* struct timespec and the clock ids are ABI (src/kernel/time/clock.h).
11
*/
12
13
#ifndef NULL
14
#define NULL ((void *)0)
15
#endif
16
17
typedef
int
clockid_t
;
18
#define CLOCK_REALTIME 0
19
#define CLOCK_MONOTONIC 1
20
#define CLOCK_PROCESS_CPUTIME_ID 2
21
22
// clock() counts in microseconds, as POSIX asks
23
#define CLOCKS_PER_SEC 1000000l
24
25
struct
timespec
26
{
27
time_t
tv_sec
;
28
long
tv_nsec
;
29
};
30
31
struct
tm
32
{
33
int
tm_sec
;
// 0-60
34
int
tm_min
;
// 0-59
35
int
tm_hour
;
// 0-23
36
int
tm_mday
;
// 1-31
37
int
tm_mon
;
// 0-11
38
int
tm_year
;
// years since 1900
39
int
tm_wday
;
// 0-6, Sunday = 0
40
int
tm_yday
;
// 0-365
41
int
tm_isdst
;
// always 0
42
long
tm_gmtoff
;
// seconds east of UTC: always 0 (ginnOS keeps UTC)
43
const
char
*
tm_zone
;
// "UTC"
44
};
45
46
time_t
time
(
time_t
*out);
47
int
clock_gettime
(
clockid_t
id
,
struct
timespec
*out);
48
49
#define TIME_UTC 1
// the base of timespec_get: CLOCK_REALTIME
50
51
/**
52
* the time now (C11).
53
* @return base (TIME_UTC), or 0 for another base.
54
*/
55
int
timespec_get
(
struct
timespec
*out,
int
base
);
56
/** set the realtime clock (root only; whole seconds) */
57
int
clock_settime
(
clockid_t
id
,
const
struct
timespec
*when);
58
int
nanosleep
(
const
struct
timespec
*span,
struct
timespec
*left);
59
clock_t
clock
(
void
);
60
double
difftime
(
time_t
end,
time_t
start);
61
62
struct
tm
*
gmtime_r
(
const
time_t
*t,
struct
tm
*out);
63
struct
tm
*
gmtime
(
const
time_t
*t);
64
struct
tm
*
localtime_r
(
const
time_t
*t,
struct
tm
*out);
65
struct
tm
*
localtime
(
const
time_t
*t);
66
time_t
timegm
(
struct
tm
*
tm
);
67
time_t
mktime
(
struct
tm
*
tm
);
68
69
char
*
asctime_r
(
const
struct
tm
*
tm
,
char
*buf);
70
char
*
asctime
(
const
struct
tm
*
tm
);
71
char
*
ctime
(
const
time_t
*t);
72
73
/**
74
* format a time. supports %a %A %b %B %c %d %e %H %I %j %m %M %n %p %S %t
75
* %u %w %y %Y %Z %z %F %T %D %R and %%.
76
* @return the length written, or 0 if it does not fit.
77
*/
78
size_t
strftime
(
char
*buf,
size_t
size,
const
char
*format,
const
struct
tm
*
tm
);
79
/**
80
* read a time from text as format says (the strftime conversions, and
81
* spaces in the format match any spaces) into the fields of tm it names.
82
* @return the first character not read, or NULL when the text does not fit.
83
*/
84
char
*
strptime
(
const
char
*restrict text,
const
char
*restrict format,
struct
tm
*restrict
tm
);
base
uint32_t base
Definition
gdt.c:1
timespec
Definition
time.h:26
timespec::tv_nsec
long tv_nsec
Definition
time.h:28
timespec::tv_sec
time_t tv_sec
Definition
time.h:27
tm
Definition
time.h:32
tm::tm_mon
int tm_mon
Definition
time.h:37
tm::tm_zone
const char * tm_zone
Definition
time.h:43
tm::tm_year
int tm_year
Definition
time.h:38
tm::tm_hour
int tm_hour
Definition
time.h:35
tm::tm_sec
int tm_sec
Definition
time.h:33
tm::tm_isdst
int tm_isdst
Definition
time.h:41
tm::tm_gmtoff
long tm_gmtoff
Definition
time.h:42
tm::tm_yday
int tm_yday
Definition
time.h:40
tm::tm_mday
int tm_mday
Definition
time.h:36
tm::tm_min
int tm_min
Definition
time.h:34
tm::tm_wday
int tm_wday
Definition
time.h:39
strftime
size_t strftime(char *buf, size_t size, const char *format, const struct tm *tm)
format a time.
gmtime
struct tm * gmtime(const time_t *t)
asctime_r
char * asctime_r(const struct tm *tm, char *buf)
timegm
time_t timegm(struct tm *tm)
localtime
struct tm * localtime(const time_t *t)
clock_gettime
int clock_gettime(clockid_t id, struct timespec *out)
clock_settime
int clock_settime(clockid_t id, const struct timespec *when)
set the realtime clock (root only; whole seconds)
clockid_t
int clockid_t
Definition
time.h:17
ctime
char * ctime(const time_t *t)
difftime
double difftime(time_t end, time_t start)
time
time_t time(time_t *out)
strptime
char * strptime(const char *restrict text, const char *restrict format, struct tm *restrict tm)
read a time from text as format says (the strftime conversions, and spaces in the format match any sp...
timespec_get
int timespec_get(struct timespec *out, int base)
the time now (C11).
nanosleep
int nanosleep(const struct timespec *span, struct timespec *left)
clock
clock_t clock(void)
localtime_r
struct tm * localtime_r(const time_t *t, struct tm *out)
gmtime_r
struct tm * gmtime_r(const time_t *t, struct tm *out)
asctime
char * asctime(const struct tm *tm)
mktime
time_t mktime(struct tm *tm)
types.h
basic system types.
clock_t
long clock_t
Definition
types.h:29
time_t
long time_t
Definition
types.h:26
src
libc
include
time.h
Generated by
1.18.0