time.c revision 15a44745412679c30a6d022733925af70a38b715
/*
* Copyright (C) 1998-2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: time.c,v 1.18 2000/07/27 09:53:18 tale Exp $ */
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <isc/assertions.h>
/*
* struct FILETIME uses "100-nanoseconds intervals".
* NS / S = 1000000000 (10^9).
* While it is reasonably obvious that this makes the needed
* conversion factor 10^7, it is coded this way for additional clarity.
*/
#define NS_PER_S 1000000000
#define NS_INTERVAL 100
/***
*** Intervals
***/
static isc_interval_t zero_interval = { 0 };
void
unsigned int seconds, unsigned int nanoseconds) {
/*
* Set 'i' to a value representing an interval of 'seconds' seconds
* and 'nanoseconds' nanoseconds, suitable for use in isc_time_add()
* and isc_time_subtract().
*/
+ nanoseconds / NS_INTERVAL;
}
/*
* Returns ISC_TRUE iff. 'i' is the zero interval.
*/
if (i->interval == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
/***
*** Absolute Times
***/
static isc_time_t epoch = { 0, 0 };
void
/*
* Set 't' to a particular number of seconds + nanoseconds since the
* epoch.
*/
+ nanoseconds / NS_INTERVAL;
}
void
/*
* Set 't' to the time of the epoch.
*/
t->absolute.dwLowDateTime = 0;
t->absolute.dwHighDateTime = 0;
}
isc_time_isepoch(isc_time_t *t) {
/*
* Returns ISC_TRUE iff. 't' is the epoch ("time zero").
*/
if (t->absolute.dwLowDateTime == 0 &&
t->absolute.dwHighDateTime == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_time_now(isc_time_t *t) {
/*
* Set *t to the current absolute time.
*/
return (ISC_R_SUCCESS);
}
/*
* Set *t to the current absolute time + i.
*/
return (ISC_R_RANGE);
return (ISC_R_SUCCESS);
}
int
/*
* Compare the times referenced by 't1' and 't2'
*/
}
/*
* Add 't' to 'i', storing the result in 'result'.
*/
return (ISC_R_RANGE);
return (ISC_R_SUCCESS);
}
/*
* Subtract 'i' from 't', storing the result in 'result'.
*/
return (ISC_R_RANGE);
}
return (0);
/*
* Convert to microseconds.
*/
return (i3);
}
isc_time_seconds(isc_time_t *t) {
}
/*
* Ensure that the number of seconds can be represented by a time_t.
* Since the number seconds is an unsigned int and since time_t is
* mostly opaque, this is trickier than it seems. (This standardized
* opaqueness of time_t is *very* * frustrating; time_t is not even
* limited to being an integral type.) Thought it is known at the
* time of this writing that time_t is a signed long on the Win32
* platform, the full treatment is given to figuring out if things
* fit to allow for future Windows platforms where time_t is *not*
* a signed long, or where perhaps a signed long is longer than
* it currently is.
*/
/*
* First, only do the range tests if the type of size_t is integral.
*/
/*
* Did all the bits make it in?
*/
return (ISC_R_RANGE);
/*
* Is time_t signed with the high bit set?
*
* The first test (the sizeof comparison) determines
* whether we can even deduce the signedness of time_t
* by using ANSI's rule about integer conversion to
* wider integers.
*
* The second test uses that ANSI rule to see whether
* the value of time_t was sign extended into QuadPart.
* If the test is true, then time_t is signed.
*
* The final test ensures the high bit is not set, or
* the value is negative and hence there is a range error.
*/
return (ISC_R_RANGE);
/*
* Last test ... the size of time_t is >= that of i2.QuadPart,
* so we can't determine its signedness. Unconditionally
* declare anything with the high bit set as out of range.
* Since even the maxed signed value is ludicrously far from
* when this is being written, this rule shall not impact
* anything for all intents and purposes.
*
* How far? Well ... if FILETIME is in 100 ns intervals since
* 1600, and a QuadPart can store 9223372036854775808 such
* intervals when interpreted as signed (ie, if sizeof(time_t)
* == sizeof(QuadPart) but time_t is signed), that means
* 9223372036854775808 / INTERVALS_PER_S = 922,337,203,685
* seconds. That number divided by 60 * 60 * 24 * 365 seconds
* per year means a signed time_t can store at least 29,247
* years, with only 400 of those years used up since 1600 as I
* write this in May, 2000.
*
* (Real date calculations are of course incredibly more
* complex; I'm only describing the approximate scale of
* the numbers involved here.)
*
* If the Galactic Federation is still running libisc's time
* libray on a Windows platform in the year 27647 A.D., then
* feel free to hunt down my greatgreatgreatgreatgreat(etc)
* grandchildren and whine at them about what I did.
*/
return (ISC_R_RANGE);
}
return (ISC_R_SUCCESS);
}
i.QuadPart -= isc_time_seconds(t);
}