1 #pragma ident "%Z%%M% %I% %E% SMI" 2 /* 3 * lib/krb5/os/ustime.c 4 * 5 * Copyright 1990,1991 by the Massachusetts Institute of Technology. 6 * All Rights Reserved. 7 * 8 * Export of this software from the United States of America may 9 * require a specific license from the United States Government. 10 * It is the responsibility of any person or organization contemplating 11 * export to obtain such a license before exporting. 12 * 13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 14 * distribute this software and its documentation for any purpose and 15 * without fee is hereby granted, provided that the above copyright 16 * notice appear in all copies and that both that copyright notice and 17 * this permission notice appear in supporting documentation, and that 18 * the name of M.I.T. not be used in advertising or publicity pertaining 19 * to distribution of the software without specific, written prior 20 * permission. Furthermore if you modify this software you must label 21 * your software as modified software and not distribute it in such a 22 * fashion that it might be confused with the original M.I.T. software. 23 * M.I.T. makes no representations about the suitability of 24 * this software for any purpose. It is provided "as is" without express 25 * or implied warranty. 26 * 27 * krb5_crypto_us_timeofday() does all of the real work; however, we 28 * handle the time offset adjustment here, since this is context 29 * specific, and the crypto version of this call doesn't have access 30 * to the context variable. Fortunately the only user of 31 * krb5_crypto_us_timeofday in the crypto library doesn't require that 32 * this time adjustment be done. 33 */ 34 35 #include <k5-int.h> 36 37 krb5_error_code KRB5_CALLCONV 38 krb5_us_timeofday(krb5_context context, krb5_int32 *seconds, krb5_int32 *microseconds) 39 { 40 krb5_os_context os_ctx = context->os_context; 41 krb5_int32 sec, usec; 42 krb5_error_code retval; 43 44 if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) { 45 *seconds = os_ctx->time_offset; 46 *microseconds = os_ctx->usec_offset; 47 return 0; 48 } 49 retval = krb5_crypto_us_timeofday(&sec, &usec); 50 if (retval) 51 return retval; 52 if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) { 53 usec += os_ctx->usec_offset; 54 if (usec > 1000000) { 55 usec -= 1000000; 56 sec++; 57 } 58 if (usec < 0) { 59 usec += 1000000; 60 sec--; 61 } 62 sec += os_ctx->time_offset; 63 } 64 *seconds = sec; 65 *microseconds = usec; 66 return 0; 67 } 68