]> git.ipfire.org Git - thirdparty/gcc.git/blob - libphobos/libdruntime/core/sys/posix/time.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / libphobos / libdruntime / core / sys / posix / time.d
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Sean Kelly,
7 Alex Rønne Petersen
8 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9 */
10
11 /* Copyright Sean Kelly 2005 - 2009.
12 * Distributed under the Boost Software License, Version 1.0.
13 * (See accompanying file LICENSE or copy at
14 * http://www.boost.org/LICENSE_1_0.txt)
15 */
16 module core.sys.posix.time;
17
18 private import core.sys.posix.config;
19 public import core.stdc.time;
20 public import core.sys.posix.sys.types;
21 public import core.sys.posix.signal; // for sigevent
22
23 version (OSX)
24 version = Darwin;
25 else version (iOS)
26 version = Darwin;
27 else version (TVOS)
28 version = Darwin;
29 else version (WatchOS)
30 version = Darwin;
31
32 version (Posix):
33 extern (C):
34 nothrow:
35 @nogc:
36
37 //
38 // Required (defined in core.stdc.time)
39 //
40 /*
41 char* asctime(in tm*);
42 clock_t clock();
43 char* ctime(in time_t*);
44 double difftime(time_t, time_t);
45 tm* gmtime(in time_t*);
46 tm* localtime(in time_t*);
47 time_t mktime(tm*);
48 size_t strftime(char*, size_t, in char*, in tm*);
49 time_t time(time_t*);
50 */
51
52 version (CRuntime_Glibc)
53 {
54 time_t timegm(tm*); // non-standard
55 }
56 else version (Darwin)
57 {
58 time_t timegm(tm*); // non-standard
59 }
60 else version (FreeBSD)
61 {
62 time_t timegm(tm*); // non-standard
63 }
64 else version (NetBSD)
65 {
66 time_t timegm(tm*); // non-standard
67 }
68 else version (DragonFlyBSD)
69 {
70 time_t timegm(tm*); // non-standard
71 }
72 else version (Solaris)
73 {
74 time_t timegm(tm*); // non-standard
75 }
76 else version (CRuntime_Bionic)
77 {
78 // Not supported.
79 }
80 else version (CRuntime_Musl)
81 {
82 time_t timegm(tm*);
83 }
84 else version (CRuntime_UClibc)
85 {
86 time_t timegm(tm*);
87 }
88 else
89 {
90 static assert(false, "Unsupported platform");
91 }
92
93 //
94 // C Extension (CX)
95 // (defined in core.stdc.time)
96 //
97 /*
98 char* tzname[];
99 void tzset();
100 */
101
102 //
103 // Process CPU-Time Clocks (CPT)
104 //
105 /*
106 int clock_getcpuclockid(pid_t, clockid_t*);
107 */
108
109 //
110 // Clock Selection (CS)
111 //
112 /*
113 int clock_nanosleep(clockid_t, int, in timespec*, timespec*);
114 */
115
116 //
117 // Monotonic Clock (MON)
118 //
119 /*
120 CLOCK_MONOTONIC
121 */
122
123 version (linux)
124 {
125 enum CLOCK_MONOTONIC = 1;
126 // To be removed in December 2015.
127 static import core.sys.linux.time;
128 deprecated("Please import it from core.sys.linux.time instead.")
129 alias CLOCK_MONOTONIC_RAW = core.sys.linux.time.CLOCK_MONOTONIC_RAW; // non-standard
130 deprecated("Please import it from core.sys.linux.time instead.")
131 alias CLOCK_MONOTONIC_COARSE = core.sys.linux.time.CLOCK_MONOTONIC_COARSE; // non-standard
132 }
133 else version (FreeBSD)
134 { // time.h
135 enum CLOCK_MONOTONIC = 4;
136 // To be removed in December 2015.
137 static import core.sys.freebsd.time;
138 deprecated("Please import it from core.sys.freebsd.time instead.")
139 alias CLOCK_MONOTONIC_PRECISE = core.sys.freebsd.time.CLOCK_MONOTONIC_PRECISE;
140 deprecated("Please import it from core.sys.freebsd.time instead.")
141 alias CLOCK_MONOTONIC_FAST = core.sys.freebsd.time.CLOCK_MONOTONIC_FAST;
142 }
143 else version (NetBSD)
144 {
145 // time.h
146 enum CLOCK_MONOTONIC = 3;
147 }
148 else version (DragonFlyBSD)
149 { // time.h
150 enum CLOCK_MONOTONIC = 4;
151 // To be removed in December 2015.
152 static import core.sys.dragonflybsd.time;
153 deprecated("Please import it from core.sys.dragonflybsd.time instead.")
154 alias CLOCK_MONOTONIC_PRECISE = core.sys.dragonflybsd.time.CLOCK_MONOTONIC_PRECISE;
155 deprecated("Please import it from core.sys.dragonflybsd.time instead.")
156 alias CLOCK_MONOTONIC_FAST = core.sys.dragonflybsd.time.CLOCK_MONOTONIC_FAST;
157 }
158 else version (Darwin)
159 {
160 // No CLOCK_MONOTONIC defined
161 }
162 else version (Solaris)
163 {
164 enum CLOCK_MONOTONIC = 4;
165 }
166 else
167 {
168 static assert(0);
169 }
170
171 //
172 // Timer (TMR)
173 //
174 /*
175 CLOCK_PROCESS_CPUTIME_ID (TMR|CPT)
176 CLOCK_THREAD_CPUTIME_ID (TMR|TCT)
177
178 NOTE: timespec must be defined in core.sys.posix.signal to break
179 a circular import.
180
181 struct timespec
182 {
183 time_t tv_sec;
184 int tv_nsec;
185 }
186
187 struct itimerspec
188 {
189 timespec it_interval;
190 timespec it_value;
191 }
192
193 CLOCK_REALTIME
194 TIMER_ABSTIME
195
196 clockid_t
197 timer_t
198
199 int clock_getres(clockid_t, timespec*);
200 int clock_gettime(clockid_t, timespec*);
201 int clock_settime(clockid_t, in timespec*);
202 int nanosleep(in timespec*, timespec*);
203 int timer_create(clockid_t, sigevent*, timer_t*);
204 int timer_delete(timer_t);
205 int timer_gettime(timer_t, itimerspec*);
206 int timer_getoverrun(timer_t);
207 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
208 */
209
210 version (CRuntime_Glibc)
211 {
212 enum CLOCK_PROCESS_CPUTIME_ID = 2;
213 enum CLOCK_THREAD_CPUTIME_ID = 3;
214
215 // NOTE: See above for why this is commented out.
216 //
217 //struct timespec
218 //{
219 // time_t tv_sec;
220 // c_long tv_nsec;
221 //}
222
223 struct itimerspec
224 {
225 timespec it_interval;
226 timespec it_value;
227 }
228
229 enum CLOCK_REALTIME = 0;
230 // To be removed in December 2015.
231 static import core.sys.linux.time;
232 deprecated("Please import it from core.sys.linux.time instead.")
233 alias CLOCK_REALTIME_COARSE = core.sys.linux.time.CLOCK_REALTIME_COARSE; // non-standard
234 enum TIMER_ABSTIME = 0x01;
235
236 alias int clockid_t;
237 alias void* timer_t;
238
239 int clock_getres(clockid_t, timespec*);
240 int clock_gettime(clockid_t, timespec*);
241 int clock_settime(clockid_t, in timespec*);
242 int nanosleep(in timespec*, timespec*);
243 int timer_create(clockid_t, sigevent*, timer_t*);
244 int timer_delete(timer_t);
245 int timer_gettime(timer_t, itimerspec*);
246 int timer_getoverrun(timer_t);
247 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
248 }
249 else version (Darwin)
250 {
251 int nanosleep(in timespec*, timespec*);
252 }
253 else version (FreeBSD)
254 {
255 //enum CLOCK_PROCESS_CPUTIME_ID = ??;
256 enum CLOCK_THREAD_CPUTIME_ID = 15;
257
258 // NOTE: See above for why this is commented out.
259 //
260 //struct timespec
261 //{
262 // time_t tv_sec;
263 // c_long tv_nsec;
264 //}
265
266 struct itimerspec
267 {
268 timespec it_interval;
269 timespec it_value;
270 }
271
272 enum CLOCK_REALTIME = 0;
273 enum TIMER_ABSTIME = 0x01;
274
275 alias int clockid_t; // <sys/_types.h>
276 alias int timer_t;
277
278 int clock_getres(clockid_t, timespec*);
279 int clock_gettime(clockid_t, timespec*);
280 int clock_settime(clockid_t, in timespec*);
281 int nanosleep(in timespec*, timespec*);
282 int timer_create(clockid_t, sigevent*, timer_t*);
283 int timer_delete(timer_t);
284 int timer_gettime(timer_t, itimerspec*);
285 int timer_getoverrun(timer_t);
286 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
287 }
288 else version (DragonFlyBSD)
289 {
290 enum CLOCK_THREAD_CPUTIME_ID = 15;
291
292 struct itimerspec
293 {
294 timespec it_interval;
295 timespec it_value;
296 }
297
298 enum CLOCK_REALTIME = 0;
299 enum TIMER_ABSTIME = 0x01;
300
301 alias int clockid_t; // <sys/_types.h>
302 alias int timer_t;
303
304 int clock_getres(clockid_t, timespec*);
305 int clock_gettime(clockid_t, timespec*);
306 int clock_settime(clockid_t, in timespec*);
307 int nanosleep(in timespec*, timespec*);
308 int timer_create(clockid_t, sigevent*, timer_t*);
309 int timer_delete(timer_t);
310 int timer_gettime(timer_t, itimerspec*);
311 int timer_getoverrun(timer_t);
312 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
313 }
314 else version (NetBSD)
315 {
316 struct itimerspec
317 {
318 timespec it_interval;
319 timespec it_value;
320 }
321
322 enum CLOCK_REALTIME = 0;
323 enum TIMER_ABSTIME = 0x01;
324
325 alias int clockid_t; // <sys/_types.h>
326 alias int timer_t;
327
328 int clock_getres(clockid_t, timespec*);
329 int clock_gettime(clockid_t, timespec*);
330 int clock_settime(clockid_t, in timespec*);
331 int nanosleep(in timespec*, timespec*);
332 int timer_create(clockid_t, sigevent*, timer_t*);
333 int timer_delete(timer_t);
334 int timer_gettime(timer_t, itimerspec*);
335 int timer_getoverrun(timer_t);
336 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
337 }
338 else version (Solaris)
339 {
340 enum CLOCK_PROCESS_CPUTIME_ID = 5; // <sys/time_impl.h>
341 enum CLOCK_THREAD_CPUTIME_ID = 2; // <sys/time_impl.h>
342
343 struct itimerspec
344 {
345 timespec it_interval;
346 timespec it_value;
347 }
348
349 enum CLOCK_REALTIME = 3; // <sys/time_impl.h>
350 enum TIMER_ABSOLUTE = 0x1;
351
352 alias int clockid_t;
353 alias int timer_t;
354
355 int clock_getres(clockid_t, timespec*);
356 int clock_gettime(clockid_t, timespec*);
357 int clock_settime(clockid_t, in timespec*);
358 int clock_nanosleep(clockid_t, int, in timespec*, timespec*);
359
360 int nanosleep(in timespec*, timespec*);
361
362 int timer_create(clockid_t, sigevent*, timer_t*);
363 int timer_delete(timer_t);
364 int timer_getoverrun(timer_t);
365 int timer_gettime(timer_t, itimerspec*);
366 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
367 }
368 else version (CRuntime_Bionic)
369 {
370 enum CLOCK_PROCESS_CPUTIME_ID = 2;
371 enum CLOCK_THREAD_CPUTIME_ID = 3;
372
373 struct itimerspec
374 {
375 timespec it_interval;
376 timespec it_value;
377 }
378
379 enum CLOCK_REALTIME = 0;
380 enum CLOCK_REALTIME_HR = 4;
381 enum TIMER_ABSTIME = 0x01;
382
383 alias int clockid_t;
384 alias void* timer_t; // Updated since Lollipop
385
386 int clock_getres(int, timespec*);
387 int clock_gettime(int, timespec*);
388 int nanosleep(in timespec*, timespec*);
389 int timer_create(int, sigevent*, timer_t*);
390 int timer_delete(timer_t);
391 int timer_gettime(timer_t, itimerspec*);
392 int timer_getoverrun(timer_t);
393 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
394 }
395 else version (CRuntime_Musl)
396 {
397 alias int clockid_t;
398 alias void* timer_t;
399
400 struct itimerspec
401 {
402 timespec it_interval;
403 timespec it_value;
404 }
405
406 enum TIMER_ABSTIME = 1;
407
408 enum CLOCK_REALTIME = 0;
409 enum CLOCK_PROCESS_CPUTIME_ID = 2;
410 enum CLOCK_THREAD_CPUTIME_ID = 3;
411 enum CLOCK_REALTIME_COARSE = 5;
412 enum CLOCK_BOOTTIME = 7;
413 enum CLOCK_REALTIME_ALARM = 8;
414 enum CLOCK_BOOTTIME_ALARM = 9;
415 enum CLOCK_SGI_CYCLE = 10;
416 enum CLOCK_TAI = 11;
417
418 int nanosleep(in timespec*, timespec*);
419
420 int clock_getres(clockid_t, timespec*);
421 int clock_gettime(clockid_t, timespec*);
422 int clock_settime(clockid_t, in timespec*);
423 int clock_nanosleep(clockid_t, int, in timespec*, timespec*);
424 int clock_getcpuclockid(pid_t, clockid_t *);
425
426 int timer_create(clockid_t, sigevent*, timer_t*);
427 int timer_delete(timer_t);
428 int timer_gettime(timer_t, itimerspec*);
429 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
430 int timer_getoverrun(timer_t);
431 }
432 else version (CRuntime_UClibc)
433 {
434 enum CLOCK_REALTIME = 0;
435 enum CLOCK_PROCESS_CPUTIME_ID = 2;
436 enum CLOCK_THREAD_CPUTIME_ID = 3;
437
438 struct itimerspec
439 {
440 timespec it_interval;
441 timespec it_value;
442 }
443
444 enum TIMER_ABSTIME = 0x01;
445
446 alias int clockid_t;
447 alias void* timer_t;
448
449 int clock_getres(clockid_t, timespec*);
450 int clock_gettime(clockid_t, timespec*);
451 int clock_settime(clockid_t, in timespec*);
452 int nanosleep(in timespec*, timespec*);
453 int timer_create(clockid_t, sigevent*, timer_t*);
454 int timer_delete(timer_t);
455 int timer_gettime(timer_t, itimerspec*);
456 int timer_getoverrun(timer_t);
457 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
458 }
459 else
460 {
461 static assert(false, "Unsupported platform");
462 }
463
464 //
465 // Thread-Safe Functions (TSF)
466 //
467 /*
468 char* asctime_r(in tm*, char*);
469 char* ctime_r(in time_t*, char*);
470 tm* gmtime_r(in time_t*, tm*);
471 tm* localtime_r(in time_t*, tm*);
472 */
473
474 version (CRuntime_Glibc)
475 {
476 char* asctime_r(in tm*, char*);
477 char* ctime_r(in time_t*, char*);
478 tm* gmtime_r(in time_t*, tm*);
479 tm* localtime_r(in time_t*, tm*);
480 }
481 else version (Darwin)
482 {
483 char* asctime_r(in tm*, char*);
484 char* ctime_r(in time_t*, char*);
485 tm* gmtime_r(in time_t*, tm*);
486 tm* localtime_r(in time_t*, tm*);
487 }
488 else version (FreeBSD)
489 {
490 char* asctime_r(in tm*, char*);
491 char* ctime_r(in time_t*, char*);
492 tm* gmtime_r(in time_t*, tm*);
493 tm* localtime_r(in time_t*, tm*);
494 }
495 else version (NetBSD)
496 {
497 char* asctime_r(in tm*, char*);
498 char* ctime_r(in time_t*, char*);
499 tm* gmtime_r(in time_t*, tm*);
500 tm* localtime_r(in time_t*, tm*);
501 }
502 else version (DragonFlyBSD)
503 {
504 char* asctime_r(in tm*, char*);
505 char* ctime_r(in time_t*, char*);
506 tm* gmtime_r(in time_t*, tm*);
507 tm* localtime_r(in time_t*, tm*);
508 }
509 else version (Solaris)
510 {
511 char* asctime_r(in tm*, char*);
512 char* ctime_r(in time_t*, char*);
513 tm* gmtime_r(in time_t*, tm*);
514 tm* localtime_r(in time_t*, tm*);
515 }
516 else version (CRuntime_Bionic)
517 {
518 char* asctime_r(in tm*, char*);
519 char* ctime_r(in time_t*, char*);
520 tm* gmtime_r(in time_t*, tm*);
521 tm* localtime_r(in time_t*, tm*);
522 }
523 else version (CRuntime_Musl)
524 {
525 char* asctime_r(in tm*, char*);
526 char* ctime_r(in time_t*, char*);
527 tm* gmtime_r(in time_t*, tm*);
528 tm* localtime_r(in time_t*, tm*);
529 }
530 else version (CRuntime_UClibc)
531 {
532 char* asctime_r(in tm*, char*);
533 char* ctime_r(in time_t*, char*);
534 tm* gmtime_r(in time_t*, tm*);
535 tm* localtime_r(in time_t*, tm*);
536 }
537 else
538 {
539 static assert(false, "Unsupported platform");
540 }
541
542 //
543 // XOpen (XSI)
544 //
545 /*
546 getdate_err
547
548 int daylight;
549 int timezone;
550
551 tm* getdate(in char*);
552 char* strptime(in char*, in char*, tm*);
553 */
554
555 version (CRuntime_Glibc)
556 {
557 extern __gshared int daylight;
558 extern __gshared c_long timezone;
559
560 tm* getdate(in char*);
561 char* strptime(in char*, in char*, tm*);
562 }
563 else version (Darwin)
564 {
565 extern __gshared c_long timezone;
566 extern __gshared int daylight;
567
568 tm* getdate(in char*);
569 char* strptime(in char*, in char*, tm*);
570 }
571 else version (FreeBSD)
572 {
573 //tm* getdate(in char*);
574 char* strptime(in char*, in char*, tm*);
575 }
576 else version (NetBSD)
577 {
578 tm* getdate(in char*);
579 char* strptime(in char*, in char*, tm*);
580 }
581 else version (DragonFlyBSD)
582 {
583 //tm* getdate(in char*);
584 char* strptime(in char*, in char*, tm*);
585 }
586 else version (Solaris)
587 {
588 extern __gshared c_long timezone, altzone;
589 extern __gshared int daylight;
590
591 tm* getdate(in char*);
592 char* __strptime_dontzero(in char*, in char*, tm*);
593 alias __strptime_dontzero strptime;
594 }
595 else version (CRuntime_Bionic)
596 {
597 extern __gshared int daylight;
598 extern __gshared c_long timezone;
599
600 char* strptime(in char*, in char*, tm*);
601 }
602 else version (CRuntime_Musl)
603 {
604 tm* getdate(in char*);
605 char* strptime(in char*, in char*, tm*);
606 }
607 else version (CRuntime_UClibc)
608 {
609 extern __gshared int daylight;
610 extern __gshared c_long timezone;
611
612 tm* getdate(in char*);
613 char* strptime(in char*, in char*, tm*);
614 }
615 else
616 {
617 static assert(false, "Unsupported platform");
618 }