The manual
ginnOS
The reference: libc, the libraries and the kernel
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
17typedef 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
26{
28 long tv_nsec;
29};
30
31struct 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
47int 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 */
55int timespec_get(struct timespec *out, int base);
56/** set the realtime clock (root only; whole seconds) */
57int clock_settime(clockid_t id, const struct timespec *when);
58int nanosleep(const struct timespec *span, struct timespec *left);
60double difftime(time_t end, time_t start);
61
62struct tm *gmtime_r(const time_t *t, struct tm *out);
63struct tm *gmtime(const time_t *t);
64struct tm *localtime_r(const time_t *t, struct tm *out);
65struct tm *localtime(const time_t *t);
66time_t timegm(struct tm *tm);
67time_t mktime(struct tm *tm);
68
69char *asctime_r(const struct tm *tm, char *buf);
70char *asctime(const struct tm *tm);
71char *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 */
78size_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 */
84char *strptime(const char *restrict text, const char *restrict format, struct tm *restrict tm);
uint32_t base
Definition gdt.c:1
Definition time.h:26
long tv_nsec
Definition time.h:28
time_t tv_sec
Definition time.h:27
Definition time.h:32
int tm_mon
Definition time.h:37
const char * tm_zone
Definition time.h:43
int tm_year
Definition time.h:38
int tm_hour
Definition time.h:35
int tm_sec
Definition time.h:33
int tm_isdst
Definition time.h:41
long tm_gmtoff
Definition time.h:42
int tm_yday
Definition time.h:40
int tm_mday
Definition time.h:36
int tm_min
Definition time.h:34
int tm_wday
Definition time.h:39
size_t strftime(char *buf, size_t size, const char *format, const struct tm *tm)
format a time.
struct tm * gmtime(const time_t *t)
char * asctime_r(const struct tm *tm, char *buf)
time_t timegm(struct tm *tm)
struct tm * localtime(const time_t *t)
int clock_gettime(clockid_t id, struct timespec *out)
int clock_settime(clockid_t id, const struct timespec *when)
set the realtime clock (root only; whole seconds)
int clockid_t
Definition time.h:17
char * ctime(const time_t *t)
double difftime(time_t end, time_t start)
time_t time(time_t *out)
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...
int timespec_get(struct timespec *out, int base)
the time now (C11).
int nanosleep(const struct timespec *span, struct timespec *left)
clock_t clock(void)
struct tm * localtime_r(const time_t *t, struct tm *out)
struct tm * gmtime_r(const time_t *t, struct tm *out)
char * asctime(const struct tm *tm)
time_t mktime(struct tm *tm)
basic system types.
long clock_t
Definition types.h:29
long time_t
Definition types.h:26