source: mainline/uspace/lib/c/include/time.h@ cd1e3fc0

Last change on this file since cd1e3fc0 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jakub Jermar
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/** @addtogroup libc
8 * @{
9 */
10/** @file
11 */
12
13#ifndef _LIBC_TIME_H_
14#define _LIBC_TIME_H_
15
16#include <_bits/decls.h>
17
18/* ISO/IEC 9899:2011 7.27.1 (2) */
19
20#include <_bits/NULL.h>
21
22#define CLOCKS_PER_SEC ((clock_t) 1000000)
23
24#define TIME_UTC 1
25
26/* ISO/IEC 9899:2011 7.27.1 (3) */
27
28#include <_bits/size_t.h>
29
30__C_DECLS_BEGIN;
31
32/* ISO/IEC 9899:2011 7.27.1 (3), (4) */
33
34typedef long long time_t;
35typedef long long clock_t;
36
37struct timespec {
38 time_t tv_sec;
39 long tv_nsec;
40};
41
42struct tm {
43 int tm_sec;
44 int tm_nsec; /**< Nonstandard extension, nanoseconds since last second. */
45 int tm_min;
46 int tm_hour;
47 int tm_mday;
48 int tm_mon;
49 int tm_year;
50 int tm_wday;
51 int tm_yday;
52 int tm_isdst;
53};
54
55/* ISO/IEC 9899:2011 7.27.2.1 (1) */
56extern clock_t clock(void);
57
58/* ISO/IEC 9899:2011 7.27.2.2 (1) */
59extern double difftime(time_t, time_t);
60
61/* ISO/IEC 9899:2011 7.27.2.3 (1) */
62extern time_t mktime(struct tm *);
63
64/* ISO/IEC 9899:2011 7.27.2.4 (1) */
65extern time_t time(time_t *);
66
67/* ISO/IEC 9899:2011 7.27.2.5 (1) */
68extern int timespec_get(struct timespec *, int);
69
70/* ISO/IEC 9899:2011 7.27.3.1 (1) */
71extern char *asctime(const struct tm *);
72
73/* ISO/IEC 9899:2011 7.27.3.2 (1) */
74extern char *ctime(const time_t *);
75
76/* ISO/IEC 9899:2011 7.27.3.3 (1) */
77extern struct tm *gmtime(const time_t *);
78
79/* ISO/IEC 9899:2011 7.27.3.4 (1) */
80extern struct tm *localtime(const time_t *);
81
82/* ISO/IEC 9899:2011 7.27.3.5 (1) */
83extern size_t strftime(char *__restrict__, size_t, const char *__restrict__,
84 const struct tm *__restrict__);
85
86__C_DECLS_END;
87
88#ifdef _HELENOS_SOURCE
89
90/*
91 * HelenOS specific extensions
92 */
93
94#include <stdbool.h>
95#include <_bits/errno.h>
96
97__HELENOS_DECLS_BEGIN;
98
99typedef long long sec_t;
100typedef long long msec_t;
101typedef long long usec_t;
102typedef long long nsec_t; /* good for +/- 292 years */
103
104#define SEC2MSEC(s) ((s) * 1000ll)
105#define SEC2USEC(s) ((s) * 1000000ll)
106#define SEC2NSEC(s) ((s) * 1000000000ll)
107
108#define MSEC2SEC(ms) ((ms) / 1000ll)
109#define MSEC2USEC(ms) ((ms) * 1000ll)
110#define MSEC2NSEC(ms) ((ms) * 1000000ll)
111
112#define USEC2SEC(us) ((us) / 1000000ll)
113#define USEC2MSEC(us) ((us) / 1000ll)
114#define USEC2NSEC(us) ((us) * 1000ll)
115
116#define NSEC2SEC(ns) ((ns) / 1000000000ll)
117#define NSEC2MSEC(ns) ((ns) / 1000000ll)
118#define NSEC2USEC(ns) ((ns) / 1000ll)
119
120extern void getuptime(struct timespec *);
121extern void getrealtime(struct timespec *);
122
123extern void ts_add_diff(struct timespec *, nsec_t);
124extern void ts_add(struct timespec *, const struct timespec *);
125extern void ts_sub(struct timespec *, const struct timespec *);
126extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
127extern bool ts_gt(const struct timespec *, const struct timespec *);
128extern bool ts_gteq(const struct timespec *, const struct timespec *);
129
130extern errno_t time_utc2tm(const time_t, struct tm *);
131extern errno_t time_utc2str(const time_t, char *);
132extern void time_tm2str(const struct tm *, char *);
133extern errno_t time_ts2tm(const struct timespec *, struct tm *);
134extern errno_t time_local2tm(const time_t, struct tm *);
135extern errno_t time_local2str(const time_t, char *);
136
137extern void udelay(sysarg_t);
138
139__HELENOS_DECLS_END;
140
141#endif /* _HELENOS_SOURCE */
142
143#endif
144
145/** @}
146 */
Note: See TracBrowser for help on using the repository browser.