blob: 2d2de9f0931dbb2527eb870ec4f35c65ed5e9c77 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughes3503ce22013-11-05 13:28:36 -080028
Elliott Hughes52541ee2023-04-24 17:04:49 -070029#pragma once
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030
31#include <sys/cdefs.h>
32#include <sys/time.h>
Dan Albertdfb5ce42014-07-09 22:51:34 +000033#include <xlocale.h>
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020034
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035__BEGIN_DECLS
36
Elliott Hughes3503ce22013-11-05 13:28:36 -080037#define CLOCKS_PER_SEC 1000000
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
zijunzhaoe6202662023-01-03 23:32:18 +000039extern char* _Nonnull tzname[];
Elliott Hughesf47514d2016-07-19 13:56:46 -070040extern int daylight;
41extern long int timezone;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080043struct sigevent;
44
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045struct tm {
Elliott Hughes3503ce22013-11-05 13:28:36 -080046 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;
zijunzhaoe6202662023-01-03 23:32:18 +000056 const char* _Nullable tm_zone;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057};
58
Elliott Hughes3503ce22013-11-05 13:28:36 -080059#define TM_ZONE tm_zone
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080060
zijunzhaoe6202662023-01-03 23:32:18 +000061time_t time(time_t* _Nullable __t);
62int nanosleep(const struct timespec* _Nonnull __request, struct timespec* _Nullable __remainder);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080063
zijunzhaoe6202662023-01-03 23:32:18 +000064char* _Nullable asctime(const struct tm* _Nonnull __tm);
65char* _Nullable asctime_r(const struct tm* _Nonnull __tm, char* _Nonnull __buf);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080066
Elliott Hughesff26a162017-08-17 22:34:21 +000067double difftime(time_t __lhs, time_t __rhs);
zijunzhaoe6202662023-01-03 23:32:18 +000068time_t mktime(struct tm* _Nonnull __tm);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069
zijunzhaoe6202662023-01-03 23:32:18 +000070struct tm* _Nullable localtime(const time_t* _Nonnull __t);
71struct tm* _Nullable localtime_r(const time_t* _Nonnull __t, struct tm* _Nonnull __tm);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072
zijunzhaoe6202662023-01-03 23:32:18 +000073struct tm* _Nullable gmtime(const time_t* _Nonnull __t);
74struct tm* _Nullable gmtime_r(const time_t* _Nonnull __t, struct tm* _Nonnull __tm);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080075
zijunzhaoe6202662023-01-03 23:32:18 +000076char* _Nullable strptime(const char* _Nonnull __s, const char* _Nonnull __fmt, struct tm* _Nonnull __tm) __strftimelike(2);
77char* _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 Gao6cd9fb02016-09-23 14:06:05 -070078
zijunzhaoe6202662023-01-03 23:32:18 +000079size_t strftime(char* _Nonnull __buf, size_t __n, const char* _Nonnull __fmt, const struct tm* _Nullable __tm) __strftimelike(3);
zijunzhaoe6202662023-01-03 23:32:18 +000080size_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);
zijunzhaoe6202662023-01-03 23:32:18 +000081
82char* _Nullable ctime(const time_t* _Nonnull __t);
83char* _Nullable ctime_r(const time_t* _Nonnull __t, char* _Nonnull __buf);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080084
Elliott Hughes3b2096a2016-07-22 18:57:12 -070085void tzset(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
Elliott Hughes3b2096a2016-07-22 18:57:12 -070087clock_t clock(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080088
zijunzhaoe6202662023-01-03 23:32:18 +000089int clock_getcpuclockid(pid_t __pid, clockid_t* _Nonnull __clock) __INTRODUCED_IN(23);
Yabin Cuid5c65272014-11-26 14:04:26 -080090
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091
zijunzhaoe6202662023-01-03 23:32:18 +000092int clock_getres(clockid_t __clock, struct timespec* _Nullable __resolution);
93int clock_gettime(clockid_t __clock, struct timespec* _Nonnull __ts);
94int clock_nanosleep(clockid_t __clock, int __flags, const struct timespec* _Nonnull __request, struct timespec* _Nullable __remainder);
95int clock_settime(clockid_t __clock, const struct timespec* _Nonnull __ts);
96
97int timer_create(clockid_t __clock, struct sigevent* _Nullable __event, timer_t _Nonnull * _Nonnull __timer_ptr);
98int timer_delete(timer_t _Nonnull __timer);
99int timer_settime(timer_t _Nonnull __timer, int __flags, const struct itimerspec* _Nonnull __new_value, struct itimerspec* _Nullable __old_value);
100int timer_gettime(timer_t _Nonnull _timer, struct itimerspec* _Nonnull __ts);
101int timer_getoverrun(timer_t _Nonnull __timer);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800102
Elliott Hughesd10db822014-06-19 14:49:30 -0700103/* Non-standard extensions that are in the BSDs and glibc. */
zijunzhaoe6202662023-01-03 23:32:18 +0000104time_t timelocal(struct tm* _Nonnull __tm);
105time_t timegm(struct tm* _Nonnull __tm);
David 'Digit' Turner6481b912010-12-06 12:23:16 +0100106
Elliott Hughes52541ee2023-04-24 17:04:49 -0700107/**
108 * The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_REALTIME.
109 *
110 * Available since API level 29.
111 */
Elliott Hughesf98d87b2018-07-17 13:21:05 -0700112#define TIME_UTC 1
Elliott Hughes52541ee2023-04-24 17:04:49 -0700113
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 */
zijunzhaoe6202662023-01-03 23:32:18 +0000143int timespec_get(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(29);
Elliott Hughesf98d87b2018-07-17 13:21:05 -0700144
Elliott Hughes52541ee2023-04-24 17:04:49 -0700145/**
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 */
153int timespec_getres(struct timespec* _Nonnull __ts, int __base) __INTRODUCED_IN(35);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800154
Elliott Hughes52541ee2023-04-24 17:04:49 -0700155__END_DECLS