[813a703] | 1 | /*
|
---|
[205f1add] | 2 | * Copyright (c) 2018 Jakub Jermar
|
---|
[813a703] | 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
|
---|
[5b0cf63] | 33 | */
|
---|
[813a703] | 34 |
|
---|
| 35 | #ifndef LIBC_TIME_H_
|
---|
| 36 | #define LIBC_TIME_H_
|
---|
| 37 |
|
---|
[82fd245] | 38 | #ifdef __cplusplus
|
---|
| 39 | extern "C" {
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
[813a703] | 42 |
|
---|
[205f1add] | 43 | /* ISO/IEC 9899:2011 7.27.1 (2) */
|
---|
| 44 |
|
---|
| 45 | #include <_bits/NULL.h>
|
---|
| 46 |
|
---|
[cc36562b] | 47 | #define CLOCKS_PER_SEC ((clock_t) 1000000)
|
---|
[205f1add] | 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 |
|
---|
| 58 | typedef long long time_t;
|
---|
| 59 | typedef long long clock_t;
|
---|
| 60 |
|
---|
| 61 | struct timespec {
|
---|
| 62 | time_t tv_sec;
|
---|
| 63 | long tv_nsec;
|
---|
| 64 | };
|
---|
| 65 |
|
---|
| 66 | struct tm {
|
---|
| 67 | int tm_sec;
|
---|
| 68 | int tm_nsec;
|
---|
| 69 | int tm_min;
|
---|
| 70 | int tm_hour;
|
---|
| 71 | int tm_mday;
|
---|
| 72 | int tm_mon;
|
---|
| 73 | int tm_year;
|
---|
| 74 | int tm_wday;
|
---|
| 75 | int tm_yday;
|
---|
| 76 | int tm_isdst;
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | /* ISO/IEC 9899:2011 7.27.2.1 (1) */
|
---|
| 80 | extern clock_t clock(void);
|
---|
| 81 |
|
---|
| 82 | /* ISO/IEC 9899:2011 7.27.2.2 (1) */
|
---|
| 83 | extern double difftime(time_t, time_t);
|
---|
| 84 |
|
---|
| 85 | /* ISO/IEC 9899:2011 7.27.2.3 (1) */
|
---|
| 86 | extern time_t mktime(struct tm *);
|
---|
| 87 |
|
---|
| 88 | /* ISO/IEC 9899:2011 7.27.2.4 (1) */
|
---|
[813a703] | 89 | extern time_t time(time_t *);
|
---|
| 90 |
|
---|
[205f1add] | 91 | /* ISO/IEC 9899:2011 7.27.2.5 (1) */
|
---|
| 92 | extern int timespec_get(struct timespec *, int);
|
---|
| 93 |
|
---|
| 94 | /* ISO/IEC 9899:2011 7.27.3.1 (1) */
|
---|
| 95 | extern char *asctime(const struct tm *);
|
---|
| 96 |
|
---|
| 97 | /* ISO/IEC 9899:2011 7.27.3.2 (1) */
|
---|
| 98 | extern char *ctime(const time_t *);
|
---|
| 99 |
|
---|
| 100 | /* ISO/IEC 9899:2011 7.27.3.3 (1) */
|
---|
| 101 | extern struct tm *gmtime(const time_t *);
|
---|
| 102 |
|
---|
| 103 | /* ISO/IEC 9899:2011 7.27.3.4 (1) */
|
---|
| 104 | extern struct tm *localtime(const time_t *);
|
---|
| 105 |
|
---|
| 106 | /* ISO/IEC 9899:2011 7.27.3.5 (1) */
|
---|
| 107 | extern size_t strftime(char *, size_t, const char *, const struct tm *);
|
---|
| 108 |
|
---|
| 109 | /*
|
---|
| 110 | * HelenOS specific extensions
|
---|
| 111 | */
|
---|
| 112 |
|
---|
| 113 | #include <stdbool.h>
|
---|
| 114 | #include <_bits/errno.h>
|
---|
| 115 |
|
---|
| 116 | typedef long long sec_t;
|
---|
| 117 | typedef long long msec_t;
|
---|
| 118 | typedef long long usec_t;
|
---|
| 119 | typedef long long nsec_t; /* good for +/- 292 years */
|
---|
| 120 |
|
---|
| 121 | #define SEC2MSEC(s) ((s) * 1000ll)
|
---|
| 122 | #define SEC2USEC(s) ((s) * 1000000ll)
|
---|
| 123 | #define SEC2NSEC(s) ((s) * 1000000000ll)
|
---|
| 124 |
|
---|
| 125 | #define MSEC2SEC(ms) ((ms) / 1000ll)
|
---|
| 126 | #define MSEC2USEC(ms) ((ms) * 1000ll)
|
---|
| 127 | #define MSEC2NSEC(ms) ((ms) * 1000000ll)
|
---|
| 128 |
|
---|
| 129 | #define USEC2SEC(us) ((us) / 1000000ll)
|
---|
| 130 | #define USEC2MSEC(us) ((us) / 1000ll)
|
---|
| 131 | #define USEC2NSEC(us) ((us) * 1000ll)
|
---|
| 132 |
|
---|
| 133 | #define NSEC2SEC(ns) ((ns) / 1000000000ll)
|
---|
| 134 | #define NSEC2MSEC(ns) ((ns) / 1000000ll)
|
---|
| 135 | #define NSEC2USEC(ns) ((ns) / 1000ll)
|
---|
| 136 |
|
---|
| 137 | extern void getuptime(struct timespec *);
|
---|
| 138 | extern void getrealtime(struct timespec *);
|
---|
| 139 |
|
---|
| 140 | extern void ts_add_diff(struct timespec *, nsec_t);
|
---|
| 141 | extern void ts_add(struct timespec *, const struct timespec *);
|
---|
| 142 | extern void ts_sub(struct timespec *, const struct timespec *);
|
---|
| 143 | extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
|
---|
| 144 | extern bool ts_gt(const struct timespec *, const struct timespec *);
|
---|
| 145 | extern bool ts_gteq(const struct timespec *, const struct timespec *);
|
---|
| 146 |
|
---|
| 147 | extern errno_t time_utc2tm(const time_t, struct tm *);
|
---|
| 148 | extern errno_t time_utc2str(const time_t, char *);
|
---|
| 149 | extern void time_tm2str(const struct tm *, char *);
|
---|
| 150 | extern errno_t time_ts2tm(const struct timespec *, struct tm *);
|
---|
| 151 | extern errno_t time_local2tm(const time_t, struct tm *);
|
---|
| 152 | extern errno_t time_local2str(const time_t, char *);
|
---|
| 153 |
|
---|
| 154 | extern void udelay(usec_t);
|
---|
| 155 |
|
---|
[82fd245] | 156 | #ifdef __cplusplus
|
---|
| 157 | }
|
---|
| 158 | #endif
|
---|
| 159 |
|
---|
[813a703] | 160 | #endif
|
---|
| 161 |
|
---|
| 162 | /** @}
|
---|
| 163 | */
|
---|