comparison druntime/import/core/sys/posix/time.d @ 1458:e0b2d67cfe7c

Added druntime (this should be removed once it works).
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 02 Jun 2009 17:43:06 +0100
parents
children
comparison
equal deleted inserted replaced
1456:7b218ec1044f 1458:e0b2d67cfe7c
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>.
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 *
9 * Copyright Sean Kelly 2005 - 2009.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE_1_0.txt or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
13 */
14 module core.sys.posix.time;
15
16 private import core.sys.posix.config;
17 public import core.stdc.time;
18 public import core.sys.posix.sys.types;
19 public import core.sys.posix.signal; // for sigevent
20
21 extern (C):
22
23 //
24 // Required (defined in core.stdc.time)
25 //
26 /*
27 char* asctime(in tm*);
28 clock_t clock();
29 char* ctime(in time_t*);
30 double difftime(time_t, time_t);
31 tm* gmtime(in time_t*);
32 tm* localtime(in time_t*);
33 time_t mktime(tm*);
34 size_t strftime(char*, size_t, in char*, in tm*);
35 time_t time(time_t*);
36 */
37
38 version( linux )
39 {
40 time_t timegm(tm*); // non-standard
41 }
42 else version( OSX )
43 {
44 time_t timegm(tm*); // non-standard
45 }
46 else version( freebsd )
47 {
48 time_t timegm(tm*); // non-standard
49 }
50
51 //
52 // C Extension (CX)
53 // (defined in core.stdc.time)
54 //
55 /*
56 char* tzname[];
57 void tzset();
58 */
59
60 //
61 // Process CPU-Time Clocks (CPT)
62 //
63 /*
64 int clock_getcpuclockid(pid_t, clockid_t*);
65 */
66
67 //
68 // Clock Selection (CS)
69 //
70 /*
71 int clock_nanosleep(clockid_t, int, in timespec*, timespec*);
72 */
73
74 //
75 // Monotonic Clock (MON)
76 //
77 /*
78 CLOCK_MONOTONIC
79 */
80
81 //
82 // Timer (TMR)
83 //
84 /*
85 CLOCK_PROCESS_CPUTIME_ID (TMR|CPT)
86 CLOCK_THREAD_CPUTIME_ID (TMR|TCT)
87
88 NOTE: timespec must be defined in core.sys.posix.signal to break
89 a circular import.
90
91 struct timespec
92 {
93 time_t tv_sec;
94 int tv_nsec;
95 }
96
97 struct itimerspec
98 {
99 timespec it_interval;
100 timespec it_value;
101 }
102
103 CLOCK_REALTIME
104 TIMER_ABSTIME
105
106 clockid_t
107 timer_t
108
109 int clock_getres(clockid_t, timespec*);
110 int clock_gettime(clockid_t, timespec*);
111 int clock_settime(clockid_t, in timespec*);
112 int nanosleep(in timespec*, timespec*);
113 int timer_create(clockid_t, sigevent*, timer_t*);
114 int timer_delete(timer_t);
115 int timer_gettime(timer_t, itimerspec*);
116 int timer_getoverrun(timer_t);
117 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
118 */
119
120 version( linux )
121 {
122 enum CLOCK_PROCESS_CPUTIME_ID = 2; // (TMR|CPT)
123 enum CLOCK_THREAD_CPUTIME_ID = 3; // (TMR|TCT)
124
125 // NOTE: See above for why this is commented out.
126 //
127 //struct timespec
128 //{
129 // time_t tv_sec;
130 // c_long tv_nsec;
131 //}
132
133 struct itimerspec
134 {
135 timespec it_interval;
136 timespec it_value;
137 }
138
139 enum CLOCK_REALTIME = 0;
140 enum TIMER_ABSTIME = 0x01;
141
142 alias int clockid_t;
143 alias int timer_t;
144
145 int clock_getres(clockid_t, timespec*);
146 //int clock_gettime(clockid_t, timespec*);
147 //int clock_settime(clockid_t, in timespec*);
148 int nanosleep(in timespec*, timespec*);
149 int timer_create(clockid_t, sigevent*, timer_t*);
150 int timer_delete(timer_t);
151 int timer_gettime(timer_t, itimerspec*);
152 int timer_getoverrun(timer_t);
153 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
154 }
155 else version( OSX )
156 {
157 int nanosleep(in timespec*, timespec*);
158 }
159 else version( freebsd )
160 {
161 enum CLOCK_PROCESS_CPUTIME_ID = 2; // (TMR|CPT)
162 enum CLOCK_THREAD_CPUTIME_ID = 3; // (TMR|TCT)
163
164 // NOTE: See above for why this is commented out.
165 //
166 //struct timespec
167 //{
168 // time_t tv_sec;
169 // c_long tv_nsec;
170 //}
171
172 struct itimerspec
173 {
174 timespec it_interval;
175 timespec it_value;
176 }
177
178 enum CLOCK_REALTIME = 0;
179 enum TIMER_ABSTIME = 0x01;
180
181 //alias int clockid_t;
182 alias int timer_t;
183
184 int clock_getres(clockid_t, timespec*);
185 int clock_gettime(clockid_t, timespec*);
186 int clock_settime(clockid_t, in timespec*);
187 int nanosleep(in timespec*, timespec*);
188 int timer_create(clockid_t, sigevent*, timer_t*);
189 int timer_delete(timer_t);
190 int timer_gettime(timer_t, itimerspec*);
191 int timer_getoverrun(timer_t);
192 int timer_settime(timer_t, int, in itimerspec*, itimerspec*);
193 }
194
195
196 //
197 // Thread-Safe Functions (TSF)
198 //
199 /*
200 char* asctime_r(in tm*, char*);
201 char* ctime_r(in time_t*, char*);
202 tm* gmtime_r(in time_t*, tm*);
203 tm* localtime_r(in time_t*, tm*);
204 */
205
206 version( linux )
207 {
208 char* asctime_r(in tm*, char*);
209 char* ctime_r(in time_t*, char*);
210 tm* gmtime_r(in time_t*, tm*);
211 tm* localtime_r(in time_t*, tm*);
212 }
213 else version( OSX )
214 {
215 char* asctime_r(in tm*, char*);
216 char* ctime_r(in time_t*, char*);
217 tm* gmtime_r(in time_t*, tm*);
218 tm* localtime_r(in time_t*, tm*);
219 }
220 else version( freebsd )
221 {
222 char* asctime_r(in tm*, char*);
223 char* ctime_r(in time_t*, char*);
224 tm* gmtime_r(in time_t*, tm*);
225 tm* localtime_r(in time_t*, tm*);
226 }
227
228 //
229 // XOpen (XSI)
230 //
231 /*
232 getdate_err
233
234 int daylight;
235 int timezone;
236
237 tm* getdate(in char*);
238 char* strptime(in char*, in char*, tm*);
239 */
240
241 version( linux )
242 {
243 extern __gshared int daylight;
244 extern __gshared c_long timezone;
245
246 tm* getdate(in char*);
247 char* strptime(in char*, in char*, tm*);
248 }
249 else version( OSX )
250 {
251 extern __gshared c_long timezone;
252
253 tm* getdate(in char*);
254 char* strptime(in char*, in char*, tm*);
255 }
256 else version( FreeBSD )
257 {
258 extern __gshared c_long timezone;
259
260 //tm* getdate(in char*);
261 char* strptime(in char*, in char*, tm*);
262 }
263 else version( Solaris )
264 {
265 extern __gshared c_long timezone;
266
267 //tm* getdate(in char*);
268 char* strptime(in char*, in char*, tm*);
269 }
270