[2fc5072] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Petr Koupy
|
---|
| 3 | * Copyright (c) 2011 Jiri Zarevucky
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libposix
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef POSIX_TIME_H_
|
---|
| 37 | #define POSIX_TIME_H_
|
---|
| 38 |
|
---|
[acc3f82c] | 39 | #include "libc/time.h"
|
---|
[324d46b] | 40 | #include "sys/types.h"
|
---|
[2fc5072] | 41 |
|
---|
| 42 | #ifndef NULL
|
---|
| 43 | #define NULL ((void *) 0)
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
[324d46b] | 46 | #ifndef CLOCKS_PER_SEC
|
---|
| 47 | #define CLOCKS_PER_SEC (1000000L)
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | #ifndef __locale_t_defined
|
---|
| 51 | #define __locale_t_defined
|
---|
| 52 | typedef struct __posix_locale *posix_locale_t;
|
---|
| 53 | #ifndef LIBPOSIX_INTERNAL
|
---|
| 54 | #define locale_t posix_locale_t
|
---|
| 55 | #endif
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
[3f466c33] | 58 | #ifndef POSIX_SIGNAL_H_
|
---|
| 59 | struct posix_sigevent;
|
---|
| 60 | #ifndef LIBPOSIX_INTERNAL
|
---|
| 61 | #define sigevent posix_sigevent
|
---|
| 62 | #endif
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
[324d46b] | 65 | #undef ASCTIME_BUF_LEN
|
---|
| 66 | #define ASCTIME_BUF_LEN 26
|
---|
| 67 |
|
---|
| 68 | #undef CLOCK_REALTIME
|
---|
| 69 | #define CLOCK_REALTIME ((posix_clockid_t) 0)
|
---|
[06cb827] | 70 |
|
---|
[2fc5072] | 71 | struct posix_tm {
|
---|
| 72 | int tm_sec; /* Seconds [0,60]. */
|
---|
| 73 | int tm_min; /* Minutes [0,59]. */
|
---|
| 74 | int tm_hour; /* Hour [0,23]. */
|
---|
| 75 | int tm_mday; /* Day of month [1,31]. */
|
---|
| 76 | int tm_mon; /* Month of year [0,11]. */
|
---|
| 77 | int tm_year; /* Years since 1900. */
|
---|
| 78 | int tm_wday; /* Day of week [0,6] (Sunday = 0). */
|
---|
| 79 | int tm_yday; /* Day of year [0,365]. */
|
---|
| 80 | int tm_isdst; /* Daylight Savings flag. */
|
---|
| 81 | };
|
---|
| 82 |
|
---|
[324d46b] | 83 | struct posix_timespec {
|
---|
| 84 | time_t tv_sec; /* Seconds. */
|
---|
| 85 | long tv_nsec; /* Nanoseconds. */
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 | struct posix_itimerspec {
|
---|
| 89 | struct posix_timespec it_interval; /* Timer period. */
|
---|
| 90 | struct posix_timespec it_value; /* Timer expiration. */
|
---|
| 91 | };
|
---|
| 92 |
|
---|
[3f466c33] | 93 | typedef struct __posix_timer *posix_timer_t;
|
---|
| 94 |
|
---|
[324d46b] | 95 | /* Timezones */
|
---|
| 96 |
|
---|
| 97 | extern int posix_daylight;
|
---|
| 98 | extern long posix_timezone;
|
---|
| 99 | extern char *posix_tzname[2];
|
---|
| 100 |
|
---|
| 101 | extern void posix_tzset(void);
|
---|
| 102 |
|
---|
| 103 | /* time_t */
|
---|
| 104 |
|
---|
| 105 | extern double posix_difftime(time_t time1, time_t time0);
|
---|
| 106 |
|
---|
[2fc5072] | 107 | /* Broken-down Time */
|
---|
[324d46b] | 108 | extern time_t posix_mktime(struct posix_tm *timeptr);
|
---|
[3f466c33] | 109 | extern struct posix_tm *posix_gmtime(const time_t *timer);
|
---|
| 110 | extern struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
|
---|
| 111 | struct posix_tm *restrict result);
|
---|
| 112 | extern struct posix_tm *posix_localtime(const time_t *timer);
|
---|
[324d46b] | 113 | extern struct posix_tm *posix_localtime_r(const time_t *restrict timer,
|
---|
| 114 | struct posix_tm *restrict result);
|
---|
[3f466c33] | 115 |
|
---|
[2fc5072] | 116 | /* Formatting Calendar Time */
|
---|
[324d46b] | 117 | extern char *posix_asctime(const struct posix_tm *timeptr);
|
---|
| 118 | extern char *posix_asctime_r(const struct posix_tm *restrict timeptr,
|
---|
| 119 | char *restrict buf);
|
---|
[3f466c33] | 120 | extern char *posix_ctime(const time_t *timer);
|
---|
| 121 | extern char *posix_ctime_r(const time_t *timer, char *buf);
|
---|
| 122 |
|
---|
[324d46b] | 123 | extern size_t posix_strftime(char *restrict s, size_t maxsize,
|
---|
| 124 | const char *restrict format, const struct posix_tm *restrict tm);
|
---|
[2fc5072] | 125 |
|
---|
[3f466c33] | 126 | extern size_t posix_strftime_l(char *restrict s, size_t maxsize,
|
---|
| 127 | const char *restrict format, const struct posix_tm *restrict tm,
|
---|
| 128 | posix_locale_t loc);
|
---|
| 129 |
|
---|
| 130 | /* Clocks. */
|
---|
| 131 |
|
---|
| 132 | extern int posix_clock_getres(posix_clockid_t clock_id,
|
---|
| 133 | struct posix_timespec *res);
|
---|
| 134 | extern int posix_clock_gettime(posix_clockid_t clock_id,
|
---|
| 135 | struct posix_timespec *tp);
|
---|
| 136 | extern int posix_clock_settime(posix_clockid_t clock_id,
|
---|
| 137 | const struct posix_timespec *tp);
|
---|
| 138 | extern int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,
|
---|
| 139 | const struct posix_timespec *rqtp, struct posix_timespec *rmtp);
|
---|
| 140 |
|
---|
| 141 | /* Timers. */
|
---|
| 142 |
|
---|
| 143 | #if 0
|
---|
| 144 |
|
---|
| 145 | extern int posix_timer_create(posix_clockid_t clockid,
|
---|
| 146 | struct posix_sigevent *restrict evp,
|
---|
| 147 | posix_timer_t *restrict timerid);
|
---|
| 148 | extern int posix_timer_delete(posix_timer_t timerid);
|
---|
| 149 | extern int posix_timer_getoverrun(posix_timer_t timerid);
|
---|
| 150 | extern int posix_timer_gettime(posix_timer_t timerid,
|
---|
| 151 | struct posix_itimerspec *value);
|
---|
| 152 | extern int posix_timer_settime(posix_timer_t timerid, int flags,
|
---|
| 153 | const struct posix_itimerspec *restrict value,
|
---|
| 154 | struct posix_itimerspec *restrict ovalue);
|
---|
| 155 |
|
---|
| 156 | #endif
|
---|
| 157 |
|
---|
[823a929] | 158 | /* CPU Time */
|
---|
| 159 | extern posix_clock_t posix_clock(void);
|
---|
| 160 |
|
---|
[324d46b] | 161 |
|
---|
[4d10fc8] | 162 | #ifndef LIBPOSIX_INTERNAL
|
---|
| 163 | #define tm posix_tm
|
---|
[2fc5072] | 164 |
|
---|
[324d46b] | 165 | #define timespec posix_timespec
|
---|
| 166 | #define itimerspec posix_itimerspec
|
---|
[3f466c33] | 167 | #define timer_t posix_timer_t
|
---|
[823a929] | 168 |
|
---|
[324d46b] | 169 | #define difftime posix_difftime
|
---|
| 170 | #define mktime posix_mktime
|
---|
[3f466c33] | 171 | #define gmtime posix_gmtime
|
---|
| 172 | #define gmtime_r posix_gmtime_r
|
---|
[4d10fc8] | 173 | #define localtime posix_localtime
|
---|
[324d46b] | 174 | #define localtime_r posix_localtime_r
|
---|
| 175 |
|
---|
| 176 | #define daylight posix_daylight
|
---|
| 177 | #define timezone posix_timezone
|
---|
| 178 | #define tzname posix_tzname
|
---|
| 179 | #define tzset posix_tzset
|
---|
[2fc5072] | 180 |
|
---|
[4d10fc8] | 181 | #define asctime posix_asctime
|
---|
[324d46b] | 182 | #define asctime_r posix_asctime_r
|
---|
[4d10fc8] | 183 | #define ctime posix_ctime
|
---|
[3f466c33] | 184 | #define ctime_r posix_ctime_r
|
---|
[4d10fc8] | 185 | #define strftime posix_strftime
|
---|
[823a929] | 186 |
|
---|
[3f466c33] | 187 | #define clock_getres posix_clock_getres
|
---|
| 188 | #define clock_gettime posix_clock_gettime
|
---|
| 189 | #define clock_settime posix_clock_settime
|
---|
| 190 | #define clock_nanosleep posix_clock_nanosleep
|
---|
| 191 |
|
---|
| 192 | #define timer_create posix_timer_create
|
---|
| 193 | #define timer_delete posix_timer_delete
|
---|
| 194 | #define timer_getoverrun posix_timer_getoverrun
|
---|
| 195 | #define timer_gettime posix_timer_gettime
|
---|
| 196 | #define timer_settime posix_timer_settime
|
---|
| 197 |
|
---|
[823a929] | 198 | #define clock posix_clock
|
---|
[4d10fc8] | 199 | #endif
|
---|
[2fc5072] | 200 |
|
---|
| 201 | #endif // POSIX_TIME_H_
|
---|
| 202 |
|
---|
| 203 | /** @}
|
---|
| 204 | */
|
---|