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 | */ |
| 28 | #ifndef _TIME_H_ |
| 29 | #define _TIME_H_ |
| 30 | |
| 31 | #include <sys/cdefs.h> |
| 32 | #include <sys/time.h> |
| 33 | |
| 34 | #define __ARCH_SI_UID_T __kernel_uid32_t |
| 35 | #include <asm/siginfo.h> |
| 36 | #undef __ARCH_SI_UID_T |
| 37 | |
| 38 | __BEGIN_DECLS |
| 39 | |
| 40 | extern time_t time(time_t *); |
| 41 | extern int nanosleep(const struct timespec *, struct timespec *); |
| 42 | |
| 43 | extern char *strtotimeval(const char *str, struct timeval *tv); |
| 44 | |
| 45 | struct tm { |
| 46 | int tm_sec; /* seconds */ |
| 47 | int tm_min; /* minutes */ |
| 48 | int tm_hour; /* hours */ |
| 49 | int tm_mday; /* day of the month */ |
| 50 | int tm_mon; /* month */ |
| 51 | int tm_year; /* year */ |
| 52 | int tm_wday; /* day of the week */ |
| 53 | int tm_yday; /* day in the year */ |
| 54 | int tm_isdst; /* daylight saving time */ |
| 55 | |
| 56 | long int tm_gmtoff; /* Seconds east of UTC. */ |
| 57 | const char *tm_zone; /* Timezone abbreviation. */ |
| 58 | |
| 59 | }; |
| 60 | |
| 61 | /* defining TM_ZONE indicates that we have a "timezone abbreviation" field in |
| 62 | * struct tm, the value should be the field name |
| 63 | */ |
| 64 | #define TM_ZONE tm_zone |
| 65 | |
| 66 | extern char* asctime(const struct tm* a); |
| 67 | extern char* asctime_r(const struct tm* a, char* buf); |
| 68 | |
| 69 | /* Return the difference between TIME1 and TIME0. */ |
| 70 | extern double difftime (time_t __time1, time_t __time0); |
| 71 | extern time_t mktime (struct tm *a); |
| 72 | |
| 73 | extern struct tm* localtime(const time_t *t); |
| 74 | extern struct tm* localtime_r(const time_t *timep, struct tm *result); |
| 75 | |
| 76 | extern struct tm* gmtime(const time_t *timep); |
| 77 | extern struct tm* gmtime_r(const time_t *timep, struct tm *result); |
| 78 | |
| 79 | extern char* strptime(const char *buf, const char *fmt, struct tm *tm); |
| 80 | extern size_t strftime(char *s, size_t max, const char *format, const struct tm *tm); |
| 81 | |
David 'Digit' Turner | 11f3d5a | 2012-01-13 13:26:50 +0100 | [diff] [blame^] | 82 | /* The following declarations should not be part of the C library's public |
| 83 | * headers. They are duplicated under bionic/libc/private/bionic_time.h and |
| 84 | * will be removed from here when we modify system/libcutils to use the |
| 85 | * proper header instead. |
| 86 | * |
| 87 | * Use a guard macro to avoid compilation error when both headers are |
| 88 | * included. |
| 89 | */ |
| 90 | #ifndef _BIONIC_STRFTIME_TZ_DECLARED |
| 91 | #define _BIONIC_STRFTIME_TZ_DECLARED |
| 92 | |
The Android Open Source Project | edbe7fc | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 93 | struct strftime_locale { |
| 94 | const char * mon[12]; |
| 95 | const char * month[12]; |
Eric Fischer | a48fa7f | 2009-05-15 13:33:20 -0700 | [diff] [blame] | 96 | const char * standalone_month[12]; |
The Android Open Source Project | edbe7fc | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 97 | const char * wday[7]; |
| 98 | const char * weekday[7]; |
| 99 | const char * X_fmt; |
| 100 | const char * x_fmt; |
| 101 | const char * c_fmt; |
| 102 | const char * am; |
| 103 | const char * pm; |
| 104 | const char * date_fmt; |
| 105 | }; |
| 106 | |
| 107 | extern size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale* lc); |
David 'Digit' Turner | 11f3d5a | 2012-01-13 13:26:50 +0100 | [diff] [blame^] | 108 | |
| 109 | #endif /* _BIONIC_STRFTIME_TZ_DECLARED */ |
The Android Open Source Project | edbe7fc | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 110 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 111 | extern char *ctime(const time_t *timep); |
| 112 | extern char *ctime_r(const time_t *timep, char *buf); |
| 113 | |
The Android Open Source Project | edbe7fc | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 114 | extern void tzset(void); |
| 115 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 116 | /* global includes */ |
| 117 | extern char* tzname[]; |
| 118 | extern int daylight; |
| 119 | extern long int timezone; |
| 120 | |
| 121 | #define CLOCKS_PER_SEC 1000000 |
| 122 | |
Erik Gilling | 9e74f69 | 2009-09-09 14:58:19 -0700 | [diff] [blame] | 123 | extern clock_t clock(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 124 | |
| 125 | /* BIONIC: extra linux clock goodies */ |
| 126 | extern int clock_getres(int, struct timespec *); |
| 127 | extern int clock_gettime(int, struct timespec *); |
| 128 | |
| 129 | #define CLOCK_REALTIME 0 |
| 130 | #define CLOCK_MONOTONIC 1 |
| 131 | #define CLOCK_PROCESS_CPUTIME_ID 2 |
| 132 | #define CLOCK_THREAD_CPUTIME_ID 3 |
| 133 | #define CLOCK_REALTIME_HR 4 |
| 134 | #define CLOCK_MONOTONIC_HR 5 |
| 135 | |
| 136 | extern int timer_create(int, struct sigevent*, timer_t*); |
| 137 | extern int timer_delete(timer_t); |
| 138 | extern int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue); |
| 139 | extern int timer_gettime(timer_t timerid, struct itimerspec *value); |
| 140 | extern int timer_getoverrun(timer_t timerid); |
| 141 | |
David 'Digit' Turner | 6481b91 | 2010-12-06 12:23:16 +0100 | [diff] [blame] | 142 | extern time_t timelocal(struct tm *tm); |
| 143 | extern time_t timegm(struct tm* tm); |
| 144 | extern time_t time2posix(time_t ti); |
| 145 | extern time_t posix2time(time_t ti); |
| 146 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | __END_DECLS |
| 148 | |
| 149 | #endif /* _TIME_H_ */ |