1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 /* 8 * lib/krb5/os/timeofday.c 9 * 10 * Copyright 1990 by the Massachusetts Institute of Technology. 11 * All Rights Reserved. 12 * 13 * Export of this software from the United States of America may 14 * require a specific license from the United States Government. 15 * It is the responsibility of any person or organization contemplating 16 * export to obtain such a license before exporting. 17 * 18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 19 * distribute this software and its documentation for any purpose and 20 * without fee is hereby granted, provided that the above copyright 21 * notice appear in all copies and that both that copyright notice and 22 * this permission notice appear in supporting documentation, and that 23 * the name of M.I.T. not be used in advertising or publicity pertaining 24 * to distribution of the software without specific, written prior 25 * permission. M.I.T. makes no representations about the suitability of 26 * this software for any purpose. It is provided "as is" without express 27 * or implied warranty. 28 * 29 * 30 * libos: krb5_timeofday function for BSD 4.3 31 */ 32 33 34 #include <k5-int.h> 35 36 #ifdef _KERNEL 37 #include <sys/time.h> 38 #else 39 #include <time.h> 40 #include <errno.h> 41 #endif 42 43 #ifdef POSIX_TYPES 44 #define timetype time_t 45 #else 46 #define timetype long 47 #endif 48 49 #ifndef HAVE_ERRNO 50 extern int errno; 51 #endif 52 53 krb5_error_code KRB5_CALLCONV 54 krb5_timeofday(krb5_context context, register krb5_int32 *timeret) 55 { 56 krb5_os_context os_ctx = context->os_context; 57 krb5_int32 tval; 58 59 if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) { 60 *timeret = os_ctx->time_offset; 61 return 0; 62 } 63 { 64 krb5_int32 usecs; 65 krb5_error_code kret; 66 67 if (kret = krb5_crypto_us_timeofday(&tval, 68 &usecs)) 69 return kret; 70 } 71 if (tval == (timetype) -1) 72 #ifdef _KERNEL 73 return 1; 74 #else 75 return (krb5_error_code) errno; 76 #endif 77 if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) 78 tval += os_ctx->time_offset; 79 *timeret = tval; 80 81 return 0; 82 } 83