| 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 |
|
|---|
| 34 | typedef long long time_t;
|
|---|
| 35 | typedef long long clock_t;
|
|---|
| 36 |
|
|---|
| 37 | struct timespec {
|
|---|
| 38 | time_t tv_sec;
|
|---|
| 39 | long tv_nsec;
|
|---|
| 40 | };
|
|---|
| 41 |
|
|---|
| 42 | struct 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) */
|
|---|
| 56 | extern clock_t clock(void);
|
|---|
| 57 |
|
|---|
| 58 | /* ISO/IEC 9899:2011 7.27.2.2 (1) */
|
|---|
| 59 | extern double difftime(time_t, time_t);
|
|---|
| 60 |
|
|---|
| 61 | /* ISO/IEC 9899:2011 7.27.2.3 (1) */
|
|---|
| 62 | extern time_t mktime(struct tm *);
|
|---|
| 63 |
|
|---|
| 64 | /* ISO/IEC 9899:2011 7.27.2.4 (1) */
|
|---|
| 65 | extern time_t time(time_t *);
|
|---|
| 66 |
|
|---|
| 67 | /* ISO/IEC 9899:2011 7.27.2.5 (1) */
|
|---|
| 68 | extern int timespec_get(struct timespec *, int);
|
|---|
| 69 |
|
|---|
| 70 | /* ISO/IEC 9899:2011 7.27.3.1 (1) */
|
|---|
| 71 | extern char *asctime(const struct tm *);
|
|---|
| 72 |
|
|---|
| 73 | /* ISO/IEC 9899:2011 7.27.3.2 (1) */
|
|---|
| 74 | extern char *ctime(const time_t *);
|
|---|
| 75 |
|
|---|
| 76 | /* ISO/IEC 9899:2011 7.27.3.3 (1) */
|
|---|
| 77 | extern struct tm *gmtime(const time_t *);
|
|---|
| 78 |
|
|---|
| 79 | /* ISO/IEC 9899:2011 7.27.3.4 (1) */
|
|---|
| 80 | extern struct tm *localtime(const time_t *);
|
|---|
| 81 |
|
|---|
| 82 | /* ISO/IEC 9899:2011 7.27.3.5 (1) */
|
|---|
| 83 | extern 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 |
|
|---|
| 99 | typedef long long sec_t;
|
|---|
| 100 | typedef long long msec_t;
|
|---|
| 101 | typedef long long usec_t;
|
|---|
| 102 | typedef 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 |
|
|---|
| 120 | extern void getuptime(struct timespec *);
|
|---|
| 121 | extern void getrealtime(struct timespec *);
|
|---|
| 122 |
|
|---|
| 123 | extern void ts_add_diff(struct timespec *, nsec_t);
|
|---|
| 124 | extern void ts_add(struct timespec *, const struct timespec *);
|
|---|
| 125 | extern void ts_sub(struct timespec *, const struct timespec *);
|
|---|
| 126 | extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
|
|---|
| 127 | extern bool ts_gt(const struct timespec *, const struct timespec *);
|
|---|
| 128 | extern bool ts_gteq(const struct timespec *, const struct timespec *);
|
|---|
| 129 |
|
|---|
| 130 | extern errno_t time_utc2tm(const time_t, struct tm *);
|
|---|
| 131 | extern errno_t time_utc2str(const time_t, char *);
|
|---|
| 132 | extern void time_tm2str(const struct tm *, char *);
|
|---|
| 133 | extern errno_t time_ts2tm(const struct timespec *, struct tm *);
|
|---|
| 134 | extern errno_t time_local2tm(const time_t, struct tm *);
|
|---|
| 135 | extern errno_t time_local2str(const time_t, char *);
|
|---|
| 136 |
|
|---|
| 137 | extern void udelay(sysarg_t);
|
|---|
| 138 |
|
|---|
| 139 | __HELENOS_DECLS_END;
|
|---|
| 140 |
|
|---|
| 141 | #endif /* _HELENOS_SOURCE */
|
|---|
| 142 |
|
|---|
| 143 | #endif
|
|---|
| 144 |
|
|---|
| 145 | /** @}
|
|---|
| 146 | */
|
|---|