The OpenD Programming Language

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, Alex Rønne Petersen
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright Sean Kelly 2005 - 2009.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.sys.time;
16 
17 import core.sys.posix.config;
18 public import core.sys.posix.sys.types;  // for time_t, suseconds_t
19 public import core.sys.posix.sys.select; // for fd_set, FD_CLR() FD_ISSET() FD_SET() FD_ZERO() FD_SETSIZE, select()
20 
21 version (OSX)
22     version = Darwin;
23 else version (iOS)
24     version = Darwin;
25 else version (TVOS)
26     version = Darwin;
27 else version (WatchOS)
28     version = Darwin;
29 
30 version (linux) public import core.sys.linux.sys.time;
31 
32 version (Posix):
33 extern (C) nothrow @nogc:
34 
35 //
36 // XOpen (XSI)
37 //
38 /*
39 struct timeval
40 {
41     time_t      tv_sec;
42     suseconds_t tv_usec;
43 }
44 
45 struct itimerval
46 {
47     timeval it_interval;
48     timeval it_value;
49 }
50 
51 ITIMER_REAL
52 ITIMER_VIRTUAL
53 ITIMER_PROF
54 
55 int getitimer(int, itimerval*);
56 int gettimeofday(timeval*, void*);
57 int select(int, fd_set*, fd_set*, fd_set*, timeval*); (defined in core.sys.posix.sys.signal)
58 int setitimer(int, const scope itimerval*, itimerval*);
59 int utimes(const scope char*, ref const(timeval)[2]); // LEGACY
60 */
61 
62 version (CRuntime_Glibc)
63 {
64     struct timeval
65     {
66         time_t      tv_sec;
67         suseconds_t tv_usec;
68     }
69 
70     struct itimerval
71     {
72         timeval it_interval;
73         timeval it_value;
74     }
75 
76     enum ITIMER_REAL    = 0;
77     enum ITIMER_VIRTUAL = 1;
78     enum ITIMER_PROF    = 2;
79 
80     int getitimer(int, itimerval*);
81     int gettimeofday(timeval*, void*);
82     int setitimer(int, const scope itimerval*, itimerval*);
83     int utimes(const scope char*, ref const(timeval)[2]); // LEGACY
84 }
85 else version (CRuntime_Musl)
86 {
87     struct timeval
88     {
89         time_t      tv_sec;
90         suseconds_t tv_usec;
91     }
92     pragma(mangle, muslRedirTime64Mangle!("gettimeofday", "__gettimeofday_time64"))
93     int gettimeofday(timeval*, void*);
94     pragma(mangle, muslRedirTime64Mangle!("utimes", "__utimes_time64"))
95     int utimes(const scope char*, ref const(timeval)[2]);
96 }
97 else version (Darwin)
98 {
99     struct timeval
100     {
101         time_t      tv_sec;
102         suseconds_t tv_usec;
103     }
104 
105     struct itimerval
106     {
107         timeval it_interval;
108         timeval it_value;
109     }
110 
111     // non-standard
112     struct timezone_t
113     {
114         int tz_minuteswest;
115         int tz_dsttime;
116     }
117 
118     int getitimer(int, itimerval*);
119     int gettimeofday(timeval*, timezone_t*); // timezone_t* is normally void*
120     int setitimer(int, const scope itimerval*, itimerval*);
121     int utimes(const scope char*, ref const(timeval)[2]);
122 }
123 else version (FreeBSD)
124 {
125     struct timeval
126     {
127         time_t      tv_sec;
128         suseconds_t tv_usec;
129     }
130 
131     struct itimerval
132     {
133         timeval it_interval;
134         timeval it_value;
135     }
136 
137     // non-standard
138     struct timezone_t
139     {
140         int tz_minuteswest;
141         int tz_dsttime;
142     }
143 
144     int getitimer(int, itimerval*);
145     int gettimeofday(timeval*, timezone_t*); // timezone_t* is normally void*
146     int setitimer(int, const scope itimerval*, itimerval*);
147     int utimes(const scope char*, ref const(timeval)[2]);
148 }
149 else version (NetBSD)
150 {
151     struct timeval
152     {
153         time_t      tv_sec;
154         suseconds_t tv_usec;
155     }
156 
157     struct itimerval
158     {
159         timeval it_interval;
160         timeval it_value;
161     }
162 
163     int getitimer(int, itimerval*);
164     int gettimeofday(timeval*, void*); // timezone_t* is normally void*
165     int setitimer(int, const scope itimerval*, itimerval*);
166     int utimes(const scope char*, ref const(timeval)[2]);
167 }
168 else version (OpenBSD)
169 {
170     struct timeval
171     {
172         time_t      tv_sec;
173         suseconds_t tv_usec;
174     }
175 
176     struct itimerval
177     {
178         timeval it_interval;
179         timeval it_value;
180     }
181 
182     // non-standard
183     struct timezone_t
184     {
185         int tz_minuteswest;
186         int tz_dsttime;
187     }
188 
189     int getitimer(int, itimerval*);
190     int gettimeofday(timeval*, timezone_t*);
191     int setitimer(int, const scope itimerval*, itimerval*);
192     int utimes(const scope char*, ref const(timeval)[2]);
193 }
194 else version (DragonFlyBSD)
195 {
196     struct timeval
197     {
198         time_t      tv_sec;
199         suseconds_t tv_usec;
200     }
201 
202     struct itimerval
203     {
204         timeval it_interval;
205         timeval it_value;
206     }
207 
208     // non-standard
209     struct timezone_t
210     {
211         int tz_minuteswest;
212         int tz_dsttime;
213     }
214 
215     int getitimer(int, itimerval*);
216     int gettimeofday(timeval*, timezone_t*); // timezone_t* is normally void*
217     int setitimer(int, const scope itimerval*, itimerval*);
218     int utimes(const scope char*, ref const(timeval)[2]);
219 }
220 else version (Solaris)
221 {
222     struct timeval
223     {
224         time_t tv_sec;
225         suseconds_t tv_usec;
226     }
227 
228     struct itimerval
229     {
230         timeval it_interval;
231         timeval it_value;
232     }
233 
234     int getitimer(int, itimerval*);
235     int gettimeofday(timeval*, void*);
236     int setitimer(int, const scope itimerval*, itimerval*);
237     int utimes(const scope char*, ref const(timeval)[2]);
238 }
239 else version (CRuntime_Bionic)
240 {
241     struct timeval
242     {
243         time_t      tv_sec;
244         suseconds_t tv_usec;
245     }
246 
247     struct itimerval
248     {
249         timeval it_interval;
250         timeval it_value;
251     }
252 
253     struct timezone_t
254     {
255         int tz_minuteswest;
256         int tz_dsttime;
257     }
258 
259     enum ITIMER_REAL    = 0;
260     enum ITIMER_VIRTUAL = 1;
261     enum ITIMER_PROF    = 2;
262 
263     int getitimer(int, itimerval*);
264     int gettimeofday(timeval*, timezone_t*);
265     int setitimer(int, const scope itimerval*, itimerval*);
266     int utimes(const scope char*, ref const(timeval)[2]);
267 }
268 else version (CRuntime_UClibc)
269 {
270     struct timeval
271     {
272         time_t      tv_sec;
273         suseconds_t tv_usec;
274     }
275 
276     struct itimerval
277     {
278         timeval it_interval;
279         timeval it_value;
280     }
281 
282     enum ITIMER_REAL    = 0;
283     enum ITIMER_VIRTUAL = 1;
284     enum ITIMER_PROF    = 2;
285 
286     int getitimer(int, itimerval*);
287     int gettimeofday(timeval*, void*);
288     int setitimer(int, const scope itimerval*, itimerval*);
289     int utimes(const scope char*, ref const(timeval)[2]);
290 }
291 else
292 {
293     static assert(false, "Unsupported platform");
294 }