]>
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::operator struct timeval () const
51 if (mValue
> LONG_MAX
) {
55 tv
.tv_sec
= int32_t(mValue
);
57 tv
.tv_usec
= int32_t(modf(mValue
, &intPart
));
62 struct timeval
Interval::timevalInterval() const
65 if (mValue
> LONG_MAX
) {
68 } else if (mValue
< 0) {
69 tv
.tv_sec
= tv
.tv_usec
= 0;
71 tv
.tv_sec
= int32_t(mValue
);
73 tv
.tv_usec
= int32_t(modf(mValue
, &intPart
));
80 // Estimate resolution at given time.
82 // BSD select(2) has theoretical microsecond resolution, but the underlying
83 // Mach system deals with milliseconds, so we report that conservatively.
84 // Sometime in the future when the sun is near collapse, residual resolution
85 // of a double will drop under 1E-3, but we won't worry about that just yet.
87 Interval
resolution(Absolute
)
93 } // end namespace Time
94 } // end namespace Security