From 61682d68c205903a38b2f55beb84618ed76574f4 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Sat, 22 Jun 2002 07:10:20 +0000 Subject: [PATCH] * c_ustime.c: Remove various things missed in 1-2-2-branch MacOS microseconds timer removal. * c_ustime.c: punted the accurate microseconds timing code because it wasn't so accurate after all. [pullup from 1-2-2-branch] * init_os_ctx.c: Add CoreServices.h before k5-int.h so we don't get multiple definitions for FSSpec. Also removed an unused variable in Mac OS X code and added casts for Mac OS X code so FSSpecs are cast to profile file types (code deals properly on the other side) * timeofday.c: Added casts to remove warnings * ccdefname.c, init_os_ctx.c, timeofday.c: Updated Mac OS X headers to new framework layout and updated Mac OS macros * read_pwd.c: Removed #defines for Mac OS X (__MACH__) because we now export krb5_read_password on Mac OS X [pullups from 1-2-2-branch] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14559 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 28 ++++++++ src/lib/krb5/os/c_ustime.c | 132 ++-------------------------------- src/lib/krb5/os/ccdefname.c | 6 +- src/lib/krb5/os/init_os_ctx.c | 40 +++++++---- src/lib/krb5/os/timeofday.c | 6 +- 5 files changed, 66 insertions(+), 146 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 338478294..6671a38f1 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,31 @@ +2002-06-22 Tom Yu + + * c_ustime.c: Remove various things missed in 1-2-2-branch MacOS + microseconds timer removal. + +2001-06-22 Miro Jurisic + + * c_ustime.c: punted the accurate microseconds timing code because it + wasn't so accurate after all. + [pullup from 1-2-2-branch] + +2002-06-22 Alexandra Ellwood + + * init_os_ctx.c: Add CoreServices.h before k5-int.h so we don't get + multiple definitions for FSSpec. Also removed an unused variable in + Mac OS X code and added casts for Mac OS X code so FSSpecs are cast + to profile file types (code deals properly on the other side) + + * timeofday.c: Added casts to remove warnings + + * ccdefname.c, init_os_ctx.c, timeofday.c: Updated Mac OS X + headers to new framework layout and updated Mac OS macros + + * read_pwd.c: Removed #defines for Mac OS X (__MACH__) because we + now export krb5_read_password on Mac OS X + + [pullups from 1-2-2-branch] + 2002-06-19 Ken Raeburn * init_os_ctx.c: Don't include sys/ioctl.h or sys/filio.h. diff --git a/src/lib/krb5/os/c_ustime.c b/src/lib/krb5/os/c_ustime.c index 92585a89d..02205014c 100644 --- a/src/lib/krb5/os/c_ustime.c +++ b/src/lib/krb5/os/c_ustime.c @@ -51,6 +51,7 @@ #include /* Nanosecond timing */ #include /* Check for presence of UpTime */ #include /* 64-bit integer math */ +#include /* Mac time -> UNIX time conversion */ /* Mac Cincludes */ #include @@ -58,16 +59,6 @@ static krb5_int32 last_sec = 0, last_usec = 0; -/* Check for availability of microseconds or better timer */ -Boolean HaveAccurateTime (); - -/* Convert nanoseconds to date and time */ -void AbsoluteToSecsNanosecs ( - AbsoluteTime eventTime, /* Value to convert */ - UInt32 *eventSeconds, /* Result goes here */ - UInt32 *residualNanoseconds /* Fractional second */ - ); - /* * The Unix epoch is 1/1/70, the Mac epoch is 1/1/04. * @@ -101,14 +92,6 @@ getTimeZoneOffset() /* 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 - */ - krb5_error_code krb5_crypto_us_timeofday(seconds, microseconds) krb5_int32 *seconds, *microseconds; @@ -116,34 +99,13 @@ krb5_crypto_us_timeofday(seconds, microseconds) krb5_int32 sec, usec; time_t the_time; - GetDateTime (&the_time); - - sec = the_time - - ((66 * 365 * 24 * 60 * 60) + (17 * 24 * 60 * 60) + - (getTimeZoneOffset() * 60 * 60)); - -#if TARGET_CPU_PPC /* Only PPC has accurate time */ - if (HaveAccurateTime ()) { /* Does hardware support accurate time? */ - - AbsoluteTime absoluteTime; - UInt32 nanoseconds; - - absoluteTime = UpTime (); - AbsoluteToSecsNanosecs (absoluteTime, &sec, &nanoseconds); - - usec = nanoseconds / 1000; - } else -#endif /* TARGET_CPU_PPC */ - { - GetDateTime (&sec); - usec = 0; - } + GetDateTime (&sec); + usec = 0; /* Fix secs to UNIX epoch */ - sec -= ((66 * 365 * 24 * 60 * 60) + (17 * 24 * 60 * 60) + - (getTimeZoneOffset() * 60 * 60)); - + mac_time_to_unix_time (&sec); + /* Make sure that we are _not_ repeating */ if (sec < last_sec) { /* Seconds should be at least equal to last seconds */ @@ -170,90 +132,6 @@ krb5_crypto_us_timeofday(seconds, microseconds) return 0; } -/* Check if we have microsecond or better timer */ - -Boolean HaveAccurateTime () -{ - static Boolean alreadyChecked = false; - static haveAccurateTime = false; - - if (!alreadyChecked) { - alreadyChecked = true; - haveAccurateTime = false; -#if TARGET_CPU_PPC - if ((Ptr) UpTime != (Ptr) kUnresolvedCFragSymbolAddress) { - UInt32 minAbsoluteTimeDelta; - UInt32 theAbsoluteTimeToNanosecondNumerator; - UInt32 theAbsoluteTimeToNanosecondDenominator; - UInt32 theProcessorToAbsoluteTimeNumerator; - UInt32 theProcessorToAbsoluteTimeDenominator; - - GetTimeBaseInfo ( - &minAbsoluteTimeDelta, - &theAbsoluteTimeToNanosecondNumerator, - &theAbsoluteTimeToNanosecondDenominator, - &theProcessorToAbsoluteTimeNumerator, - &theProcessorToAbsoluteTimeDenominator); - - /* minAbsoluteTimeDelta is the period in which Uptime is updated, in absolute time */ - /* We convert it to nanoseconds and compare it with .5 microsecond */ - - if (minAbsoluteTimeDelta * theAbsoluteTimeToNanosecondNumerator < - 500 * theAbsoluteTimeToNanosecondDenominator) { - haveAccurateTime = true; - } - } -#endif /* TARGET_CPU_PPC */ - } - - return haveAccurateTime; -} - -/* Convert nanoseconds to date and time */ - -void AbsoluteToSecsNanosecs ( - AbsoluteTime eventTime, /* Value to convert */ - UInt32 *eventSeconds, /* Result goes here */ - UInt32 *residualNanoseconds /* Fractional second */ - ) -{ - UInt64 eventNanoseconds; - UInt64 eventSeconds64; - static const UInt64 kTenE9 = U64SetU (1000000000); - static UInt64 gNanosecondsAtStart = U64SetU (0); - - /* - * If this is the first call, compute the offset between - * GetDateTime and UpTime. - */ - if (U64Compare (gNanosecondsAtStart, U64SetU (0)) == 0) { - UInt32 secondsAtStart; - AbsoluteTime absoluteTimeAtStart; - UInt64 upTimeAtStart; - UInt64 nanosecondsAtStart; - - GetDateTime (&secondsAtStart); - upTimeAtStart = UnsignedWideToUInt64 (AbsoluteToNanoseconds (UpTime())); - nanosecondsAtStart = U64SetU (secondsAtStart); - nanosecondsAtStart = U64Multiply (nanosecondsAtStart, kTenE9); - gNanosecondsAtStart = U64Subtract (nanosecondsAtStart, upTimeAtStart); - } - /* - * Convert the event time (UpTime value) to nanoseconds and add - * the local time epoch. - */ - eventNanoseconds = UnsignedWideToUInt64 (AbsoluteToNanoseconds (eventTime)); - eventNanoseconds = U64Add (gNanosecondsAtStart, eventNanoseconds); - /* - * eventSeconds = eventNanoseconds /= 10e9; - * residualNanoseconds = eventNanoseconds % 10e9; - * Finally, compute the local time (seconds) and fraction. - */ - eventSeconds64 = U64Div (eventNanoseconds, kTenE9); - eventNanoseconds = U64Subtract (eventNanoseconds, U64Multiply (eventSeconds64, kTenE9)); - *eventSeconds = (UInt64ToUnsignedWide (eventSeconds64)).lo; - *residualNanoseconds = (UInt64ToUnsignedWide (eventNanoseconds)).lo; -} #elif defined(_WIN32) /* Microsoft Windows NT and 95 (32bit) */ diff --git a/src/lib/krb5/os/ccdefname.c b/src/lib/krb5/os/ccdefname.c index 3556997bb..fb6af2fb5 100644 --- a/src/lib/krb5/os/ccdefname.c +++ b/src/lib/krb5/os/ccdefname.c @@ -31,8 +31,8 @@ #include "k5-int.h" #include -#ifdef macintosh -#include "CCache.h" +#if TARGET_OS_MAC +#include #endif #if defined(_WIN32) @@ -186,7 +186,7 @@ static krb5_error_code get_from_os(char *name_buf, int name_size) } #endif -#if defined (macintosh) +#if TARGET_OS_MAC static krb5_error_code get_from_os(char *name_buf, int name_size) { diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index ceefb73db..06344226e 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -27,13 +27,14 @@ */ #define NEED_WINDOWS + +#ifdef TARGET_OS_MAC +#include +#endif /* TARGET_OS_MAC */ + #include "k5-int.h" #include "os-proto.h" -#ifdef macintosh -#include -#endif /* macintosh */ - #if defined(_WIN32) static krb5_error_code @@ -171,7 +172,7 @@ static void free_filespecs(files) profile_filespec_t *files; { -#ifndef macintosh +#if !TARGET_OS_MAC char **cp; if (files == 0) @@ -188,15 +189,14 @@ os_get_default_config_files(pfiles, secure) profile_filespec_t ** pfiles; krb5_boolean secure; { - profile_filespec_t* files; -#ifdef macintosh +#ifdef TARGET_OS_MAC + FSSpec* files = nil; FSSpec* preferencesFiles = nil; UInt32 numPreferencesFiles; FSSpec* preferencesFilesToInit = nil; UInt32 numPreferencesFilesToInit; UInt32 i; Boolean foundPreferences = false; - Boolean writtenPreferences = false; SInt16 refNum = -1; SInt32 length = 0; @@ -278,7 +278,8 @@ os_get_default_config_files(pfiles, secure) else if (err != noErr) return ENOENT; -#else /* !macintosh */ +#else /* !TARGET_OS_MAC */ + profile_filespec_t* files; #if defined(_WIN32) krb5_error_code retval = 0; char *name = 0; @@ -366,7 +367,7 @@ os_get_default_config_files(pfiles, secure) files[i] = 0; #endif /* !_WIN32 */ #endif /* !macintosh */ - *pfiles = files; + *pfiles = (profile_filespec_t *)files; return 0; } @@ -389,8 +390,14 @@ os_init_paths(ctx) retval = os_get_default_config_files(&files, secure); if (!retval) { +#if TARGET_OS_MAC + retval = FSp_profile_init_path((const FSSpec *)files, + &ctx->profile); +#else retval = profile_init((const_profile_filespec_t *) files, &ctx->profile); +#endif + #ifdef KRB5_DNS_LOOKUP /* if none of the filenames can be opened use an empty profile */ if (retval == ENOENT) { @@ -466,8 +473,15 @@ krb5_get_profile (ctx, profile) retval = os_get_default_config_files(&files, ctx->profile_secure); - if (!retval) - retval = profile_init((const_profile_filespec_t *) files, profile); + if (!retval) { +#if TARGET_OS_MAC + retval = FSp_profile_init_path((const FSSpec *)files, + profile); +#else + retval = profile_init((const_profile_filespec_t *) files, + profile); +#endif + } if (files) free_filespecs(files); @@ -485,7 +499,7 @@ krb5_get_profile (ctx, profile) return retval; } -#ifndef macintosh +#if !TARGET_OS_MAC krb5_error_code krb5_set_config_files(ctx, filenames) diff --git a/src/lib/krb5/os/timeofday.c b/src/lib/krb5/os/timeofday.c index 143993c4b..f9945ecbf 100644 --- a/src/lib/krb5/os/timeofday.c +++ b/src/lib/krb5/os/timeofday.c @@ -48,12 +48,12 @@ krb5_timeofday(context, timeret) *timeret = os_ctx->time_offset; return 0; } -#ifdef macintosh +#if TARGET_OS_MAC { - long usecs; + krb5_int32 usecs; krb5_error_code kret; - if (kret = krb5_crypto_us_timeofday(&tval, &usecs)) + if (kret = krb5_crypto_us_timeofday((krb5_int32 *)&tval, &usecs)) return kret; } #else -- 2.26.2