blob: f65ac4e7c3de737e24518fc900bca18f8217486f [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 */
28#ifndef _TIME_H_
29#define _TIME_H_
30
31#include <sys/cdefs.h>
32#include <sys/time.h>
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020033#include <machine/signal.h> /* for struct sigevent */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
35__BEGIN_DECLS
36
37extern time_t time(time_t *);
38extern int nanosleep(const struct timespec *, struct timespec *);
39
40extern char *strtotimeval(const char *str, struct timeval *tv);
41
42struct tm {
43 int tm_sec; /* seconds */
44 int tm_min; /* minutes */
45 int tm_hour; /* hours */
46 int tm_mday; /* day of the month */
47 int tm_mon; /* month */
48 int tm_year; /* year */
49 int tm_wday; /* day of the week */
50 int tm_yday; /* day in the year */
51 int tm_isdst; /* daylight saving time */
52
53 long int tm_gmtoff; /* Seconds east of UTC. */
54 const char *tm_zone; /* Timezone abbreviation. */
55
56};
57
58/* defining TM_ZONE indicates that we have a "timezone abbreviation" field in
59 * struct tm, the value should be the field name
60 */
61#define TM_ZONE tm_zone
62
63extern char* asctime(const struct tm* a);
64extern char* asctime_r(const struct tm* a, char* buf);
65
66/* Return the difference between TIME1 and TIME0. */
67extern double difftime (time_t __time1, time_t __time0);
68extern time_t mktime (struct tm *a);
69
70extern struct tm* localtime(const time_t *t);
71extern struct tm* localtime_r(const time_t *timep, struct tm *result);
72
73extern struct tm* gmtime(const time_t *timep);
74extern struct tm* gmtime_r(const time_t *timep, struct tm *result);
75
76extern char* strptime(const char *buf, const char *fmt, struct tm *tm);
77extern size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
78
79extern char *ctime(const time_t *timep);
80extern char *ctime_r(const time_t *timep, char *buf);
81
The Android Open Source Projectedbe7fc2009-03-18 22:20:24 -070082extern void tzset(void);
83
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080084/* global includes */
85extern char* tzname[];
86extern int daylight;
87extern long int timezone;
88
89#define CLOCKS_PER_SEC 1000000
90
Erik Gilling9e74f692009-09-09 14:58:19 -070091extern clock_t clock(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092
93/* BIONIC: extra linux clock goodies */
94extern int clock_getres(int, struct timespec *);
95extern int clock_gettime(int, struct timespec *);
96
97#define CLOCK_REALTIME 0
98#define CLOCK_MONOTONIC 1
99#define CLOCK_PROCESS_CPUTIME_ID 2
100#define CLOCK_THREAD_CPUTIME_ID 3
101#define CLOCK_REALTIME_HR 4
102#define CLOCK_MONOTONIC_HR 5
Nick Pelly03519552012-07-19 13:50:55 -0700103#define CLOCK_BOOTTIME 7
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800104
105extern int timer_create(int, struct sigevent*, timer_t*);
106extern int timer_delete(timer_t);
107extern int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
108extern int timer_gettime(timer_t timerid, struct itimerspec *value);
109extern int timer_getoverrun(timer_t timerid);
110
David 'Digit' Turner6481b912010-12-06 12:23:16 +0100111extern time_t timelocal(struct tm *tm);
112extern time_t timegm(struct tm* tm);
113extern time_t time2posix(time_t ti);
114extern time_t posix2time(time_t ti);
115
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800116__END_DECLS
117
118#endif /* _TIME_H_ */