Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / include / time.h
blobab3491341ecd046ec0d7a1d79b6bf40714f95579
1 /*
2 * time.h
3 *
4 * Struct and function declarations for dealing with time.
5 */
7 #ifndef _TIME_H_
8 #define _TIME_H_
10 #include "_ansi.h"
11 #include <sys/cdefs.h>
12 #include <sys/reent.h>
14 #define __need_size_t
15 #define __need_NULL
16 #include <stddef.h>
18 /* Get _CLOCKS_PER_SEC_ */
19 #include <machine/time.h>
21 #ifndef _CLOCKS_PER_SEC_
22 #define _CLOCKS_PER_SEC_ 1000
23 #endif
25 #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_
26 #define CLK_TCK CLOCKS_PER_SEC
28 #include <sys/types.h>
29 #include <sys/timespec.h>
31 #if __POSIX_VISIBLE >= 200809
32 #include <sys/_locale.h>
33 #endif
35 _BEGIN_STD_C
37 struct tm
39 int tm_sec;
40 int tm_min;
41 int tm_hour;
42 int tm_mday;
43 int tm_mon;
44 int tm_year;
45 int tm_wday;
46 int tm_yday;
47 int tm_isdst;
48 #ifdef __TM_GMTOFF
49 long __TM_GMTOFF;
50 #endif
51 #ifdef __TM_ZONE
52 const char *__TM_ZONE;
53 #endif
56 clock_t clock (void);
57 double difftime (time_t _time2, time_t _time1);
58 time_t mktime (struct tm *_timeptr);
59 time_t time (time_t *_timer);
60 #ifndef _REENT_ONLY
61 char *asctime (const struct tm *_tblock);
62 char *ctime (const time_t *_time);
63 struct tm *gmtime (const time_t *_timer);
64 struct tm *localtime (const time_t *_timer);
65 #endif
66 size_t strftime (char *__restrict _s,
67 size_t _maxsize, const char *__restrict _fmt,
68 const struct tm *__restrict _t);
70 #if __POSIX_VISIBLE >= 200809
71 extern size_t strftime_l (char *__restrict _s, size_t _maxsize,
72 const char *__restrict _fmt,
73 const struct tm *__restrict _t, locale_t _l);
74 #endif
76 char *asctime_r (const struct tm *__restrict,
77 char *__restrict);
78 char *ctime_r (const time_t *, char *);
79 struct tm *gmtime_r (const time_t *__restrict,
80 struct tm *__restrict);
81 struct tm *localtime_r (const time_t *__restrict,
82 struct tm *__restrict);
84 _END_STD_C
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
90 #if __XSI_VISIBLE
91 char *strptime (const char *__restrict,
92 const char *__restrict,
93 struct tm *__restrict);
94 #endif
95 #if __GNU_VISIBLE
96 char *strptime_l (const char *__restrict, const char *__restrict,
97 struct tm *__restrict, locale_t);
98 #endif
100 #if __POSIX_VISIBLE
101 void tzset (void);
102 #endif
103 void _tzset_r (struct _reent *);
105 /* getdate functions */
107 #ifdef HAVE_GETDATE
108 #if __XSI_VISIBLE >= 4
109 #ifndef _REENT_ONLY
110 #define getdate_err (*__getdate_err())
111 int *__getdate_err (void);
113 struct tm * getdate (const char *);
114 /* getdate_err is set to one of the following values to indicate the error.
115 1 the DATEMSK environment variable is null or undefined,
116 2 the template file cannot be opened for reading,
117 3 failed to get file status information,
118 4 the template file is not a regular file,
119 5 an error is encountered while reading the template file,
120 6 memory allication failed (not enough memory available),
121 7 there is no line in the template that matches the input,
122 8 invalid input specification */
123 #endif /* !_REENT_ONLY */
124 #endif /* __XSI_VISIBLE >= 4 */
126 #if __GNU_VISIBLE
127 /* getdate_r returns the error code as above */
128 int getdate_r (const char *, struct tm *);
129 #endif /* __GNU_VISIBLE */
130 #endif /* HAVE_GETDATE */
132 /* defines for the opengroup specifications Derived from Issue 1 of the SVID. */
133 #if __SVID_VISIBLE || __XSI_VISIBLE
134 extern __IMPORT long _timezone;
135 extern __IMPORT int _daylight;
136 #endif
137 #if __POSIX_VISIBLE
138 extern __IMPORT char *_tzname[2];
140 /* POSIX defines the external tzname being defined in time.h */
141 #ifndef tzname
142 #define tzname _tzname
143 #endif
144 #endif /* __POSIX_VISIBLE */
146 #ifdef __cplusplus
148 #endif
150 #include <sys/features.h>
152 #ifdef __CYGWIN__
153 #include <cygwin/time.h>
154 #endif /*__CYGWIN__*/
156 #if defined(_POSIX_TIMERS)
158 #include <signal.h>
160 #ifdef __cplusplus
161 extern "C" {
162 #endif
164 /* Clocks, P1003.1b-1993, p. 263 */
166 int clock_settime (clockid_t clock_id, const struct timespec *tp);
167 int clock_gettime (clockid_t clock_id, struct timespec *tp);
168 int clock_getres (clockid_t clock_id, struct timespec *res);
170 /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */
172 int timer_create (clockid_t clock_id,
173 struct sigevent *__restrict evp,
174 timer_t *__restrict timerid);
176 /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */
178 int timer_delete (timer_t timerid);
180 /* Per-Process Timers, P1003.1b-1993, p. 267 */
182 int timer_settime (timer_t timerid, int flags,
183 const struct itimerspec *__restrict value,
184 struct itimerspec *__restrict ovalue);
185 int timer_gettime (timer_t timerid, struct itimerspec *value);
186 int timer_getoverrun (timer_t timerid);
188 /* High Resolution Sleep, P1003.1b-1993, p. 269 */
190 int nanosleep (const struct timespec *rqtp, struct timespec *rmtp);
192 #ifdef __cplusplus
194 #endif
195 #endif /* _POSIX_TIMERS */
197 #if defined(_POSIX_CLOCK_SELECTION)
199 #ifdef __cplusplus
200 extern "C" {
201 #endif
203 int clock_nanosleep (clockid_t clock_id, int flags,
204 const struct timespec *rqtp, struct timespec *rmtp);
206 #ifdef __cplusplus
208 #endif
210 #endif /* _POSIX_CLOCK_SELECTION */
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
216 /* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */
218 /* values for the clock enable attribute */
220 #define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */
221 #define CLOCK_DISABLED 0 /* clock is disabled */
223 /* values for the pthread cputime_clock_allowed attribute */
225 #define CLOCK_ALLOWED 1 /* If a thread is created with this value a */
226 /* CPU-time clock attached to that thread */
227 /* shall be accessible. */
228 #define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */
229 /* thread shall not have a CPU-time clock */
230 /* accessible. */
232 /* Flag indicating time is "absolute" with respect to the clock
233 associated with a time. Value 4 is historic. */
235 #define TIMER_ABSTIME 4
237 /* Manifest Constants, P1003.1b-1993, p. 262 */
239 #if __GNU_VISIBLE
240 #define CLOCK_REALTIME_COARSE (0)
241 #endif
243 #define CLOCK_REALTIME (1)
245 /* Manifest Constants, P1003.4b/D8, p. 55 */
247 #if defined(_POSIX_CPUTIME)
249 /* When used in a clock or timer function call, this is interpreted as
250 the identifier of the CPU_time clock associated with the PROCESS
251 making the function call. */
253 #define CLOCK_PROCESS_CPUTIME_ID (2)
255 #endif
257 #if defined(_POSIX_THREAD_CPUTIME)
259 /* When used in a clock or timer function call, this is interpreted as
260 the identifier of the CPU_time clock associated with the THREAD
261 making the function call. */
263 #define CLOCK_THREAD_CPUTIME_ID (3)
265 #endif
267 #if defined(_POSIX_MONOTONIC_CLOCK)
269 /* The identifier for the system-wide monotonic clock, which is defined
270 * as a clock whose value cannot be set via clock_settime() and which
271 * cannot have backward clock jumps. */
273 #define CLOCK_MONOTONIC (4)
275 #endif
277 #if __GNU_VISIBLE
279 #define CLOCK_MONOTONIC_RAW (5)
281 #define CLOCK_MONOTONIC_COARSE (6)
283 #define CLOCK_BOOTTIME (7)
285 #define CLOCK_REALTIME_ALARM (8)
287 #define CLOCK_BOOTTIME_ALARM (9)
289 #endif
291 #if defined(_POSIX_CPUTIME)
293 /* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */
295 int clock_getcpuclockid (pid_t pid, clockid_t *clock_id);
297 #endif /* _POSIX_CPUTIME */
299 #if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME)
301 /* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */
303 int clock_setenable_attr (clockid_t clock_id, int attr);
304 int clock_getenable_attr (clockid_t clock_id, int *attr);
306 #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */
308 #ifdef __cplusplus
310 #endif
312 #endif /* _TIME_H_ */