2 * D header file for POSIX.
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
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)
16 module core.sys.posix.time;
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
29 else version (WatchOS)
38 // Required (defined in core.stdc.time)
41 char* asctime(in tm*);
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*);
48 size_t strftime(char*, size_t, in char*, in tm*);
52 version (CRuntime_Glibc)
54 time_t timegm(tm*); // non-standard
58 time_t timegm(tm*); // non-standard
60 else version (FreeBSD)
62 time_t timegm(tm*); // non-standard
66 time_t timegm(tm*); // non-standard
68 else version (DragonFlyBSD)
70 time_t timegm(tm*); // non-standard
72 else version (Solaris)
74 time_t timegm(tm*); // non-standard
76 else version (CRuntime_Bionic)
80 else version (CRuntime_Musl)
84 else version (CRuntime_UClibc)
90 static assert(false, "Unsupported platform");
95 // (defined in core.stdc.time)
103 // Process CPU-Time Clocks (CPT)
106 int clock_getcpuclockid(pid_t, clockid_t*);
110 // Clock Selection (CS)
113 int clock_nanosleep(clockid_t, int, in timespec*, timespec*);
117 // Monotonic Clock (MON)
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
133 else version (FreeBSD)
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;
143 else version (NetBSD)
146 enum CLOCK_MONOTONIC = 3;
148 else version (DragonFlyBSD)
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;
158 else version (Darwin)
160 // No CLOCK_MONOTONIC defined
162 else version (Solaris)
164 enum CLOCK_MONOTONIC = 4;
175 CLOCK_PROCESS_CPUTIME_ID (TMR|CPT)
176 CLOCK_THREAD_CPUTIME_ID (TMR|TCT)
178 NOTE: timespec must be defined in core.sys.posix.signal to break
189 timespec it_interval;
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*);
210 version (CRuntime_Glibc)
212 enum CLOCK_PROCESS_CPUTIME_ID = 2;
213 enum CLOCK_THREAD_CPUTIME_ID = 3;
215 // NOTE: See above for why this is commented out.
225 timespec it_interval;
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;
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*);
249 else version (Darwin)
251 int nanosleep(in timespec*, timespec*);
253 else version (FreeBSD)
255 //enum CLOCK_PROCESS_CPUTIME_ID = ??;
256 enum CLOCK_THREAD_CPUTIME_ID = 15;
258 // NOTE: See above for why this is commented out.
268 timespec it_interval;
272 enum CLOCK_REALTIME = 0;
273 enum TIMER_ABSTIME = 0x01;
275 alias int clockid_t; // <sys/_types.h>
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*);
288 else version (DragonFlyBSD)
290 enum CLOCK_THREAD_CPUTIME_ID = 15;
294 timespec it_interval;
298 enum CLOCK_REALTIME = 0;
299 enum TIMER_ABSTIME = 0x01;
301 alias int clockid_t; // <sys/_types.h>
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*);
314 else version (NetBSD)
318 timespec it_interval;
322 enum CLOCK_REALTIME = 0;
323 enum TIMER_ABSTIME = 0x01;
325 alias int clockid_t; // <sys/_types.h>
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*);
338 else version (Solaris)
340 enum CLOCK_PROCESS_CPUTIME_ID = 5; // <sys/time_impl.h>
341 enum CLOCK_THREAD_CPUTIME_ID = 2; // <sys/time_impl.h>
345 timespec it_interval;
349 enum CLOCK_REALTIME = 3; // <sys/time_impl.h>
350 enum TIMER_ABSOLUTE = 0x1;
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*);
360 int nanosleep(in timespec*, timespec*);
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*);
368 else version (CRuntime_Bionic)
370 enum CLOCK_PROCESS_CPUTIME_ID = 2;
371 enum CLOCK_THREAD_CPUTIME_ID = 3;
375 timespec it_interval;
379 enum CLOCK_REALTIME = 0;
380 enum CLOCK_REALTIME_HR = 4;
381 enum TIMER_ABSTIME = 0x01;
384 alias void* timer_t; // Updated since Lollipop
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*);
395 else version (CRuntime_Musl)
402 timespec it_interval;
406 enum TIMER_ABSTIME = 1;
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;
418 int nanosleep(in timespec*, timespec*);
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 *);
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);
432 else version (CRuntime_UClibc)
434 enum CLOCK_REALTIME = 0;
435 enum CLOCK_PROCESS_CPUTIME_ID = 2;
436 enum CLOCK_THREAD_CPUTIME_ID = 3;
440 timespec it_interval;
444 enum TIMER_ABSTIME = 0x01;
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*);
461 static assert(false, "Unsupported platform");
465 // Thread-Safe Functions (TSF)
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*);
474 version (CRuntime_Glibc)
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*);
481 else version (Darwin)
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*);
488 else version (FreeBSD)
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*);
495 else version (NetBSD)
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*);
502 else version (DragonFlyBSD)
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*);
509 else version (Solaris)
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*);
516 else version (CRuntime_Bionic)
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*);
523 else version (CRuntime_Musl)
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*);
530 else version (CRuntime_UClibc)
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*);
539 static assert(false, "Unsupported platform");
551 tm* getdate(in char*);
552 char* strptime(in char*, in char*, tm*);
555 version (CRuntime_Glibc)
557 extern __gshared int daylight;
558 extern __gshared c_long timezone;
560 tm* getdate(in char*);
561 char* strptime(in char*, in char*, tm*);
563 else version (Darwin)
565 extern __gshared c_long timezone;
566 extern __gshared int daylight;
568 tm* getdate(in char*);
569 char* strptime(in char*, in char*, tm*);
571 else version (FreeBSD)
573 //tm* getdate(in char*);
574 char* strptime(in char*, in char*, tm*);
576 else version (NetBSD)
578 tm* getdate(in char*);
579 char* strptime(in char*, in char*, tm*);
581 else version (DragonFlyBSD)
583 //tm* getdate(in char*);
584 char* strptime(in char*, in char*, tm*);
586 else version (Solaris)
588 extern __gshared c_long timezone, altzone;
589 extern __gshared int daylight;
591 tm* getdate(in char*);
592 char* __strptime_dontzero(in char*, in char*, tm*);
593 alias __strptime_dontzero strptime;
595 else version (CRuntime_Bionic)
597 extern __gshared int daylight;
598 extern __gshared c_long timezone;
600 char* strptime(in char*, in char*, tm*);
602 else version (CRuntime_Musl)
604 tm* getdate(in char*);
605 char* strptime(in char*, in char*, tm*);
607 else version (CRuntime_UClibc)
609 extern __gshared int daylight;
610 extern __gshared c_long timezone;
612 tm* getdate(in char*);
613 char* strptime(in char*, in char*, tm*);
617 static assert(false, "Unsupported platform");