|
1 | 1 | /*
|
2 |
| - * This file is part of frosted shared kernel-userspace headers. |
3 |
| - * |
4 |
| - * frosted is free software: you can redistribute it and/or modify |
5 |
| - * it under the terms of the GNU Lesser General Public License version 2.1, as |
6 |
| - * published by the Free Software Foundation. |
7 |
| - * |
8 |
| - * |
9 |
| - * frosted is distributed in the hope that it will be useful, |
10 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
| - * GNU General Public License for more details. |
13 |
| - * |
14 |
| - * You should have received a copy of the GNU General Public License |
15 |
| - * along with frosted. If not, see <http://www.gnu.org/licenses/>. |
16 |
| - * |
17 |
| - * Authors: brabo |
| 2 | + * time.h |
18 | 3 | *
|
| 4 | + * Struct and function declarations for dealing with time. |
19 | 5 | */
|
20 | 6 |
|
21 |
| -#ifndef _FROSTED_TIME_H_ |
22 |
| -#define _FROSTED_TIME_H_ |
| 7 | +#ifndef _TIME_H_ |
| 8 | + |
| 9 | +#include "_ansi.h" |
| 10 | +#include <sys/reent.h> |
| 11 | + |
| 12 | +#ifdef __cplusplus |
| 13 | +extern "C" { |
| 14 | +#endif |
| 15 | + |
| 16 | +#ifndef NULL |
| 17 | +#define NULL 0 |
| 18 | +#endif |
| 19 | + |
| 20 | +/* Get _CLOCKS_PER_SEC_ */ |
| 21 | +#include <machine/time.h> |
| 22 | +#include <sys/types.h> |
| 23 | +#include <sys/timespec.h> |
| 24 | + |
| 25 | +#ifndef __need_timespec |
| 26 | + |
| 27 | +#define _TIME_H_ 1 |
| 28 | + |
| 29 | +#ifndef _CLOCKS_PER_SEC_ |
| 30 | +#define _CLOCKS_PER_SEC_ 1000 |
| 31 | +#endif |
| 32 | + |
| 33 | +#define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ |
| 34 | +#define CLK_TCK CLOCKS_PER_SEC |
| 35 | +#define __need_size_t |
| 36 | +#include <stddef.h> |
| 37 | + |
| 38 | +struct tm |
| 39 | +{ |
| 40 | + int tm_sec; |
| 41 | + int tm_min; |
| 42 | + int tm_hour; |
| 43 | + int tm_mday; |
| 44 | + int tm_mon; |
| 45 | + int tm_year; |
| 46 | + int tm_wday; |
| 47 | + int tm_yday; |
| 48 | + int tm_isdst; |
| 49 | +}; |
| 50 | + |
| 51 | +#ifndef __timer_t_defined |
| 52 | +# define __timer_t_defined 1 |
| 53 | +typedef __timer_t timer_t; |
| 54 | +#endif |
| 55 | + |
| 56 | +clock_t _EXFUN(clock, (void)); |
| 57 | +double _EXFUN(difftime, (time_t _time2, time_t _time1)); |
| 58 | +time_t _EXFUN(mktime, (struct tm *_timeptr)); |
| 59 | +time_t _EXFUN(time, (time_t *_timer)); |
| 60 | +#ifndef _REENT_ONLY |
| 61 | +char *_EXFUN(asctime, (const struct tm *_tblock)); |
| 62 | +char *_EXFUN(ctime, (const time_t *_time)); |
| 63 | +struct tm *_EXFUN(gmtime, (const time_t *_timer)); |
| 64 | +struct tm *_EXFUN(localtime,(const time_t *_timer)); |
| 65 | +#endif |
| 66 | +size_t _EXFUN(strftime, (char *_s, size_t _maxsize, const char *_fmt, const struct tm *_t)); |
| 67 | + |
| 68 | +char *_EXFUN(asctime_r, (const struct tm *, char *)); |
| 69 | +char *_EXFUN(ctime_r, (const time_t *, char *)); |
| 70 | +struct tm *_EXFUN(gmtime_r, (const time_t *, struct tm *)); |
| 71 | +struct tm *_EXFUN(localtime_r, (const time_t *, struct tm *)); |
| 72 | + |
| 73 | +#ifndef __STRICT_ANSI__ |
| 74 | +char *_EXFUN(strptime, (const char *, const char *, struct tm *)); |
| 75 | +_VOID _EXFUN(tzset, (_VOID)); |
| 76 | +_VOID _EXFUN(_tzset_r, (struct _reent *)); |
| 77 | + |
| 78 | +typedef struct __tzrule_struct |
| 79 | +{ |
| 80 | + char ch; |
| 81 | + int m; |
| 82 | + int n; |
| 83 | + int d; |
| 84 | + int s; |
| 85 | + time_t change; |
| 86 | + long offset; /* Match type of _timezone. */ |
| 87 | +} __tzrule_type; |
| 88 | + |
| 89 | +typedef struct __tzinfo_struct |
| 90 | +{ |
| 91 | + int __tznorth; |
| 92 | + int __tzyear; |
| 93 | + __tzrule_type __tzrule[2]; |
| 94 | +} __tzinfo_type; |
| 95 | + |
| 96 | +__tzinfo_type *_EXFUN (__gettzinfo, (_VOID)); |
| 97 | + |
| 98 | +/* getdate functions */ |
| 99 | + |
| 100 | +#ifndef _REENT_ONLY |
| 101 | +#define getdate_err (*__getdate_err()) |
| 102 | +int *_EXFUN(__getdate_err,(_VOID)); |
| 103 | + |
| 104 | +struct tm * _EXFUN(getdate, (const char *)); |
| 105 | +/* getdate_err is set to one of the following values to indicate the error. |
| 106 | + 1 the DATEMSK environment variable is null or undefined, |
| 107 | + 2 the template file cannot be opened for reading, |
| 108 | + 3 failed to get file status information, |
| 109 | + 4 the template file is not a regular file, |
| 110 | + 5 an error is encountered while reading the template file, |
| 111 | + 6 memory allication failed (not enough memory available), |
| 112 | + 7 there is no line in the template that matches the input, |
| 113 | + 8 invalid input specification */ |
| 114 | +#endif /* !_REENT_ONLY */ |
| 115 | + |
| 116 | +/* getdate_r returns the error code as above */ |
| 117 | +int _EXFUN(getdate_r, (const char *, struct tm *)); |
| 118 | + |
| 119 | +/* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ |
| 120 | +extern __IMPORT long _timezone; |
| 121 | +extern __IMPORT int _daylight; |
| 122 | +extern __IMPORT char *_tzname[2]; |
| 123 | + |
| 124 | +/* POSIX defines the external tzname being defined in time.h */ |
| 125 | +#ifndef tzname |
| 126 | +#define tzname _tzname |
| 127 | +#endif |
| 128 | + |
| 129 | +#endif /* !__STRICT_ANSI__ */ |
| 130 | + |
| 131 | +#include <sys/features.h> |
| 132 | + |
| 133 | +//#if defined(_POSIX_TIMERS) |
| 134 | + |
| 135 | +#include <signal.h> |
| 136 | + |
| 137 | +/* Clocks, P1003.1b-1993, p. 263 */ |
| 138 | + |
| 139 | +int clock_settime(clockid_t clock_id, const struct timespec *tp); |
| 140 | +int clock_gettime(clockid_t clock_id, struct timespec *tp); |
| 141 | +int clock_getres(clockid_t clock_id, struct timespec *res); |
23 | 142 |
|
24 |
| -typedef unsigned long clockid_t; |
| 143 | +/* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ |
| 144 | + |
| 145 | +int _EXFUN(timer_create, |
| 146 | + (clockid_t clock_id, struct sigevent *evp, timer_t *timerid)); |
| 147 | + |
| 148 | +/* Delete a Per_process Timer, P1003.1b-1993, p. 266 */ |
| 149 | + |
| 150 | +int _EXFUN(timer_delete, (timer_t timerid)); |
| 151 | + |
| 152 | +/* Per-Process Timers, P1003.1b-1993, p. 267 */ |
| 153 | + |
| 154 | +int _EXFUN(timer_settime, |
| 155 | + (timer_t timerid, int flags, const struct itimerspec *value, |
| 156 | + struct itimerspec *ovalue)); |
| 157 | +int _EXFUN(timer_gettime, (timer_t timerid, struct itimerspec *value)); |
| 158 | +int _EXFUN(timer_getoverrun, (timer_t timerid)); |
| 159 | + |
| 160 | +/* High Resolution Sleep, P1003.1b-1993, p. 269 */ |
| 161 | + |
| 162 | +int _EXFUN(nanosleep, (const struct timespec *rqtp, struct timespec *rmtp)); |
| 163 | + |
| 164 | +//#endif /* _POSIX_TIMERS */ |
| 165 | + |
| 166 | +/* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */ |
| 167 | + |
| 168 | +/* values for the clock enable attribute */ |
| 169 | + |
| 170 | +#define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */ |
| 171 | +#define CLOCK_DISABLED 0 /* clock is disabled */ |
| 172 | + |
| 173 | +/* values for the pthread cputime_clock_allowed attribute */ |
| 174 | + |
| 175 | +#define CLOCK_ALLOWED 1 /* If a thread is created with this value a */ |
| 176 | + /* CPU-time clock attached to that thread */ |
| 177 | + /* shall be accessible. */ |
| 178 | +#define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */ |
| 179 | + /* thread shall not have a CPU-time clock */ |
| 180 | + /* accessible. */ |
25 | 181 |
|
26 | 182 | /* Manifest Constants, P1003.1b-1993, p. 262 */
|
27 | 183 |
|
28 | 184 | #define CLOCK_REALTIME (clockid_t)0
|
29 | 185 | #define CLOCK_MONOTONIC (clockid_t)1
|
30 | 186 |
|
| 187 | +/* Flag indicating time is "absolute" with respect to the clock |
| 188 | + associated with a time. */ |
| 189 | + |
| 190 | +#define TIMER_ABSTIME 4 |
| 191 | + |
| 192 | +/* Manifest Constants, P1003.4b/D8, p. 55 */ |
| 193 | + |
| 194 | +#if defined(_POSIX_CPUTIME) |
| 195 | + |
| 196 | +/* When used in a clock or timer function call, this is interpreted as |
| 197 | + the identifier of the CPU_time clock associated with the PROCESS |
| 198 | + making the function call. */ |
| 199 | + |
| 200 | +#define CLOCK_PROCESS_CPUTIME_ID (clockid_t)2 |
| 201 | + |
31 | 202 | #endif
|
| 203 | + |
| 204 | +#if defined(_POSIX_THREAD_CPUTIME) |
| 205 | + |
| 206 | +/* When used in a clock or timer function call, this is interpreted as |
| 207 | + the identifier of the CPU_time clock associated with the THREAD |
| 208 | + making the function call. */ |
| 209 | + |
| 210 | +#define CLOCK_THREAD_CPUTIME_ID (clockid_t)3 |
| 211 | + |
| 212 | +#endif |
| 213 | + |
| 214 | +#if defined(_POSIX_CPUTIME) |
| 215 | + |
| 216 | +/* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */ |
| 217 | + |
| 218 | +int _EXFUN(clock_getcpuclockid, (pid_t pid, clockid_t *clock_id)); |
| 219 | + |
| 220 | +#endif /* _POSIX_CPUTIME */ |
| 221 | + |
| 222 | +#if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME) |
| 223 | + |
| 224 | +/* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */ |
| 225 | + |
| 226 | +int _EXFUN(clock_setenable_attr, (clockid_t clock_id, int attr)); |
| 227 | +int _EXFUN(clock_getenable_attr, (clockid_t clock_id, int *attr)); |
| 228 | + |
| 229 | +#endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */ |
| 230 | + |
| 231 | +#ifdef __cplusplus |
| 232 | +} |
| 233 | +#endif |
| 234 | + |
| 235 | +#endif /* ! __need_timespec */ |
| 236 | + |
| 237 | +#undef __need_timespec |
| 238 | + |
| 239 | +#endif /* _TIME_H_ */ |
| 240 | + |
0 commit comments