]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/timeflow.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // timeflow - abstract view of the flow of time
37 gettimeofday(&tv
, NULL
);
38 return tv
.tv_sec
+ double(tv
.tv_usec
) / 1E6
;
45 Absolute::Absolute(const struct timeval
&tv
)
46 { mValue
= tv
.tv_sec
+ double(tv
.tv_usec
) / 1E6
; }
48 Absolute::Absolute(const struct timespec
&tv
)
49 { mValue
= tv
.tv_sec
+ double(tv
.tv_nsec
) / 1E9
; }
51 Absolute::operator struct timeval () const
54 if (mValue
> LONG_MAX
) {
58 tv
.tv_sec
= int32_t(mValue
);
60 tv
.tv_usec
= int32_t(modf(mValue
, &intPart
) * 1E6
);
65 Absolute::operator struct timespec () const
68 if (mValue
> LONG_MAX
) {
72 ts
.tv_sec
= time_t(mValue
);
74 ts
.tv_nsec
= int32_t(modf(mValue
, &intPart
) * 1E9
);
79 struct timeval
Interval::timevalInterval() const
82 if (mValue
> LONG_MAX
) {
85 } else if (mValue
< 0) {
86 tv
.tv_sec
= tv
.tv_usec
= 0;
88 tv
.tv_sec
= int32_t(mValue
);
90 tv
.tv_usec
= int32_t(modf(mValue
, &intPart
) * 1E6
);
97 // Estimate resolution at given time.
99 // BSD select(2) has theoretical microsecond resolution, but the underlying
100 // Mach system deals with milliseconds, so we report that conservatively.
101 // Sometime in the future when the sun is near collapse, residual resolution
102 // of a double will drop under 1E-3, but we won't worry about that just yet.
104 Interval
resolution(Absolute
)
110 } // end namespace Time
111 } // end namespace Security