132
|
1 /**
|
|
2 * D header file for POSIX.
|
|
3 *
|
|
4 * Copyright: Public Domain
|
|
5 * License: Public Domain
|
|
6 * Authors: Sean Kelly
|
|
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
|
|
8 */
|
|
9 module tango.stdc.posix.time;
|
|
10
|
|
11 private import tango.stdc.posix.config;
|
|
12 public import tango.stdc.time;
|
|
13 public import tango.stdc.posix.sys.types;
|
|
14 public import tango.stdc.posix.signal; // for sigevent
|
|
15
|
|
16 extern (C):
|
|
17
|
|
18 //
|
|
19 // Required (defined in tango.stdc.time)
|
|
20 //
|
|
21 /*
|
|
22 char* asctime(tm*);
|
|
23 clock_t clock();
|
|
24 char* ctime(time_t*);
|
|
25 double difftime(time_t, time_t);
|
|
26 tm* gmtime(time_t*);
|
|
27 tm* localtime(time_t*);
|
|
28 time_t mktime(tm*);
|
|
29 size_t strftime(char*, size_t, char*, tm*);
|
|
30 time_t time(time_t*);
|
|
31 */
|
|
32
|
|
33 version( linux )
|
|
34 {
|
|
35 time_t timegm(tm*); // non-standard
|
|
36 }
|
|
37 else version( darwin )
|
|
38 {
|
|
39 time_t timegm(tm*); // non-standard
|
|
40 }
|
|
41
|
|
42 //
|
|
43 // C Extension (CX)
|
|
44 // (defined in tango.stdc.time)
|
|
45 //
|
|
46 /*
|
|
47 char* tzname[];
|
|
48 void tzset();
|
|
49 */
|
|
50
|
|
51 //
|
|
52 // Process CPU-Time Clocks (CPT)
|
|
53 //
|
|
54 /*
|
|
55 int clock_getcpuclockid(pid_t, clockid_t*);
|
|
56 */
|
|
57
|
|
58 //
|
|
59 // Clock Selection (CS)
|
|
60 //
|
|
61 /*
|
|
62 int clock_nanosleep(clockid_t, int, timespec*, timespec*);
|
|
63 */
|
|
64
|
|
65 //
|
|
66 // Monotonic Clock (MON)
|
|
67 //
|
|
68 /*
|
|
69 CLOCK_MONOTONIC
|
|
70 */
|
|
71
|
|
72 //
|
|
73 // Timer (TMR)
|
|
74 //
|
|
75 /*
|
|
76 CLOCK_PROCESS_CPUTIME_ID (TMR|CPT)
|
|
77 CLOCK_THREAD_CPUTIME_ID (TMR|TCT)
|
|
78
|
|
79 NOTE: timespec must be defined in tango.stdc.posix.signal to break
|
|
80 a circular import.
|
|
81
|
|
82 struct timespec
|
|
83 {
|
|
84 time_t tv_sec;
|
|
85 int tv_nsec;
|
|
86 }
|
|
87
|
|
88 struct itimerspec
|
|
89 {
|
|
90 timespec it_interval;
|
|
91 timespec it_value;
|
|
92 }
|
|
93
|
|
94 CLOCK_REALTIME
|
|
95 TIMER_ABSTIME
|
|
96
|
|
97 clockid_t
|
|
98 timer_t
|
|
99
|
|
100 int clock_getres(clockid_t, timespec*);
|
|
101 int clock_gettime(clockid_t, timespec*);
|
|
102 int clock_settime(clockid_t, timespec*);
|
|
103 int nanosleep(timespec*, timespec*);
|
|
104 int timer_create(clockid_t, sigevent*, timer_t*);
|
|
105 int timer_delete(timer_t);
|
|
106 int timer_gettime(timer_t, itimerspec*);
|
|
107 int timer_getoverrun(timer_t);
|
|
108 int timer_settime(timer_t, int, itimerspec*, itimerspec*);
|
|
109 */
|
|
110
|
|
111 version( linux )
|
|
112 {
|
|
113 const CLOCK_PROCESS_CPUTIME_ID = 2; // (TMR|CPT)
|
|
114 const CLOCK_THREAD_CPUTIME_ID = 3; // (TMR|TCT)
|
|
115
|
|
116 // NOTE: See above for why this is commented out.
|
|
117 //
|
|
118 //struct timespec
|
|
119 //{
|
|
120 // time_t tv_sec;
|
|
121 // c_long tv_nsec;
|
|
122 //}
|
|
123
|
|
124 struct itimerspec
|
|
125 {
|
|
126 timespec it_interval;
|
|
127 timespec it_value;
|
|
128 }
|
|
129
|
|
130 const CLOCK_REALTIME = 0;
|
|
131 const TIMER_ABSTIME = 0x01;
|
|
132
|
|
133 alias int clockid_t;
|
|
134 alias int timer_t;
|
|
135
|
|
136 int clock_getres(clockid_t, timespec*);
|
|
137 //int clock_gettime(clockid_t, timespec*);
|
|
138 //int clock_settime(clockid_t, timespec*);
|
|
139 int nanosleep(timespec*, timespec*);
|
|
140 int timer_create(clockid_t, sigevent*, timer_t*);
|
|
141 int timer_delete(timer_t);
|
|
142 int timer_gettime(timer_t, itimerspec*);
|
|
143 int timer_getoverrun(timer_t);
|
|
144 int timer_settime(timer_t, int, itimerspec*, itimerspec*);
|
|
145 }
|
|
146 else version( darwin )
|
|
147 {
|
|
148 int nanosleep(timespec*, timespec*);
|
|
149 }
|
|
150
|
|
151
|
|
152 //
|
|
153 // Thread-Safe Functions (TSF)
|
|
154 //
|
|
155 /*
|
|
156 char* asctime_r(tm*, char*);
|
|
157 char* ctime_r(time_t*, char*);
|
|
158 tm* gmtime_r(time_t*, tm*);
|
|
159 tm* localtime_r(time_t*, tm*);
|
|
160 */
|
|
161
|
|
162 version( linux )
|
|
163 {
|
|
164 char* asctime_r(tm*, char*);
|
|
165 char* ctime_r(time_t*, char*);
|
|
166 tm* gmtime_r(time_t*, tm*);
|
|
167 tm* localtime_r(time_t*, tm*);
|
|
168 }
|
|
169 else version( darwin )
|
|
170 {
|
|
171 char* asctime_r(tm*, char*);
|
|
172 char* ctime_r(time_t*, char*);
|
|
173 tm* gmtime_r(time_t*, tm*);
|
|
174 tm* localtime_r(time_t*, tm*);
|
|
175 }
|
|
176
|
|
177 //
|
|
178 // XOpen (XSI)
|
|
179 //
|
|
180 /*
|
|
181 getdate_err
|
|
182
|
|
183 int daylight;
|
|
184 int timezone;
|
|
185
|
|
186 tm* getdate(char*);
|
|
187 char* strptime(char*, char*, tm*);
|
|
188 */
|
|
189
|
|
190 version( linux )
|
|
191 {
|
|
192 extern int daylight;
|
|
193 extern c_long timezone;
|
|
194
|
|
195 tm* getdate(char*);
|
|
196 char* strptime(char*, char*, tm*);
|
|
197 }
|
|
198 else version( darwin )
|
|
199 {
|
|
200 extern c_long timezone;
|
|
201
|
|
202 tm* getdate(char *);
|
|
203 char* strptime(char*, char*, tm*);
|
|
204 }
|