c_ustime.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* Copyright 1990,1991 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*
* krb5_mstimeofday for BSD 4.3
*/
#define NEED_SOCKETS
#include <k5-int.h>
#ifdef macintosh
/* We're a Macintosh -- do Mac time things. */
/*
* This code is derived from kerberos/src/lib/des/mac_time.c from
* the Cygnus Support release of Kerberos V4:
*
* (Originally time_stuff.c)
* Copyright 1989 by the Massachusetts Institute of Technology.
* Macintosh ooperating system interface for Kerberos.
*/
#include <ConditionalMacros.h>
#include <script.h> /* Defines MachineLocation, used by getTimeZoneOffset */
#include <ToolUtils.h> /* Defines BitTst(), called by getTimeZoneOffset() */
#include <OSUtils.h> /* Defines GetDateTime */
#include <DriverServices.h> /* Nanosecond timing */
#include <CodeFragments.h> /* Check for presence of UpTime */
#include <Math64.h> /* 64-bit integer math */
/* Mac Cincludes */
#include <string.h>
#include <stddef.h>
/* Check for availability of microseconds or better timer */
/* Convert nanoseconds to date and time */
void AbsoluteToSecsNanosecs (
);
/*
* The Unix epoch is 1/1/70, the Mac epoch is 1/1/04.
*
* 70 - 4 = 66 year differential
*
* Thus the offset is:
*
* plus
*
* Don't forget the offset from GMT.
*/
/* returns the offset in hours between the mac local time and the GMT */
/* unsigned krb5_int32 */
{
long gmtDelta;
macLocation.u.gmtDelta=0L;
gmtDelta |= 0xFF000000;
gmtDelta /= 3600L;
return(gmtDelta);
}
/* Returns the GMT in seconds (and fake microseconds) using the Unix epoch */
/*
* Note that unix timers are guaranteed that consecutive calls to timing functions will
* always return monotonically increasing values for time; even if called within one microsecond,
* they must increase from one call to another. We must preserve this property in this code,
* even though Mac UpTime does not make such guarantees... (actually it does, but it measures in
* units that can be finer than 1 microsecond, so conversion can cause repeat microsecond values
*/
{
GetDateTime (&the_time);
((66 * 365 * 24 * 60 * 60) + (17 * 24 * 60 * 60) +
#if TARGET_CPU_PPC /* Only PPC has accurate time */
if (HaveAccurateTime ()) { /* Does hardware support accurate time? */
absoluteTime = UpTime ();
} else
#endif /* TARGET_CPU_PPC */
{
GetDateTime (&sec);
usec = 0;
}
/* Fix secs to UNIX epoch */
/* Make sure that we are _not_ repeating */
}
}
sec++;
usec = 0;
}
}
return 0;
}
/* Check if we have microsecond or better timer */
{
static Boolean alreadyChecked = false;
static haveAccurateTime = false;
if (!alreadyChecked) {
alreadyChecked = true;
haveAccurateTime = false;
#if TARGET_CPU_PPC
/* minAbsoluteTimeDelta is the period in which Uptime is updated, in absolute time */
/* We convert it to nanoseconds and compare it with .5 microsecond */
haveAccurateTime = true;
}
}
#endif /* TARGET_CPU_PPC */
}
return haveAccurateTime;
}
/* Convert nanoseconds to date and time */
void AbsoluteToSecsNanosecs (
)
{
/*
* If this is the first call, compute the offset between
* GetDateTime and UpTime.
*/
}
/*
* Convert the event time (UpTime value) to nanoseconds and add
* the local time epoch.
*/
/*
* eventSeconds = eventNanoseconds /= 10e9;
* residualNanoseconds = eventNanoseconds % 10e9;
* Finally, compute the local time (seconds) and fraction.
*/
}
/* Microsoft Windows NT and 95 (32bit) */
/* This one works for WOW (Windows on Windows, ntvdm on Win-NT) */
#include <time.h>
#include <string.h>
{
static krb5_int32 last_sec = 0;
static krb5_int32 last_usec = 0;
if (usec >= 1000000) {
++sec;
usec = 0;
}
}
*microseconds = usec;
return 0;
}
/*
* Originally written by John Gilmore, Cygnus Support, May '94.
* Public Domain.
*/
#include <time.h>
#include <dos.h>
#include <string.h>
/*
* Time handling. Translate Unix time calls into Kerberos internal
* procedure calls.
*
* Due to the fact that DOS time can be unreliable we have reverted
* to using the AT hardware clock and converting it to Unix time.
*/
static time_t win_gettime ();
static long win_time_get_epoch(); /* Adjust for MSC 7.00 bug */
{
static krb5_int32 last_sec = 0;
static krb5_int32 last_usec = 0;
usec = 0; /* Can't do microseconds */
if (usec >= 1000000) {
++sec;
usec = 0;
}
}
*microseconds = usec;
return 0;
}
static time_t
win_gettime () {
long convert; /* MSC 7.00 bug work around */
/* Get time from AT hardware clock INT 0x1A, AH=2 */
/* 0x13 = decimal 13, hence the decoding below */
/* Get date from AT hardware clock INT 0x1A, AH=4 */
}
/*
* This routine figures out the current time epoch and returns the
* conversion factor. It exists because
* Microloss screwed the pooch on the time() and _ftime() calls in
* its release 7.0 libraries. They changed the epoch to Dec 31, 1899!
* Idiots... We try to cope.
*/
static long epoch = 0;
static int epoch_set = 0;
long
{
if (!epoch_set) {
epoch_set = 1;
}
return epoch;
}
#else
/* We're a Unix machine -- do Unix time things. */
#ifdef _KERNEL
#else
#include <time.h>
#include <errno.h>
#endif
{
#ifndef _KERNEL
/* failed, return errno */
return ((krb5_error_code) errno);
}
#else
gethrestime(&now);
#endif
}
} else
return (0);
}
#endif