1 | /** @file
|
---|
2 | * IPRT - Time.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_time_h
|
---|
37 | #define IPRT_INCLUDED_time_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/cdefs.h>
|
---|
43 | #include <iprt/types.h>
|
---|
44 | #include <iprt/assertcompile.h>
|
---|
45 |
|
---|
46 | RT_C_DECLS_BEGIN
|
---|
47 |
|
---|
48 | /** @defgroup grp_rt_time RTTime - Time
|
---|
49 | * @ingroup grp_rt
|
---|
50 | * @{
|
---|
51 | */
|
---|
52 |
|
---|
53 | /** Time Specification.
|
---|
54 | *
|
---|
55 | * Use the inline RTTimeSpecGet/Set to operate on structure this so we
|
---|
56 | * can easily change the representation if required later.
|
---|
57 | *
|
---|
58 | * The current representation is in nanoseconds relative to the unix epoch
|
---|
59 | * (1970-01-01 00:00:00 UTC). This gives us an approximate span from
|
---|
60 | * 1678 to 2262 without sacrificing the resolution offered by the various
|
---|
61 | * host OSes (BSD & LINUX 1ns, NT 100ns).
|
---|
62 | */
|
---|
63 | typedef struct RTTIMESPEC
|
---|
64 | {
|
---|
65 | /** Nanoseconds since epoch.
|
---|
66 | * The name is intentially too long to be comfortable to use because you should be
|
---|
67 | * using inline helpers! */
|
---|
68 | int64_t i64NanosecondsRelativeToUnixEpoch;
|
---|
69 | } RTTIMESPEC;
|
---|
70 |
|
---|
71 |
|
---|
72 | /** @name RTTIMESPEC methods
|
---|
73 | * @{ */
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Gets the time as nanoseconds relative to the unix epoch.
|
---|
77 | *
|
---|
78 | * @returns Nanoseconds relative to unix epoch.
|
---|
79 | * @param pTime The time spec to interpret.
|
---|
80 | */
|
---|
81 | DECLINLINE(int64_t) RTTimeSpecGetNano(PCRTTIMESPEC pTime)
|
---|
82 | {
|
---|
83 | return pTime->i64NanosecondsRelativeToUnixEpoch;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Sets the time give by nanoseconds relative to the unix epoch.
|
---|
89 | *
|
---|
90 | * @returns pTime.
|
---|
91 | * @param pTime The time spec to modify.
|
---|
92 | * @param i64Nano The new time in nanoseconds.
|
---|
93 | */
|
---|
94 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNano(PRTTIMESPEC pTime, int64_t i64Nano)
|
---|
95 | {
|
---|
96 | pTime->i64NanosecondsRelativeToUnixEpoch = i64Nano;
|
---|
97 | return pTime;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Gets the time as microseconds relative to the unix epoch.
|
---|
103 | *
|
---|
104 | * @returns microseconds relative to unix epoch.
|
---|
105 | * @param pTime The time spec to interpret.
|
---|
106 | */
|
---|
107 | DECLINLINE(int64_t) RTTimeSpecGetMicro(PCRTTIMESPEC pTime)
|
---|
108 | {
|
---|
109 | return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1US;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Sets the time given by microseconds relative to the unix epoch.
|
---|
115 | *
|
---|
116 | * @returns pTime.
|
---|
117 | * @param pTime The time spec to modify.
|
---|
118 | * @param i64Micro The new time in microsecond.
|
---|
119 | */
|
---|
120 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetMicro(PRTTIMESPEC pTime, int64_t i64Micro)
|
---|
121 | {
|
---|
122 | pTime->i64NanosecondsRelativeToUnixEpoch = i64Micro * RT_NS_1US;
|
---|
123 | return pTime;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Gets the time as milliseconds relative to the unix epoch.
|
---|
129 | *
|
---|
130 | * @returns milliseconds relative to unix epoch.
|
---|
131 | * @param pTime The time spec to interpret.
|
---|
132 | */
|
---|
133 | DECLINLINE(int64_t) RTTimeSpecGetMilli(PCRTTIMESPEC pTime)
|
---|
134 | {
|
---|
135 | return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1MS;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Sets the time given by milliseconds relative to the unix epoch.
|
---|
141 | *
|
---|
142 | * @returns pTime.
|
---|
143 | * @param pTime The time spec to modify.
|
---|
144 | * @param i64Milli The new time in milliseconds.
|
---|
145 | */
|
---|
146 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetMilli(PRTTIMESPEC pTime, int64_t i64Milli)
|
---|
147 | {
|
---|
148 | pTime->i64NanosecondsRelativeToUnixEpoch = i64Milli * RT_NS_1MS;
|
---|
149 | return pTime;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Gets the time as seconds relative to the unix epoch.
|
---|
155 | *
|
---|
156 | * @returns seconds relative to unix epoch.
|
---|
157 | * @param pTime The time spec to interpret.
|
---|
158 | */
|
---|
159 | DECLINLINE(int64_t) RTTimeSpecGetSeconds(PCRTTIMESPEC pTime)
|
---|
160 | {
|
---|
161 | return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1SEC;
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Sets the time given by seconds relative to the unix epoch.
|
---|
167 | *
|
---|
168 | * @returns pTime.
|
---|
169 | * @param pTime The time spec to modify.
|
---|
170 | * @param i64Seconds The new time in seconds.
|
---|
171 | */
|
---|
172 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
|
---|
173 | {
|
---|
174 | pTime->i64NanosecondsRelativeToUnixEpoch = i64Seconds * RT_NS_1SEC;
|
---|
175 | return pTime;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Makes the time spec absolute like abs() does (i.e. a positive value).
|
---|
181 | *
|
---|
182 | * @returns pTime.
|
---|
183 | * @param pTime The time spec to modify.
|
---|
184 | */
|
---|
185 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAbsolute(PRTTIMESPEC pTime)
|
---|
186 | {
|
---|
187 | if (pTime->i64NanosecondsRelativeToUnixEpoch < 0)
|
---|
188 | pTime->i64NanosecondsRelativeToUnixEpoch = -pTime->i64NanosecondsRelativeToUnixEpoch;
|
---|
189 | return pTime;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Negates the time.
|
---|
195 | *
|
---|
196 | * @returns pTime.
|
---|
197 | * @param pTime The time spec to modify.
|
---|
198 | */
|
---|
199 | DECLINLINE(PRTTIMESPEC) RTTimeSpecNegate(PRTTIMESPEC pTime)
|
---|
200 | {
|
---|
201 | pTime->i64NanosecondsRelativeToUnixEpoch = -pTime->i64NanosecondsRelativeToUnixEpoch;
|
---|
202 | return pTime;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Adds a time period to the time.
|
---|
208 | *
|
---|
209 | * @returns pTime.
|
---|
210 | * @param pTime The time spec to modify.
|
---|
211 | * @param pTimeAdd The time spec to add to pTime.
|
---|
212 | */
|
---|
213 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAdd(PRTTIMESPEC pTime, PCRTTIMESPEC pTimeAdd)
|
---|
214 | {
|
---|
215 | pTime->i64NanosecondsRelativeToUnixEpoch += pTimeAdd->i64NanosecondsRelativeToUnixEpoch;
|
---|
216 | return pTime;
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Adds a time period give as nanoseconds from the time.
|
---|
222 | *
|
---|
223 | * @returns pTime.
|
---|
224 | * @param pTime The time spec to modify.
|
---|
225 | * @param i64Nano The time period in nanoseconds.
|
---|
226 | */
|
---|
227 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAddNano(PRTTIMESPEC pTime, int64_t i64Nano)
|
---|
228 | {
|
---|
229 | pTime->i64NanosecondsRelativeToUnixEpoch += i64Nano;
|
---|
230 | return pTime;
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Adds a time period give as microseconds from the time.
|
---|
236 | *
|
---|
237 | * @returns pTime.
|
---|
238 | * @param pTime The time spec to modify.
|
---|
239 | * @param i64Micro The time period in microseconds.
|
---|
240 | */
|
---|
241 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAddMicro(PRTTIMESPEC pTime, int64_t i64Micro)
|
---|
242 | {
|
---|
243 | pTime->i64NanosecondsRelativeToUnixEpoch += i64Micro * RT_NS_1US;
|
---|
244 | return pTime;
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Adds a time period give as milliseconds from the time.
|
---|
250 | *
|
---|
251 | * @returns pTime.
|
---|
252 | * @param pTime The time spec to modify.
|
---|
253 | * @param i64Milli The time period in milliseconds.
|
---|
254 | */
|
---|
255 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAddMilli(PRTTIMESPEC pTime, int64_t i64Milli)
|
---|
256 | {
|
---|
257 | pTime->i64NanosecondsRelativeToUnixEpoch += i64Milli * RT_NS_1MS;
|
---|
258 | return pTime;
|
---|
259 | }
|
---|
260 |
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * Adds a time period give as seconds from the time.
|
---|
264 | *
|
---|
265 | * @returns pTime.
|
---|
266 | * @param pTime The time spec to modify.
|
---|
267 | * @param i64Seconds The time period in seconds.
|
---|
268 | */
|
---|
269 | DECLINLINE(PRTTIMESPEC) RTTimeSpecAddSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
|
---|
270 | {
|
---|
271 | pTime->i64NanosecondsRelativeToUnixEpoch += i64Seconds * RT_NS_1SEC;
|
---|
272 | return pTime;
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * Subtracts a time period from the time.
|
---|
278 | *
|
---|
279 | * @returns pTime.
|
---|
280 | * @param pTime The time spec to modify.
|
---|
281 | * @param pTimeSub The time spec to subtract from pTime.
|
---|
282 | */
|
---|
283 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSub(PRTTIMESPEC pTime, PCRTTIMESPEC pTimeSub)
|
---|
284 | {
|
---|
285 | pTime->i64NanosecondsRelativeToUnixEpoch -= pTimeSub->i64NanosecondsRelativeToUnixEpoch;
|
---|
286 | return pTime;
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Subtracts a time period give as nanoseconds from the time.
|
---|
292 | *
|
---|
293 | * @returns pTime.
|
---|
294 | * @param pTime The time spec to modify.
|
---|
295 | * @param i64Nano The time period in nanoseconds.
|
---|
296 | */
|
---|
297 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSubNano(PRTTIMESPEC pTime, int64_t i64Nano)
|
---|
298 | {
|
---|
299 | pTime->i64NanosecondsRelativeToUnixEpoch -= i64Nano;
|
---|
300 | return pTime;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Subtracts a time period give as microseconds from the time.
|
---|
306 | *
|
---|
307 | * @returns pTime.
|
---|
308 | * @param pTime The time spec to modify.
|
---|
309 | * @param i64Micro The time period in microseconds.
|
---|
310 | */
|
---|
311 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSubMicro(PRTTIMESPEC pTime, int64_t i64Micro)
|
---|
312 | {
|
---|
313 | pTime->i64NanosecondsRelativeToUnixEpoch -= i64Micro * RT_NS_1US;
|
---|
314 | return pTime;
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * Subtracts a time period give as milliseconds from the time.
|
---|
320 | *
|
---|
321 | * @returns pTime.
|
---|
322 | * @param pTime The time spec to modify.
|
---|
323 | * @param i64Milli The time period in milliseconds.
|
---|
324 | */
|
---|
325 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSubMilli(PRTTIMESPEC pTime, int64_t i64Milli)
|
---|
326 | {
|
---|
327 | pTime->i64NanosecondsRelativeToUnixEpoch -= i64Milli * RT_NS_1MS;
|
---|
328 | return pTime;
|
---|
329 | }
|
---|
330 |
|
---|
331 |
|
---|
332 | /**
|
---|
333 | * Subtracts a time period give as seconds from the time.
|
---|
334 | *
|
---|
335 | * @returns pTime.
|
---|
336 | * @param pTime The time spec to modify.
|
---|
337 | * @param i64Seconds The time period in seconds.
|
---|
338 | */
|
---|
339 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSubSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
|
---|
340 | {
|
---|
341 | pTime->i64NanosecondsRelativeToUnixEpoch -= i64Seconds * RT_NS_1SEC;
|
---|
342 | return pTime;
|
---|
343 | }
|
---|
344 |
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Gives the time in seconds and nanoseconds.
|
---|
348 | *
|
---|
349 | * @returns pTime.
|
---|
350 | * @param pTime The time spec to interpret.
|
---|
351 | * @param *pi32Seconds Where to store the time period in seconds.
|
---|
352 | * @param *pi32Nano Where to store the time period in nanoseconds.
|
---|
353 | */
|
---|
354 | DECLINLINE(void) RTTimeSpecGetSecondsAndNano(PRTTIMESPEC pTime, int32_t *pi32Seconds, int32_t *pi32Nano)
|
---|
355 | {
|
---|
356 | int64_t i64 = RTTimeSpecGetNano(pTime);
|
---|
357 | int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC);
|
---|
358 | i64 /= RT_NS_1SEC;
|
---|
359 | if (i32Nano < 0)
|
---|
360 | {
|
---|
361 | i32Nano += RT_NS_1SEC;
|
---|
362 | i64--;
|
---|
363 | }
|
---|
364 | *pi32Seconds = (int32_t)i64;
|
---|
365 | *pi32Nano = i32Nano;
|
---|
366 | }
|
---|
367 |
|
---|
368 | /** @def RTTIME_LINUX_KERNEL_PREREQ
|
---|
369 | * Prerequisite minimum linux kernel version.
|
---|
370 | * @note Cannot really be moved to iprt/cdefs.h, see the-linux-kernel.h */
|
---|
371 | /** @def RTTIME_LINUX_KERNEL_PREREQ_LT
|
---|
372 | * Prerequisite maxium linux kernel version (LT=less-than).
|
---|
373 | * @note Cannot really be moved to iprt/cdefs.h, see the-linux-kernel.h */
|
---|
374 | #if defined(RT_OS_LINUX) && defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
|
---|
375 | # define RTTIME_LINUX_KERNEL_PREREQ(a, b, c) (LINUX_VERSION_CODE >= KERNEL_VERSION(a, b, c))
|
---|
376 | # define RTTIME_LINUX_KERNEL_PREREQ_LT(a, b, c) (!RTTIME_LINUX_KERNEL_PREREQ(a, b, c))
|
---|
377 | #else
|
---|
378 | # define RTTIME_LINUX_KERNEL_PREREQ(a, b, c) 0
|
---|
379 | # define RTTIME_LINUX_KERNEL_PREREQ_LT(a, b, c) 0
|
---|
380 | #endif
|
---|
381 |
|
---|
382 | /* PORTME: Add struct timeval guard macro here. */
|
---|
383 | #if defined(RTTIME_INCL_TIMEVAL) \
|
---|
384 | || defined(_SYS__TIMEVAL_H_) \
|
---|
385 | || defined(_SYS_TIME_H) \
|
---|
386 | || defined(_TIMEVAL) \
|
---|
387 | || defined(_STRUCT_TIMEVAL) \
|
---|
388 | || ( defined(RT_OS_LINUX) \
|
---|
389 | && defined(_LINUX_TIME_H) \
|
---|
390 | && ( !defined(__KERNEL__) \
|
---|
391 | || RTTIME_LINUX_KERNEL_PREREQ_LT(5,6,0) /* @bugref{9757} */ ) ) \
|
---|
392 | || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))
|
---|
393 |
|
---|
394 | /**
|
---|
395 | * Gets the time as POSIX timeval.
|
---|
396 | *
|
---|
397 | * @returns pTime.
|
---|
398 | * @param pTime The time spec to interpret.
|
---|
399 | * @param pTimeval Where to store the time as POSIX timeval.
|
---|
400 | */
|
---|
401 | DECLINLINE(struct timeval *) RTTimeSpecGetTimeval(PCRTTIMESPEC pTime, struct timeval *pTimeval)
|
---|
402 | {
|
---|
403 | int64_t i64 = RTTimeSpecGetMicro(pTime);
|
---|
404 | int32_t i32Micro = (int32_t)(i64 % RT_US_1SEC);
|
---|
405 | i64 /= RT_US_1SEC;
|
---|
406 | if (i32Micro < 0)
|
---|
407 | {
|
---|
408 | i32Micro += RT_US_1SEC;
|
---|
409 | i64--;
|
---|
410 | }
|
---|
411 | pTimeval->tv_sec = (time_t)i64;
|
---|
412 | pTimeval->tv_usec = i32Micro;
|
---|
413 | return pTimeval;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Sets the time as POSIX timeval.
|
---|
418 | *
|
---|
419 | * @returns pTime.
|
---|
420 | * @param pTime The time spec to modify.
|
---|
421 | * @param pTimeval Pointer to the POSIX timeval struct with the new time.
|
---|
422 | */
|
---|
423 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimeval(PRTTIMESPEC pTime, const struct timeval *pTimeval)
|
---|
424 | {
|
---|
425 | return RTTimeSpecAddMicro(RTTimeSpecSetSeconds(pTime, pTimeval->tv_sec), pTimeval->tv_usec);
|
---|
426 | }
|
---|
427 |
|
---|
428 | #endif /* various ways of detecting struct timeval */
|
---|
429 |
|
---|
430 |
|
---|
431 | /* PORTME: Add struct timespec guard macro here. */
|
---|
432 | #if defined(RTTIME_INCL_TIMESPEC) \
|
---|
433 | || defined(_SYS__TIMESPEC_H_) \
|
---|
434 | || defined(TIMEVAL_TO_TIMESPEC) \
|
---|
435 | || defined(_TIMESPEC) \
|
---|
436 | || ( defined(_STRUCT_TIMESPEC) \
|
---|
437 | && ( !defined(RT_OS_LINUX) \
|
---|
438 | || !defined(__KERNEL__) \
|
---|
439 | || RTTIME_LINUX_KERNEL_PREREQ_LT(5,6,0) /* @bugref{9757} */ ) ) \
|
---|
440 | || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))
|
---|
441 |
|
---|
442 | /**
|
---|
443 | * Gets the time as POSIX timespec.
|
---|
444 | *
|
---|
445 | * @returns pTimespec.
|
---|
446 | * @param pTime The time spec to interpret.
|
---|
447 | * @param pTimespec Where to store the time as POSIX timespec.
|
---|
448 | */
|
---|
449 | DECLINLINE(struct timespec *) RTTimeSpecGetTimespec(PCRTTIMESPEC pTime, struct timespec *pTimespec)
|
---|
450 | {
|
---|
451 | int64_t i64 = RTTimeSpecGetNano(pTime);
|
---|
452 | int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC);
|
---|
453 | i64 /= RT_NS_1SEC;
|
---|
454 | if (i32Nano < 0)
|
---|
455 | {
|
---|
456 | i32Nano += RT_NS_1SEC;
|
---|
457 | i64--;
|
---|
458 | }
|
---|
459 | pTimespec->tv_sec = (time_t)i64;
|
---|
460 | pTimespec->tv_nsec = i32Nano;
|
---|
461 | return pTimespec;
|
---|
462 | }
|
---|
463 |
|
---|
464 | /**
|
---|
465 | * Sets the time as POSIX timespec.
|
---|
466 | *
|
---|
467 | * @returns pTime.
|
---|
468 | * @param pTime The time spec to modify.
|
---|
469 | * @param pTimespec Pointer to the POSIX timespec struct with the new time.
|
---|
470 | */
|
---|
471 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec(PRTTIMESPEC pTime, const struct timespec *pTimespec)
|
---|
472 | {
|
---|
473 | return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimespec->tv_sec), pTimespec->tv_nsec);
|
---|
474 | }
|
---|
475 |
|
---|
476 | #endif /* various ways of detecting struct timespec */
|
---|
477 |
|
---|
478 |
|
---|
479 | #if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H) /* since linux 3.17 */
|
---|
480 |
|
---|
481 | /**
|
---|
482 | * Gets the time a linux 64-bit timespec structure.
|
---|
483 | * @returns pTimespec.
|
---|
484 | * @param pTime The time spec to modify.
|
---|
485 | * @param pTimespec Where to store the time as linux 64-bit timespec.
|
---|
486 | */
|
---|
487 | DECLINLINE(struct timespec64 *) RTTimeSpecGetTimespec64(PCRTTIMESPEC pTime, struct timespec64 *pTimespec)
|
---|
488 | {
|
---|
489 | int64_t i64 = RTTimeSpecGetNano(pTime);
|
---|
490 | int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC);
|
---|
491 | i64 /= RT_NS_1SEC;
|
---|
492 | if (i32Nano < 0)
|
---|
493 | {
|
---|
494 | i32Nano += RT_NS_1SEC;
|
---|
495 | i64--;
|
---|
496 | }
|
---|
497 | pTimespec->tv_sec = i64;
|
---|
498 | pTimespec->tv_nsec = i32Nano;
|
---|
499 | return pTimespec;
|
---|
500 | }
|
---|
501 |
|
---|
502 | /**
|
---|
503 | * Sets the time from a linux 64-bit timespec structure.
|
---|
504 | * @returns pTime.
|
---|
505 | * @param pTime The time spec to modify.
|
---|
506 | * @param pTimespec Pointer to the linux 64-bit timespec struct with the new time.
|
---|
507 | */
|
---|
508 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec64(PRTTIMESPEC pTime, const struct timespec64 *pTimespec)
|
---|
509 | {
|
---|
510 | return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimespec->tv_sec), pTimespec->tv_nsec);
|
---|
511 | }
|
---|
512 |
|
---|
513 | #endif /* RT_OS_LINUX && _LINUX_TIME64_H */
|
---|
514 |
|
---|
515 |
|
---|
516 | /** The offset of the unix epoch and the base for NT time (in 100ns units).
|
---|
517 | * Nt time starts at 1601-01-01 00:00:00. */
|
---|
518 | #define RTTIME_NT_TIME_OFFSET_UNIX (116444736000000000LL)
|
---|
519 |
|
---|
520 |
|
---|
521 | /**
|
---|
522 | * Gets the time as NT time.
|
---|
523 | *
|
---|
524 | * @returns NT time.
|
---|
525 | * @param pTime The time spec to interpret.
|
---|
526 | */
|
---|
527 | DECLINLINE(int64_t) RTTimeSpecGetNtTime(PCRTTIMESPEC pTime)
|
---|
528 | {
|
---|
529 | return pTime->i64NanosecondsRelativeToUnixEpoch / 100
|
---|
530 | + RTTIME_NT_TIME_OFFSET_UNIX;
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * Sets the time given by Nt time.
|
---|
536 | *
|
---|
537 | * @returns pTime.
|
---|
538 | * @param pTime The time spec to modify.
|
---|
539 | * @param u64NtTime The new time in Nt time.
|
---|
540 | */
|
---|
541 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNtTime(PRTTIMESPEC pTime, uint64_t u64NtTime)
|
---|
542 | {
|
---|
543 | pTime->i64NanosecondsRelativeToUnixEpoch =
|
---|
544 | ((int64_t)u64NtTime - RTTIME_NT_TIME_OFFSET_UNIX) * 100;
|
---|
545 | return pTime;
|
---|
546 | }
|
---|
547 |
|
---|
548 |
|
---|
549 | #ifdef _FILETIME_
|
---|
550 |
|
---|
551 | /**
|
---|
552 | * Gets the time as NT file time.
|
---|
553 | *
|
---|
554 | * @returns pFileTime.
|
---|
555 | * @param pTime The time spec to interpret.
|
---|
556 | * @param pFileTime Pointer to NT filetime structure.
|
---|
557 | */
|
---|
558 | DECLINLINE(PFILETIME) RTTimeSpecGetNtFileTime(PCRTTIMESPEC pTime, PFILETIME pFileTime)
|
---|
559 | {
|
---|
560 | *((uint64_t *)pFileTime) = RTTimeSpecGetNtTime(pTime);
|
---|
561 | return pFileTime;
|
---|
562 | }
|
---|
563 |
|
---|
564 | /**
|
---|
565 | * Sets the time as NT file time.
|
---|
566 | *
|
---|
567 | * @returns pTime.
|
---|
568 | * @param pTime The time spec to modify.
|
---|
569 | * @param pFileTime Where to store the time as Nt file time.
|
---|
570 | */
|
---|
571 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNtFileTime(PRTTIMESPEC pTime, const FILETIME *pFileTime)
|
---|
572 | {
|
---|
573 | return RTTimeSpecSetNtTime(pTime, *(const uint64_t *)pFileTime);
|
---|
574 | }
|
---|
575 |
|
---|
576 | #endif /* _FILETIME_ */
|
---|
577 |
|
---|
578 |
|
---|
579 | /** The offset to the start of DOS time.
|
---|
580 | * DOS time starts 1980-01-01 00:00:00. */
|
---|
581 | #define RTTIME_OFFSET_DOS_TIME (315532800000000000LL)
|
---|
582 |
|
---|
583 |
|
---|
584 | /**
|
---|
585 | * Gets the time as seconds relative to the start of dos time.
|
---|
586 | *
|
---|
587 | * @returns seconds relative to the start of dos time.
|
---|
588 | * @param pTime The time spec to interpret.
|
---|
589 | */
|
---|
590 | DECLINLINE(int64_t) RTTimeSpecGetDosSeconds(PCRTTIMESPEC pTime)
|
---|
591 | {
|
---|
592 | return (pTime->i64NanosecondsRelativeToUnixEpoch - RTTIME_OFFSET_DOS_TIME)
|
---|
593 | / RT_NS_1SEC;
|
---|
594 | }
|
---|
595 |
|
---|
596 |
|
---|
597 | /**
|
---|
598 | * Sets the time given by seconds relative to the start of dos time.
|
---|
599 | *
|
---|
600 | * @returns pTime.
|
---|
601 | * @param pTime The time spec to modify.
|
---|
602 | * @param i64Seconds The new time in seconds relative to the start of dos time.
|
---|
603 | */
|
---|
604 | DECLINLINE(PRTTIMESPEC) RTTimeSpecSetDosSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
|
---|
605 | {
|
---|
606 | pTime->i64NanosecondsRelativeToUnixEpoch = i64Seconds * RT_NS_1SEC
|
---|
607 | + RTTIME_OFFSET_DOS_TIME;
|
---|
608 | return pTime;
|
---|
609 | }
|
---|
610 |
|
---|
611 |
|
---|
612 | /**
|
---|
613 | * Compare two time specs.
|
---|
614 | *
|
---|
615 | * @returns true they are equal.
|
---|
616 | * @returns false they are not equal.
|
---|
617 | * @param pTime1 The 1st time spec.
|
---|
618 | * @param pTime2 The 2nd time spec.
|
---|
619 | */
|
---|
620 | DECLINLINE(bool) RTTimeSpecIsEqual(PCRTTIMESPEC pTime1, PCRTTIMESPEC pTime2)
|
---|
621 | {
|
---|
622 | return pTime1->i64NanosecondsRelativeToUnixEpoch == pTime2->i64NanosecondsRelativeToUnixEpoch;
|
---|
623 | }
|
---|
624 |
|
---|
625 |
|
---|
626 | /**
|
---|
627 | * Compare two time specs.
|
---|
628 | *
|
---|
629 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
630 | * @returns false they are not equal.
|
---|
631 | * @param pLeft The 1st time spec.
|
---|
632 | * @param pRight The 2nd time spec.
|
---|
633 | */
|
---|
634 | DECLINLINE(int) RTTimeSpecCompare(PCRTTIMESPEC pLeft, PCRTTIMESPEC pRight)
|
---|
635 | {
|
---|
636 | if (pLeft->i64NanosecondsRelativeToUnixEpoch == pRight->i64NanosecondsRelativeToUnixEpoch)
|
---|
637 | return 0;
|
---|
638 | return pLeft->i64NanosecondsRelativeToUnixEpoch < pRight->i64NanosecondsRelativeToUnixEpoch ? -1 : 1;
|
---|
639 | }
|
---|
640 |
|
---|
641 |
|
---|
642 | /**
|
---|
643 | * Converts a time spec to a ISO date string.
|
---|
644 | *
|
---|
645 | * @returns psz on success.
|
---|
646 | * @returns NULL on buffer underflow.
|
---|
647 | * @param pTime The time spec.
|
---|
648 | * @param psz Where to store the string.
|
---|
649 | * @param cb The size of the buffer.
|
---|
650 | */
|
---|
651 | RTDECL(char *) RTTimeSpecToString(PCRTTIMESPEC pTime, char *psz, size_t cb);
|
---|
652 |
|
---|
653 | /**
|
---|
654 | * Attempts to convert an ISO date string to a time structure.
|
---|
655 | *
|
---|
656 | * We're a little forgiving with zero padding, unspecified parts, and leading
|
---|
657 | * and trailing spaces.
|
---|
658 | *
|
---|
659 | * @retval pTime on success,
|
---|
660 | * @retval NULL on failure.
|
---|
661 | * @param pTime The time spec.
|
---|
662 | * @param pszString The ISO date string to convert.
|
---|
663 | */
|
---|
664 | RTDECL(PRTTIMESPEC) RTTimeSpecFromString(PRTTIMESPEC pTime, const char *pszString);
|
---|
665 |
|
---|
666 | /** @} */
|
---|
667 |
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * Exploded time.
|
---|
671 | */
|
---|
672 | typedef struct RTTIME
|
---|
673 | {
|
---|
674 | /** The year number. */
|
---|
675 | int32_t i32Year;
|
---|
676 | /** The month of the year (1-12). January is 1. */
|
---|
677 | uint8_t u8Month;
|
---|
678 | /** The day of the week (0-6). Monday is 0. */
|
---|
679 | uint8_t u8WeekDay;
|
---|
680 | /** The day of the year (1-366). January the 1st is 1. */
|
---|
681 | uint16_t u16YearDay;
|
---|
682 | /** The day of the month (1-31). */
|
---|
683 | uint8_t u8MonthDay;
|
---|
684 | /** Hour of the day (0-23). */
|
---|
685 | uint8_t u8Hour;
|
---|
686 | /** The minute of the hour (0-59). */
|
---|
687 | uint8_t u8Minute;
|
---|
688 | /** The second of the minute (0-60).
|
---|
689 | * (u32Nanosecond / 1000000) */
|
---|
690 | uint8_t u8Second;
|
---|
691 | /** The nanoseconds of the second (0-999999999). */
|
---|
692 | uint32_t u32Nanosecond;
|
---|
693 | /** Flags, of the RTTIME_FLAGS_* \#defines. */
|
---|
694 | uint32_t fFlags;
|
---|
695 | /** UTC time offset in minutes (-840-840). Positive for timezones east of
|
---|
696 | * UTC, negative for zones to the west. Same as what RTTimeLocalDeltaNano
|
---|
697 | * & RTTimeLocalDeltaNanoFor returns, just different unit. */
|
---|
698 | int32_t offUTC;
|
---|
699 | } RTTIME;
|
---|
700 | AssertCompileSize(RTTIME, 24);
|
---|
701 | /** Pointer to a exploded time structure. */
|
---|
702 | typedef RTTIME *PRTTIME;
|
---|
703 | /** Pointer to a const exploded time structure. */
|
---|
704 | typedef const RTTIME *PCRTTIME;
|
---|
705 |
|
---|
706 | /** @name RTTIME::fFlags values.
|
---|
707 | * @{ */
|
---|
708 | /** Set if the time is UTC. If clear the time local time. */
|
---|
709 | #define RTTIME_FLAGS_TYPE_MASK 3
|
---|
710 | /** the time is UTC time. */
|
---|
711 | #define RTTIME_FLAGS_TYPE_UTC 2
|
---|
712 | /** The time is local time. */
|
---|
713 | #define RTTIME_FLAGS_TYPE_LOCAL 3
|
---|
714 |
|
---|
715 | /** Set if the time is local and daylight saving time is in effect.
|
---|
716 | * Not bit is not valid if RTTIME_FLAGS_NO_DST_DATA is set. */
|
---|
717 | #define RTTIME_FLAGS_DST RT_BIT(4)
|
---|
718 | /** Set if the time is local and there is no data available on daylight saving time. */
|
---|
719 | #define RTTIME_FLAGS_NO_DST_DATA RT_BIT(5)
|
---|
720 | /** Set if the year is a leap year.
|
---|
721 | * This is mutual exclusiv with RTTIME_FLAGS_COMMON_YEAR. */
|
---|
722 | #define RTTIME_FLAGS_LEAP_YEAR RT_BIT(6)
|
---|
723 | /** Set if the year is a common year.
|
---|
724 | * This is mutual exclusiv with RTTIME_FLAGS_LEAP_YEAR. */
|
---|
725 | #define RTTIME_FLAGS_COMMON_YEAR RT_BIT(7)
|
---|
726 | /** The mask of valid flags. */
|
---|
727 | #define RTTIME_FLAGS_MASK UINT32_C(0xff)
|
---|
728 | /** @} */
|
---|
729 |
|
---|
730 |
|
---|
731 | /**
|
---|
732 | * Gets the current system time (UTC).
|
---|
733 | *
|
---|
734 | * @returns pTime.
|
---|
735 | * @param pTime Where to store the time.
|
---|
736 | */
|
---|
737 | RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime);
|
---|
738 |
|
---|
739 | /**
|
---|
740 | * Sets the system time.
|
---|
741 | *
|
---|
742 | * @returns IPRT status code
|
---|
743 | * @param pTime The new system time (UTC).
|
---|
744 | *
|
---|
745 | * @remarks This will usually fail because changing the wall time is usually
|
---|
746 | * requires extra privileges.
|
---|
747 | */
|
---|
748 | RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime);
|
---|
749 |
|
---|
750 | /**
|
---|
751 | * Explodes a time spec (UTC).
|
---|
752 | *
|
---|
753 | * @returns pTime.
|
---|
754 | * @param pTime Where to store the exploded time.
|
---|
755 | * @param pTimeSpec The time spec to exploded.
|
---|
756 | */
|
---|
757 | RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec);
|
---|
758 |
|
---|
759 | /**
|
---|
760 | * Implodes exploded time to a time spec (UTC).
|
---|
761 | *
|
---|
762 | * @returns pTime on success.
|
---|
763 | * @returns NULL if the pTime data is invalid.
|
---|
764 | * @param pTimeSpec Where to store the imploded UTC time.
|
---|
765 | * If pTime specifies a time which outside the range, maximum or
|
---|
766 | * minimum values will be returned.
|
---|
767 | * @param pTime Pointer to the exploded time to implode.
|
---|
768 | * The fields u8Month, u8WeekDay and u8MonthDay are not used,
|
---|
769 | * and all the other fields are expected to be within their
|
---|
770 | * bounds. Use RTTimeNormalize() to calculate u16YearDay and
|
---|
771 | * normalize the ranges of the fields.
|
---|
772 | */
|
---|
773 | RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime);
|
---|
774 |
|
---|
775 | /**
|
---|
776 | * Normalizes the fields of a time structure.
|
---|
777 | *
|
---|
778 | * It is possible to calculate year-day from month/day and vice
|
---|
779 | * versa. If you adjust any of of these, make sure to zero the
|
---|
780 | * other so you make it clear which of the fields to use. If
|
---|
781 | * it's ambiguous, the year-day field is used (and you get
|
---|
782 | * assertions in debug builds).
|
---|
783 | *
|
---|
784 | * All the time fields and the year-day or month/day fields will
|
---|
785 | * be adjusted for overflows. (Since all fields are unsigned, there
|
---|
786 | * is no underflows.) It is possible to exploit this for simple
|
---|
787 | * date math, though the recommended way of doing that to implode
|
---|
788 | * the time into a timespec and do the math on that.
|
---|
789 | *
|
---|
790 | * @returns pTime on success.
|
---|
791 | * @returns NULL if the data is invalid.
|
---|
792 | *
|
---|
793 | * @param pTime The time structure to normalize.
|
---|
794 | *
|
---|
795 | * @remarks This function doesn't work with local time, only with UTC time.
|
---|
796 | */
|
---|
797 | RTDECL(PRTTIME) RTTimeNormalize(PRTTIME pTime);
|
---|
798 |
|
---|
799 | /**
|
---|
800 | * Gets the current local system time.
|
---|
801 | *
|
---|
802 | * @returns pTime.
|
---|
803 | * @param pTime Where to store the local time.
|
---|
804 | */
|
---|
805 | RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime);
|
---|
806 |
|
---|
807 | /**
|
---|
808 | * Gets the current delta between UTC and local time.
|
---|
809 | *
|
---|
810 | * @code
|
---|
811 | * RTTIMESPEC LocalTime;
|
---|
812 | * RTTimeSpecAddNano(RTTimeNow(&LocalTime), RTTimeLocalDeltaNano());
|
---|
813 | * @endcode
|
---|
814 | *
|
---|
815 | * @returns Returns the nanosecond delta between UTC and local time.
|
---|
816 | */
|
---|
817 | RTDECL(int64_t) RTTimeLocalDeltaNano(void);
|
---|
818 |
|
---|
819 | /**
|
---|
820 | * Gets the delta between UTC and local time at the given time.
|
---|
821 | *
|
---|
822 | * @code
|
---|
823 | * RTTIMESPEC LocalTime;
|
---|
824 | * RTTimeNow(&LocalTime);
|
---|
825 | * RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNanoFor(&LocalTime));
|
---|
826 | * @endcode
|
---|
827 | *
|
---|
828 | * @param pTimeSpec The time spec giving the time to get the delta for.
|
---|
829 | * @returns Returns the nanosecond delta between UTC and local time.
|
---|
830 | */
|
---|
831 | RTDECL(int64_t) RTTimeLocalDeltaNanoFor(PCRTTIMESPEC pTimeSpec);
|
---|
832 |
|
---|
833 | /**
|
---|
834 | * Explodes a time spec to the localized timezone.
|
---|
835 | *
|
---|
836 | * @returns pTime.
|
---|
837 | * @param pTime Where to store the exploded time.
|
---|
838 | * @param pTimeSpec The time spec to exploded (UTC).
|
---|
839 | */
|
---|
840 | RTDECL(PRTTIME) RTTimeLocalExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec);
|
---|
841 |
|
---|
842 | /**
|
---|
843 | * Normalizes the fields of a time structure containing local time.
|
---|
844 | *
|
---|
845 | * See RTTimeNormalize for details.
|
---|
846 | *
|
---|
847 | * @returns pTime on success.
|
---|
848 | * @returns NULL if the data is invalid.
|
---|
849 | * @param pTime The time structure to normalize.
|
---|
850 | */
|
---|
851 | RTDECL(PRTTIME) RTTimeLocalNormalize(PRTTIME pTime);
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Converts a time structure to UTC, relying on UTC offset information
|
---|
855 | * if it contains local time.
|
---|
856 | *
|
---|
857 | * @returns pTime on success.
|
---|
858 | * @returns NULL if the data is invalid.
|
---|
859 | * @param pTime The time structure to convert.
|
---|
860 | */
|
---|
861 | RTDECL(PRTTIME) RTTimeConvertToZulu(PRTTIME pTime);
|
---|
862 |
|
---|
863 | /**
|
---|
864 | * Converts a time spec to a ISO date string.
|
---|
865 | *
|
---|
866 | * @returns psz on success.
|
---|
867 | * @returns NULL on buffer underflow.
|
---|
868 | * @param pTime The time. Caller should've normalized this.
|
---|
869 | * @param psz Where to store the string.
|
---|
870 | * @param cb The size of the buffer.
|
---|
871 | */
|
---|
872 | RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb);
|
---|
873 |
|
---|
874 | /**
|
---|
875 | * Converts a time spec to a ISO date string, extended version.
|
---|
876 | *
|
---|
877 | * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
|
---|
878 | * (negative) or VERR_OUT_OF_RANGE (negative) on failure.
|
---|
879 | * @param pTime The time. Caller should've normalized this.
|
---|
880 | * @param psz Where to store the string.
|
---|
881 | * @param cb The size of the buffer.
|
---|
882 | * @param cFractionDigits Number of digits in the fraction. Max is 9.
|
---|
883 | */
|
---|
884 | RTDECL(ssize_t) RTTimeToStringEx(PCRTTIME pTime, char *psz, size_t cb, unsigned cFractionDigits);
|
---|
885 |
|
---|
886 | /** Suggested buffer length for RTTimeToString and RTTimeToStringEx output, including terminator. */
|
---|
887 | #define RTTIME_STR_LEN 40
|
---|
888 |
|
---|
889 | /**
|
---|
890 | * Attempts to convert an ISO date string to a time structure.
|
---|
891 | *
|
---|
892 | * We're a little forgiving with zero padding, unspecified parts, and leading
|
---|
893 | * and trailing spaces.
|
---|
894 | *
|
---|
895 | * @retval pTime on success,
|
---|
896 | * @retval NULL on failure.
|
---|
897 | * @param pTime Where to store the time on success.
|
---|
898 | * @param pszString The ISO date string to convert.
|
---|
899 | */
|
---|
900 | RTDECL(PRTTIME) RTTimeFromString(PRTTIME pTime, const char *pszString);
|
---|
901 |
|
---|
902 | /**
|
---|
903 | * Formats the given time on a RTC-2822 compliant format.
|
---|
904 | *
|
---|
905 | * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
|
---|
906 | * (negative) on failure.
|
---|
907 | * @param pTime The time. Caller should've normalized this.
|
---|
908 | * @param psz Where to store the string.
|
---|
909 | * @param cb The size of the buffer.
|
---|
910 | * @param fFlags RTTIME_RFC2822_F_XXX
|
---|
911 | * @sa RTTIME_RFC2822_LEN
|
---|
912 | */
|
---|
913 | RTDECL(ssize_t) RTTimeToRfc2822(PRTTIME pTime, char *psz, size_t cb, uint32_t fFlags);
|
---|
914 |
|
---|
915 | /** Suggested buffer length for RTTimeToRfc2822 output, including terminator. */
|
---|
916 | #define RTTIME_RFC2822_LEN 40
|
---|
917 | /** @name RTTIME_RFC2822_F_XXX
|
---|
918 | * @{ */
|
---|
919 | /** Use the deprecated GMT timezone instead of +/-0000.
|
---|
920 | * This is required by the HTTP RFC-7231 7.1.1.1. */
|
---|
921 | #define RTTIME_RFC2822_F_GMT RT_BIT_32(0)
|
---|
922 | /** @} */
|
---|
923 |
|
---|
924 | /**
|
---|
925 | * Attempts to convert an RFC-2822 date string to a time structure.
|
---|
926 | *
|
---|
927 | * We're a little forgiving with zero padding, unspecified parts, and leading
|
---|
928 | * and trailing spaces.
|
---|
929 | *
|
---|
930 | * @retval pTime on success,
|
---|
931 | * @retval NULL on failure.
|
---|
932 | * @param pTime Where to store the time on success.
|
---|
933 | * @param pszString The ISO date string to convert.
|
---|
934 | */
|
---|
935 | RTDECL(PRTTIME) RTTimeFromRfc2822(PRTTIME pTime, const char *pszString);
|
---|
936 |
|
---|
937 | /**
|
---|
938 | * Checks if a year is a leap year or not.
|
---|
939 | *
|
---|
940 | * @returns true if it's a leap year.
|
---|
941 | * @returns false if it's a common year.
|
---|
942 | * @param i32Year The year in question.
|
---|
943 | */
|
---|
944 | RTDECL(bool) RTTimeIsLeapYear(int32_t i32Year);
|
---|
945 |
|
---|
946 | /**
|
---|
947 | * Compares two normalized time structures.
|
---|
948 | *
|
---|
949 | * @retval 0 if equal.
|
---|
950 | * @retval -1 if @a pLeft is earlier than @a pRight.
|
---|
951 | * @retval 1 if @a pRight is earlier than @a pLeft.
|
---|
952 | *
|
---|
953 | * @param pLeft The left side time. NULL is accepted.
|
---|
954 | * @param pRight The right side time. NULL is accepted.
|
---|
955 | *
|
---|
956 | * @note A NULL time is considered smaller than anything else. If both are
|
---|
957 | * NULL, they are considered equal.
|
---|
958 | */
|
---|
959 | RTDECL(int) RTTimeCompare(PCRTTIME pLeft, PCRTTIME pRight);
|
---|
960 |
|
---|
961 | /**
|
---|
962 | * Gets the current nanosecond timestamp.
|
---|
963 | *
|
---|
964 | * @returns nanosecond timestamp.
|
---|
965 | */
|
---|
966 | RTDECL(uint64_t) RTTimeNanoTS(void);
|
---|
967 |
|
---|
968 | /**
|
---|
969 | * Gets the current millisecond timestamp.
|
---|
970 | *
|
---|
971 | * @returns millisecond timestamp.
|
---|
972 | */
|
---|
973 | RTDECL(uint64_t) RTTimeMilliTS(void);
|
---|
974 |
|
---|
975 | /**
|
---|
976 | * Debugging the time api.
|
---|
977 | *
|
---|
978 | * @returns the number of 1ns steps which has been applied by RTTimeNanoTS().
|
---|
979 | */
|
---|
980 | RTDECL(uint32_t) RTTimeDbgSteps(void);
|
---|
981 |
|
---|
982 | /**
|
---|
983 | * Debugging the time api.
|
---|
984 | *
|
---|
985 | * @returns the number of times the TSC interval expired RTTimeNanoTS().
|
---|
986 | */
|
---|
987 | RTDECL(uint32_t) RTTimeDbgExpired(void);
|
---|
988 |
|
---|
989 | /**
|
---|
990 | * Debugging the time api.
|
---|
991 | *
|
---|
992 | * @returns the number of bad previous values encountered by RTTimeNanoTS().
|
---|
993 | */
|
---|
994 | RTDECL(uint32_t) RTTimeDbgBad(void);
|
---|
995 |
|
---|
996 | /**
|
---|
997 | * Debugging the time api.
|
---|
998 | *
|
---|
999 | * @returns the number of update races in RTTimeNanoTS().
|
---|
1000 | */
|
---|
1001 | RTDECL(uint32_t) RTTimeDbgRaces(void);
|
---|
1002 |
|
---|
1003 |
|
---|
1004 | RTDECL(const char *) RTTimeNanoTSWorkerName(void);
|
---|
1005 |
|
---|
1006 |
|
---|
1007 | /** @name RTTimeNanoTS GIP worker functions, for TM.
|
---|
1008 | * @{ */
|
---|
1009 |
|
---|
1010 | /** Extra info optionally returned by the RTTimeNanoTS GIP workers. */
|
---|
1011 | typedef struct RTITMENANOTSEXTRA
|
---|
1012 | {
|
---|
1013 | /** The TSC value used (delta adjusted). */
|
---|
1014 | uint64_t uTSCValue;
|
---|
1015 | } RTITMENANOTSEXTRA;
|
---|
1016 | /** Pointer to extra info optionally returned by the RTTimeNanoTS GIP workers. */
|
---|
1017 | typedef RTITMENANOTSEXTRA *PRTITMENANOTSEXTRA;
|
---|
1018 |
|
---|
1019 | /** Pointer to a RTTIMENANOTSDATA structure. */
|
---|
1020 | typedef struct RTTIMENANOTSDATA *PRTTIMENANOTSDATA;
|
---|
1021 |
|
---|
1022 | /**
|
---|
1023 | * Nanosecond timestamp data.
|
---|
1024 | *
|
---|
1025 | * This is used to keep track of statistics and callback so IPRT
|
---|
1026 | * and TM (VirtualBox) can share code.
|
---|
1027 | *
|
---|
1028 | * @remark Keep this in sync with the assembly version in timesupA.asm.
|
---|
1029 | */
|
---|
1030 | typedef struct RTTIMENANOTSDATA
|
---|
1031 | {
|
---|
1032 | /** Where the previous timestamp is stored.
|
---|
1033 | * This is maintained to ensure that time doesn't go backwards or anything. */
|
---|
1034 | uint64_t volatile *pu64Prev;
|
---|
1035 |
|
---|
1036 | /**
|
---|
1037 | * Helper function that's used by the assembly routines when something goes bust.
|
---|
1038 | *
|
---|
1039 | * @param pData Pointer to this structure.
|
---|
1040 | * @param u64NanoTS The calculated nano ts.
|
---|
1041 | * @param u64DeltaPrev The delta relative to the previously returned timestamp.
|
---|
1042 | * @param u64PrevNanoTS The previously returned timestamp (as it was read it).
|
---|
1043 | */
|
---|
1044 | DECLCALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
|
---|
1045 |
|
---|
1046 | /**
|
---|
1047 | * Callback for when rediscovery is required.
|
---|
1048 | *
|
---|
1049 | * @returns Nanosecond timestamp.
|
---|
1050 | * @param pData Pointer to this structure.
|
---|
1051 | * @param pExtra Where to return extra time info. Optional.
|
---|
1052 | */
|
---|
1053 | DECLCALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra));
|
---|
1054 |
|
---|
1055 | /**
|
---|
1056 | * Callback for when some CPU index related stuff goes wrong.
|
---|
1057 | *
|
---|
1058 | * @returns Nanosecond timestamp.
|
---|
1059 | * @param pData Pointer to this structure.
|
---|
1060 | * @param pExtra Where to return extra time info. Optional.
|
---|
1061 | * @param idApic The APIC ID if available, otherwise (UINT16_MAX-1).
|
---|
1062 | * @param iCpuSet The CPU set index if available, otherwise
|
---|
1063 | * (UINT16_MAX-1).
|
---|
1064 | * @param iGipCpu The GIP CPU array index if available, otherwise
|
---|
1065 | * (UINT16_MAX-1).
|
---|
1066 | */
|
---|
1067 | DECLCALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra,
|
---|
1068 | uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
|
---|
1069 |
|
---|
1070 | /** Number of 1ns steps because of overshooting the period. */
|
---|
1071 | uint32_t c1nsSteps;
|
---|
1072 | /** The number of times the interval expired (overflow). */
|
---|
1073 | uint32_t cExpired;
|
---|
1074 | /** Number of "bad" previous values. */
|
---|
1075 | uint32_t cBadPrev;
|
---|
1076 | /** The number of update races. */
|
---|
1077 | uint32_t cUpdateRaces;
|
---|
1078 | } RTTIMENANOTSDATA;
|
---|
1079 |
|
---|
1080 | #ifndef IN_RING3
|
---|
1081 | /**
|
---|
1082 | * The Ring-3 layout of the RTTIMENANOTSDATA structure.
|
---|
1083 | */
|
---|
1084 | typedef struct RTTIMENANOTSDATAR3
|
---|
1085 | {
|
---|
1086 | R3PTRTYPE(uint64_t volatile *) pu64Prev;
|
---|
1087 | DECLR3CALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
|
---|
1088 | DECLR3CALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra));
|
---|
1089 | DECLR3CALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra,
|
---|
1090 | uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
|
---|
1091 | uint32_t c1nsSteps;
|
---|
1092 | uint32_t cExpired;
|
---|
1093 | uint32_t cBadPrev;
|
---|
1094 | uint32_t cUpdateRaces;
|
---|
1095 | } RTTIMENANOTSDATAR3;
|
---|
1096 | #else
|
---|
1097 | typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR3;
|
---|
1098 | #endif
|
---|
1099 |
|
---|
1100 | #ifndef IN_RING0
|
---|
1101 | /**
|
---|
1102 | * The Ring-3 layout of the RTTIMENANOTSDATA structure.
|
---|
1103 | */
|
---|
1104 | typedef struct RTTIMENANOTSDATAR0
|
---|
1105 | {
|
---|
1106 | R0PTRTYPE(uint64_t volatile *) pu64Prev;
|
---|
1107 | DECLR0CALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
|
---|
1108 | DECLR0CALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra));
|
---|
1109 | DECLR0CALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra,
|
---|
1110 | uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
|
---|
1111 | uint32_t c1nsSteps;
|
---|
1112 | uint32_t cExpired;
|
---|
1113 | uint32_t cBadPrev;
|
---|
1114 | uint32_t cUpdateRaces;
|
---|
1115 | } RTTIMENANOTSDATAR0;
|
---|
1116 | #else
|
---|
1117 | typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR0;
|
---|
1118 | #endif
|
---|
1119 |
|
---|
1120 | #ifndef IN_RC
|
---|
1121 | /**
|
---|
1122 | * The RC layout of the RTTIMENANOTSDATA structure.
|
---|
1123 | */
|
---|
1124 | typedef struct RTTIMENANOTSDATARC
|
---|
1125 | {
|
---|
1126 | RCPTRTYPE(uint64_t volatile *) pu64Prev;
|
---|
1127 | DECLRCCALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
|
---|
1128 | DECLRCCALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra));
|
---|
1129 | DECLRCCALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra,
|
---|
1130 | uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
|
---|
1131 | uint32_t c1nsSteps;
|
---|
1132 | uint32_t cExpired;
|
---|
1133 | uint32_t cBadPrev;
|
---|
1134 | uint32_t cUpdateRaces;
|
---|
1135 | } RTTIMENANOTSDATARC;
|
---|
1136 | #else
|
---|
1137 | typedef RTTIMENANOTSDATA RTTIMENANOTSDATARC;
|
---|
1138 | #endif
|
---|
1139 |
|
---|
1140 | /** Internal RTTimeNanoTS worker (assembly). */
|
---|
1141 | typedef DECLCALLBACKTYPE(uint64_t, FNTIMENANOTSINTERNAL,(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra));
|
---|
1142 | /** Pointer to an internal RTTimeNanoTS worker (assembly). */
|
---|
1143 | typedef FNTIMENANOTSINTERNAL *PFNTIMENANOTSINTERNAL;
|
---|
1144 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarNoDelta(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1145 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarNoDelta(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1146 | #ifdef IN_RING3
|
---|
1147 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicId(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1148 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1149 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1150 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscp(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1151 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1152 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseIdtrLim(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1153 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1154 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1155 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1156 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1157 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1158 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicId(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1159 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1160 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1161 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscp(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1162 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1163 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseIdtrLim(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1164 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1165 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1166 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1167 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1168 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1169 | #else
|
---|
1170 | RTDECL(uint64_t) RTTimeNanoTSLegacyAsync(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1171 | RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDelta(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1172 | RTDECL(uint64_t) RTTimeNanoTSLFenceAsync(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1173 | RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDelta(PRTTIMENANOTSDATA pData, PRTITMENANOTSEXTRA pExtra);
|
---|
1174 | #endif
|
---|
1175 |
|
---|
1176 | /** @} */
|
---|
1177 |
|
---|
1178 |
|
---|
1179 | /**
|
---|
1180 | * Gets the current nanosecond timestamp.
|
---|
1181 | *
|
---|
1182 | * This differs from RTTimeNanoTS in that it will use system APIs and not do any
|
---|
1183 | * resolution or performance optimizations.
|
---|
1184 | *
|
---|
1185 | * @returns nanosecond timestamp.
|
---|
1186 | */
|
---|
1187 | RTDECL(uint64_t) RTTimeSystemNanoTS(void);
|
---|
1188 |
|
---|
1189 | /**
|
---|
1190 | * Gets the current millisecond timestamp.
|
---|
1191 | *
|
---|
1192 | * This differs from RTTimeNanoTS in that it will use system APIs and not do any
|
---|
1193 | * resolution or performance optimizations.
|
---|
1194 | *
|
---|
1195 | * @returns millisecond timestamp.
|
---|
1196 | */
|
---|
1197 | RTDECL(uint64_t) RTTimeSystemMilliTS(void);
|
---|
1198 |
|
---|
1199 | /**
|
---|
1200 | * Get the nanosecond timestamp relative to program startup.
|
---|
1201 | *
|
---|
1202 | * @returns Timestamp relative to program startup.
|
---|
1203 | */
|
---|
1204 | RTDECL(uint64_t) RTTimeProgramNanoTS(void);
|
---|
1205 |
|
---|
1206 | /**
|
---|
1207 | * Get the microsecond timestamp relative to program startup.
|
---|
1208 | *
|
---|
1209 | * @returns Timestamp relative to program startup.
|
---|
1210 | */
|
---|
1211 | RTDECL(uint64_t) RTTimeProgramMicroTS(void);
|
---|
1212 |
|
---|
1213 | /**
|
---|
1214 | * Get the millisecond timestamp relative to program startup.
|
---|
1215 | *
|
---|
1216 | * @returns Timestamp relative to program startup.
|
---|
1217 | */
|
---|
1218 | RTDECL(uint64_t) RTTimeProgramMilliTS(void);
|
---|
1219 |
|
---|
1220 | /**
|
---|
1221 | * Get the second timestamp relative to program startup.
|
---|
1222 | *
|
---|
1223 | * @returns Timestamp relative to program startup.
|
---|
1224 | */
|
---|
1225 | RTDECL(uint32_t) RTTimeProgramSecTS(void);
|
---|
1226 |
|
---|
1227 | /**
|
---|
1228 | * Get the RTTimeNanoTS() of when the program started.
|
---|
1229 | *
|
---|
1230 | * @returns Program startup timestamp.
|
---|
1231 | */
|
---|
1232 | RTDECL(uint64_t) RTTimeProgramStartNanoTS(void);
|
---|
1233 |
|
---|
1234 |
|
---|
1235 | /**
|
---|
1236 | * Time zone information.
|
---|
1237 | */
|
---|
1238 | typedef struct RTTIMEZONEINFO
|
---|
1239 | {
|
---|
1240 | /** Unix time zone name (continent/country[/city]|). */
|
---|
1241 | const char *pszUnixName;
|
---|
1242 | /** Windows time zone name. */
|
---|
1243 | const char *pszWindowsName;
|
---|
1244 | /** The length of the unix time zone name. */
|
---|
1245 | uint8_t cchUnixName;
|
---|
1246 | /** The length of the windows time zone name. */
|
---|
1247 | uint8_t cchWindowsName;
|
---|
1248 | /** Two letter country/territory code if applicable, otherwise 'ZZ'. */
|
---|
1249 | char szCountry[3];
|
---|
1250 | /** Two letter windows country/territory code if applicable.
|
---|
1251 | * Empty string if no windows mapping. */
|
---|
1252 | char szWindowsCountry[3];
|
---|
1253 | #if 0 /* Add when needed and it's been extracted. */
|
---|
1254 | /** The standard delta in minutes (add to UTC). */
|
---|
1255 | int16_t cMinStdDelta;
|
---|
1256 | /** The daylight saving time delta in minutes (add to UTC). */
|
---|
1257 | int16_t cMinDstDelta;
|
---|
1258 | #endif
|
---|
1259 | /** closest matching windows time zone index. */
|
---|
1260 | uint32_t idxWindows;
|
---|
1261 | /** Flags, RTTIMEZONEINFO_F_XXX. */
|
---|
1262 | uint32_t fFlags;
|
---|
1263 | } RTTIMEZONEINFO;
|
---|
1264 | /** Pointer to time zone info. */
|
---|
1265 | typedef RTTIMEZONEINFO const *PCRTTIMEZONEINFO;
|
---|
1266 |
|
---|
1267 | /** @name RTTIMEZONEINFO_F_XXX - time zone info flags.
|
---|
1268 | * @{ */
|
---|
1269 | /** Indicates golden mapping entry for a windows time zone name. */
|
---|
1270 | #define RTTIMEZONEINFO_F_GOLDEN RT_BIT_32(0)
|
---|
1271 | /** @} */
|
---|
1272 |
|
---|
1273 | /**
|
---|
1274 | * Looks up static time zone information by unix name.
|
---|
1275 | *
|
---|
1276 | * @returns Pointer to info entry if found, NULL if not.
|
---|
1277 | * @param pszName The unix zone name (TZ).
|
---|
1278 | */
|
---|
1279 | RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByUnixName(const char *pszName);
|
---|
1280 |
|
---|
1281 | /**
|
---|
1282 | * Looks up static time zone information by window name.
|
---|
1283 | *
|
---|
1284 | * @returns Pointer to info entry if found, NULL if not.
|
---|
1285 | * @param pszName The windows zone name (reg key).
|
---|
1286 | */
|
---|
1287 | RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByWindowsName(const char *pszName);
|
---|
1288 |
|
---|
1289 | /**
|
---|
1290 | * Looks up static time zone information by windows index.
|
---|
1291 | *
|
---|
1292 | * @returns Pointer to info entry if found, NULL if not.
|
---|
1293 | * @param idxZone The windows timezone index.
|
---|
1294 | */
|
---|
1295 | RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByWindowsIndex(uint32_t idxZone);
|
---|
1296 |
|
---|
1297 | /**
|
---|
1298 | * Get the current time zone (TZ).
|
---|
1299 | *
|
---|
1300 | * @returns IPRT status code.
|
---|
1301 | * @param pszName Where to return the time zone name.
|
---|
1302 | * @param cbName The size of the name buffer.
|
---|
1303 | */
|
---|
1304 | RTDECL(int) RTTimeZoneGetCurrent(char *pszName, size_t cbName);
|
---|
1305 |
|
---|
1306 | /** @} */
|
---|
1307 |
|
---|
1308 | RT_C_DECLS_END
|
---|
1309 |
|
---|
1310 | #endif /* !IPRT_INCLUDED_time_h */
|
---|
1311 |
|
---|