The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
Elliott Hughes | 3503ce2 | 2013-11-05 13:28:36 -0800 | [diff] [blame] | 28 | |
Elliott Hughes | 52541ee | 2023-04-24 17:04:49 -0700 | [diff] [blame^] | 29 | #pragma once |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | |
| 31 | #include <sys/cdefs.h> |
| 32 | #include <sys/time.h> |
Dan Albert | dfb5ce4 | 2014-07-09 22:51:34 +0000 | [diff] [blame] | 33 | #include <xlocale.h> |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 34 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | __BEGIN_DECLS |
| 36 | |
Elliott Hughes | 3503ce2 | 2013-11-05 13:28:36 -0800 | [diff] [blame] | 37 | #define CLOCKS_PER_SEC 1000000 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 39 | extern char* _Nonnull tzname[]; |
Elliott Hughes | f47514d | 2016-07-19 13:56:46 -0700 | [diff] [blame] | 40 | extern int daylight; |
| 41 | extern long int timezone; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 43 | struct sigevent; |
| 44 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | struct tm { |
Elliott Hughes | 3503ce2 | 2013-11-05 13:28:36 -0800 | [diff] [blame] | 46 | int tm_sec; |
| 47 | int tm_min; |
| 48 | int tm_hour; |
| 49 | int tm_mday; |
| 50 | int tm_mon; |
| 51 | int tm_year; |
| 52 | int tm_wday; |
| 53 | int tm_yday; |
| 54 | int tm_isdst; |
| 55 | long int tm_gmtoff; |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 56 | const char* _Nullable tm_zone; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Elliott Hughes | 3503ce2 | 2013-11-05 13:28:36 -0800 | [diff] [blame] | 59 | #define TM_ZONE tm_zone |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 60 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 61 | time_t time(time_t* _Nullable __t); |
| 62 | int nanosleep(const struct timespec* _Nonnull __request, struct timespec* _Nullable __remainder); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 64 | char* _Nullable asctime(const struct tm* _Nonnull __tm); |
| 65 | char* _Nullable asctime_r(const struct tm* _Nonnull __tm, char* _Nonnull __buf); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 66 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 67 | double difftime(time_t __lhs, time_t __rhs); |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 68 | time_t mktime(struct tm* _Nonnull __tm); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 70 | struct tm* _Nullable localtime(const time_t* _Nonnull __t); |
| 71 | struct tm* _Nullable localtime_r(const time_t* _Nonnull __t, struct tm* _Nonnull __tm); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 72 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 73 | struct tm* _Nullable gmtime(const time_t* _Nonnull __t); |
| 74 | struct tm* _Nullable gmtime_r(const time_t* _Nonnull __t, struct tm* _Nonnull __tm); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 75 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 76 | char* _Nullable strptime(const char* _Nonnull __s, const char* _Nonnull __fmt, struct tm* _Nonnull __tm) __strftimelike(2); |
| 77 | char* _Nullable strptime_l(const char* _Nonnull __s, const char* _Nonnull __fmt, struct tm* _Nonnull __tm, locale_t _Nonnull __l) __strftimelike(2) __INTRODUCED_IN(28); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 78 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 79 | size_t strftime(char* _Nonnull __buf, size_t __n, const char* _Nonnull __fmt, const struct tm* _Nullable __tm) __strftimelike(3); |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 80 | size_t strftime_l(char* _Nonnull __buf, size_t __n, const char* _Nonnull __fmt, const struct tm* _Nullable __tm, locale_t _Nonnull __l) __strftimelike(3) __INTRODUCED_IN(21); |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 81 | |
| 82 | char* _Nullable ctime(const time_t* _Nonnull __t); |
| 83 | char* _Nullable ctime_r(const time_t* _Nonnull __t, char* _Nonnull __buf); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 85 | void tzset(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 86 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 87 | clock_t clock(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 89 | int clock_getcpuclockid(pid_t __pid, clockid_t* _Nonnull __clock) __INTRODUCED_IN(23); |
Yabin Cui | d5c6527 | 2014-11-26 14:04:26 -0800 | [diff] [blame] | 90 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 92 | int clock_getres(clockid_t __clock, struct timespec* _Nullable __resolution); |
| 93 | int clock_gettime(clockid_t __clock, struct timespec* _Nonnull __ts); |
| 94 | int clock_nanosleep(clockid_t __clock, int __flags, const struct timespec* _Nonnull __request, struct timespec* _Nullable __remainder); |
| 95 | int clock_settime(clockid_t __clock, const struct timespec* _Nonnull __ts); |
| 96 | |
| 97 | int timer_create(clockid_t __clock, struct sigevent* _Nullable __event, timer_t _Nonnull * _Nonnull __timer_ptr); |
| 98 | int timer_delete(timer_t _Nonnull __timer); |
| 99 | int timer_settime(timer_t _Nonnull __timer, int __flags, const struct itimerspec* _Nonnull __new_value, struct itimerspec* _Nullable __old_value); |
| 100 | int timer_gettime(timer_t _Nonnull _timer, struct itimerspec* _Nonnull __ts); |
| 101 | int timer_getoverrun(timer_t _Nonnull __timer); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 | |
Elliott Hughes | d10db82 | 2014-06-19 14:49:30 -0700 | [diff] [blame] | 103 | /* Non-standard extensions that are in the BSDs and glibc. */ |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 104 | time_t timelocal(struct tm* _Nonnull __tm); |
| 105 | time_t timegm(struct tm* _Nonnull __tm); |
David 'Digit' Turner | 6481b91 | 2010-12-06 12:23:16 +0100 | [diff] [blame] | 106 | |
Elliott Hughes | 52541ee | 2023-04-24 17:04:49 -0700 | [diff] [blame^] | 107 | /** |
| 108 | * The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_REALTIME. |
| 109 | * |
| 110 | * Available since API level 29. |
| 111 | */ |
Elliott Hughes | f98d87b | 2018-07-17 13:21:05 -0700 | [diff] [blame] | 112 | #define TIME_UTC 1 |
Elliott Hughes | 52541ee | 2023-04-24 17:04:49 -0700 | [diff] [blame^] | 113 | |
| 114 | /** |
| 115 | * The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_MONOTONIC. |
| 116 | * |
| 117 | * Available since API level 35. |
| 118 | */ |
| 119 | #define TIME_MONOTONIC 2 |
| 120 | |
| 121 | /** |
| 122 | * The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_PROCESS_CPUTIME_ID. |
| 123 | * |
| 124 | * Available since API level 35. |
| 125 | */ |
| 126 | #define TIME_ACTIVE 3 |
| 127 | |
| 128 | /** |
| 129 | * The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_THREAD_CPUTIME_ID. |
| 130 | * |
| 131 | * Available since API level 35. |
| 132 | */ |
| 133 | #define TIME_THREAD_ACTIVE 4 |
| 134 | |
| 135 | /** |
| 136 | * timespec_get(3) is equivalent to clock_gettime() for the clock corresponding to the given base. |
| 137 | * |
| 138 | * Returns the base on success and returns 0 on failure. |
| 139 | * |
| 140 | * Available since API level 29 for TIME_UTC; other bases arrived later. |
| 141 | * Code for Android should prefer clock_gettime(). |
| 142 | */ |
zijunzhao | e620266 | 2023-01-03 23:32:18 +0000 | [diff] [blame] | 143 | int timespec_get(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(29); |
Elliott Hughes | f98d87b | 2018-07-17 13:21:05 -0700 | [diff] [blame] | 144 | |
Elliott Hughes | 52541ee | 2023-04-24 17:04:49 -0700 | [diff] [blame^] | 145 | /** |
| 146 | * timespec_getres(3) is equivalent to clock_getres() for the clock corresponding to the given base. |
| 147 | * |
| 148 | * Returns the base on success and returns 0 on failure. |
| 149 | * |
| 150 | * Available since API level 35. |
| 151 | * Code for Android should prefer clock_gettime(). |
| 152 | */ |
| 153 | int timespec_getres(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(35); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 154 | |
Elliott Hughes | 52541ee | 2023-04-24 17:04:49 -0700 | [diff] [blame^] | 155 | __END_DECLS |