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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 967e7a1 was 4805495, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Make sure libc and abi header guards are reserved identifiers

It's only needed for a small subset that end up included from standard
headers, but for consistency this changes all of them.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2018 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#ifndef _LIBC_TIME_H_
36#define _LIBC_TIME_H_
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* ISO/IEC 9899:2011 7.27.1 (2) */
43
44#include <_bits/NULL.h>
45
46#define CLOCKS_PER_SEC ((clock_t) 1000000)
47
48#define TIME_UTC 1
49
50/* ISO/IEC 9899:2011 7.27.1 (3) */
51
52#include <_bits/size_t.h>
53
54/* ISO/IEC 9899:2011 7.27.1 (3), (4) */
55
56typedef long long time_t;
57typedef long long clock_t;
58
59struct timespec {
60 time_t tv_sec;
61 long tv_nsec;
62};
63
64struct tm {
65 int tm_sec;
66 int tm_nsec; /**< Nonstandard extension, nanoseconds since last second. */
67 int tm_min;
68 int tm_hour;
69 int tm_mday;
70 int tm_mon;
71 int tm_year;
72 int tm_wday;
73 int tm_yday;
74 int tm_isdst;
75};
76
77/* ISO/IEC 9899:2011 7.27.2.1 (1) */
78extern clock_t clock(void);
79
80/* ISO/IEC 9899:2011 7.27.2.2 (1) */
81extern double difftime(time_t, time_t);
82
83/* ISO/IEC 9899:2011 7.27.2.3 (1) */
84extern time_t mktime(struct tm *);
85
86/* ISO/IEC 9899:2011 7.27.2.4 (1) */
87extern time_t time(time_t *);
88
89/* ISO/IEC 9899:2011 7.27.2.5 (1) */
90extern int timespec_get(struct timespec *, int);
91
92/* ISO/IEC 9899:2011 7.27.3.1 (1) */
93extern char *asctime(const struct tm *);
94
95/* ISO/IEC 9899:2011 7.27.3.2 (1) */
96extern char *ctime(const time_t *);
97
98/* ISO/IEC 9899:2011 7.27.3.3 (1) */
99extern struct tm *gmtime(const time_t *);
100
101/* ISO/IEC 9899:2011 7.27.3.4 (1) */
102extern struct tm *localtime(const time_t *);
103
104/* ISO/IEC 9899:2011 7.27.3.5 (1) */
105extern size_t strftime(char *__restrict__, size_t, const char *__restrict__,
106 const struct tm *__restrict__);
107
108#ifdef _HELENOS_SOURCE
109
110/*
111 * HelenOS specific extensions
112 */
113
114#include <stdbool.h>
115#include <_bits/errno.h>
116
117typedef long long sec_t;
118typedef long long msec_t;
119typedef long long usec_t;
120typedef long long nsec_t; /* good for +/- 292 years */
121
122#define SEC2MSEC(s) ((s) * 1000ll)
123#define SEC2USEC(s) ((s) * 1000000ll)
124#define SEC2NSEC(s) ((s) * 1000000000ll)
125
126#define MSEC2SEC(ms) ((ms) / 1000ll)
127#define MSEC2USEC(ms) ((ms) * 1000ll)
128#define MSEC2NSEC(ms) ((ms) * 1000000ll)
129
130#define USEC2SEC(us) ((us) / 1000000ll)
131#define USEC2MSEC(us) ((us) / 1000ll)
132#define USEC2NSEC(us) ((us) * 1000ll)
133
134#define NSEC2SEC(ns) ((ns) / 1000000000ll)
135#define NSEC2MSEC(ns) ((ns) / 1000000ll)
136#define NSEC2USEC(ns) ((ns) / 1000ll)
137
138extern void getuptime(struct timespec *);
139extern void getrealtime(struct timespec *);
140
141extern void ts_add_diff(struct timespec *, nsec_t);
142extern void ts_add(struct timespec *, const struct timespec *);
143extern void ts_sub(struct timespec *, const struct timespec *);
144extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
145extern bool ts_gt(const struct timespec *, const struct timespec *);
146extern bool ts_gteq(const struct timespec *, const struct timespec *);
147
148extern errno_t time_utc2tm(const time_t, struct tm *);
149extern errno_t time_utc2str(const time_t, char *);
150extern void time_tm2str(const struct tm *, char *);
151extern errno_t time_ts2tm(const struct timespec *, struct tm *);
152extern errno_t time_local2tm(const time_t, struct tm *);
153extern errno_t time_local2str(const time_t, char *);
154
155extern void udelay(sysarg_t);
156
157#endif /* _HELENOS_SOURCE */
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif
164
165/** @}
166 */
Note: See TracBrowser for help on using the repository browser.