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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d2c91ab was d2c91ab, checked in by Jakub Jermar <jakub@…>, 7 years ago

Add restrict to strftime() declaration

  • 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
43/* ISO/IEC 9899:2011 7.27.1 (2) */
44
45#include <_bits/NULL.h>
46
47#define CLOCKS_PER_SEC ((clock_t) 1000000)
48
49#define TIME_UTC 1
50
51
52/* ISO/IEC 9899:2011 7.27.1 (3) */
53
54#include <_bits/size_t.h>
55
56/* ISO/IEC 9899:2011 7.27.1 (3), (4) */
57
58typedef long long time_t;
59typedef long long clock_t;
60
61struct timespec {
62 time_t tv_sec;
63 long tv_nsec;
64};
65
66struct tm {
67 int tm_sec;
68#ifdef _HELENOS_SOURCE
69 int tm_nsec;
70#endif
71 int tm_min;
72 int tm_hour;
73 int tm_mday;
74 int tm_mon;
75 int tm_year;
76 int tm_wday;
77 int tm_yday;
78 int tm_isdst;
79};
80
81/* ISO/IEC 9899:2011 7.27.2.1 (1) */
82extern clock_t clock(void);
83
84/* ISO/IEC 9899:2011 7.27.2.2 (1) */
85extern double difftime(time_t, time_t);
86
87/* ISO/IEC 9899:2011 7.27.2.3 (1) */
88extern time_t mktime(struct tm *);
89
90/* ISO/IEC 9899:2011 7.27.2.4 (1) */
91extern time_t time(time_t *);
92
93/* ISO/IEC 9899:2011 7.27.2.5 (1) */
94extern int timespec_get(struct timespec *, int);
95
96/* ISO/IEC 9899:2011 7.27.3.1 (1) */
97extern char *asctime(const struct tm *);
98
99/* ISO/IEC 9899:2011 7.27.3.2 (1) */
100extern char *ctime(const time_t *);
101
102/* ISO/IEC 9899:2011 7.27.3.3 (1) */
103extern struct tm *gmtime(const time_t *);
104
105/* ISO/IEC 9899:2011 7.27.3.4 (1) */
106extern struct tm *localtime(const time_t *);
107
108/* ISO/IEC 9899:2011 7.27.3.5 (1) */
109extern size_t strftime(char *__restrict__, size_t, const char *__restrict__,
110 const struct tm *__restrict__);
111
112
113#ifdef _HELENOS_SOURCE
114
115/*
116 * HelenOS specific extensions
117 */
118
119#include <stdbool.h>
120#include <_bits/errno.h>
121
122typedef long long sec_t;
123typedef long long msec_t;
124typedef long long usec_t;
125typedef long long nsec_t; /* good for +/- 292 years */
126
127#define SEC2MSEC(s) ((s) * 1000ll)
128#define SEC2USEC(s) ((s) * 1000000ll)
129#define SEC2NSEC(s) ((s) * 1000000000ll)
130
131#define MSEC2SEC(ms) ((ms) / 1000ll)
132#define MSEC2USEC(ms) ((ms) * 1000ll)
133#define MSEC2NSEC(ms) ((ms) * 1000000ll)
134
135#define USEC2SEC(us) ((us) / 1000000ll)
136#define USEC2MSEC(us) ((us) / 1000ll)
137#define USEC2NSEC(us) ((us) * 1000ll)
138
139#define NSEC2SEC(ns) ((ns) / 1000000000ll)
140#define NSEC2MSEC(ns) ((ns) / 1000000ll)
141#define NSEC2USEC(ns) ((ns) / 1000ll)
142
143extern void getuptime(struct timespec *);
144extern void getrealtime(struct timespec *);
145
146extern void ts_add_diff(struct timespec *, nsec_t);
147extern void ts_add(struct timespec *, const struct timespec *);
148extern void ts_sub(struct timespec *, const struct timespec *);
149extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
150extern bool ts_gt(const struct timespec *, const struct timespec *);
151extern bool ts_gteq(const struct timespec *, const struct timespec *);
152
153extern errno_t time_utc2tm(const time_t, struct tm *);
154extern errno_t time_utc2str(const time_t, char *);
155extern void time_tm2str(const struct tm *, char *);
156extern errno_t time_ts2tm(const struct timespec *, struct tm *);
157extern errno_t time_local2tm(const time_t, struct tm *);
158extern errno_t time_local2str(const time_t, char *);
159
160extern void udelay(sysarg_t);
161
162#endif /* _HELENOS_SOURCE */
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif
169
170/** @}
171 */
Note: See TracBrowser for help on using the repository browser.