[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 | */
|
---|
[4cf8ca6] | 33 | /** @file Time measurement support.
|
---|
[2fc5072] | 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 CLOCK_REALTIME
|
---|
| 66 | #define CLOCK_REALTIME ((posix_clockid_t) 0)
|
---|
[06cb827] | 67 |
|
---|
[324d46b] | 68 | struct posix_timespec {
|
---|
| 69 | time_t tv_sec; /* Seconds. */
|
---|
| 70 | long tv_nsec; /* Nanoseconds. */
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | struct posix_itimerspec {
|
---|
| 74 | struct posix_timespec it_interval; /* Timer period. */
|
---|
| 75 | struct posix_timespec it_value; /* Timer expiration. */
|
---|
| 76 | };
|
---|
| 77 |
|
---|
[3f466c33] | 78 | typedef struct __posix_timer *posix_timer_t;
|
---|
| 79 |
|
---|
[324d46b] | 80 | /* Timezones */
|
---|
| 81 | extern int posix_daylight;
|
---|
| 82 | extern long posix_timezone;
|
---|
| 83 | extern char *posix_tzname[2];
|
---|
| 84 | extern void posix_tzset(void);
|
---|
| 85 |
|
---|
[2fc5072] | 86 | /* Broken-down Time */
|
---|
[f8b6d34c] | 87 | extern struct tm *posix_gmtime_r(const time_t *restrict timer,
|
---|
| 88 | struct tm *restrict result);
|
---|
| 89 | extern struct tm *posix_localtime_r(const time_t *restrict timer,
|
---|
| 90 | struct tm *restrict result);
|
---|
[3f466c33] | 91 |
|
---|
[2fc5072] | 92 | /* Formatting Calendar Time */
|
---|
[f8b6d34c] | 93 | extern char *posix_asctime_r(const struct tm *restrict timeptr,
|
---|
[324d46b] | 94 | char *restrict buf);
|
---|
[3f466c33] | 95 | extern char *posix_ctime_r(const time_t *timer, char *buf);
|
---|
| 96 |
|
---|
[4cf8ca6] | 97 | /* Clocks */
|
---|
[3f466c33] | 98 | extern int posix_clock_getres(posix_clockid_t clock_id,
|
---|
| 99 | struct posix_timespec *res);
|
---|
| 100 | extern int posix_clock_gettime(posix_clockid_t clock_id,
|
---|
| 101 | struct posix_timespec *tp);
|
---|
| 102 | extern int posix_clock_settime(posix_clockid_t clock_id,
|
---|
| 103 | const struct posix_timespec *tp);
|
---|
| 104 | extern int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,
|
---|
| 105 | const struct posix_timespec *rqtp, struct posix_timespec *rmtp);
|
---|
| 106 |
|
---|
[823a929] | 107 | /* CPU Time */
|
---|
| 108 | extern posix_clock_t posix_clock(void);
|
---|
| 109 |
|
---|
[4d10fc8] | 110 | #ifndef LIBPOSIX_INTERNAL
|
---|
[324d46b] | 111 | #define timespec posix_timespec
|
---|
| 112 | #define itimerspec posix_itimerspec
|
---|
[3f466c33] | 113 | #define timer_t posix_timer_t
|
---|
[823a929] | 114 |
|
---|
[4cf8ca6] | 115 | #define daylight posix_daylight
|
---|
| 116 | #define timezone posix_timezone
|
---|
| 117 | #define tzname posix_tzname
|
---|
| 118 | #define tzset posix_tzset
|
---|
| 119 |
|
---|
[3f466c33] | 120 | #define gmtime_r posix_gmtime_r
|
---|
[324d46b] | 121 | #define localtime_r posix_localtime_r
|
---|
| 122 |
|
---|
| 123 | #define asctime_r posix_asctime_r
|
---|
[3f466c33] | 124 | #define ctime_r posix_ctime_r
|
---|
[823a929] | 125 |
|
---|
[3f466c33] | 126 | #define clock_getres posix_clock_getres
|
---|
| 127 | #define clock_gettime posix_clock_gettime
|
---|
| 128 | #define clock_settime posix_clock_settime
|
---|
| 129 | #define clock_nanosleep posix_clock_nanosleep
|
---|
[55b1efd] | 130 |
|
---|
[823a929] | 131 | #define clock posix_clock
|
---|
[4d10fc8] | 132 | #endif
|
---|
[2fc5072] | 133 |
|
---|
| 134 | #endif // POSIX_TIME_H_
|
---|
| 135 |
|
---|
| 136 | /** @}
|
---|
| 137 | */
|
---|