1 /* 2 * Copyright 2001-2003 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_DLLIMP krb5_error_code KRB5_CALLCONV 54 krb5_timeofday(context, timeret) 55 krb5_context context; 56 register krb5_int32 FAR *timeret; 57 { 58 krb5_os_context os_ctx = context->os_context; 59 krb5_int32 tval; 60 61 if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) { 62 *timeret = os_ctx->time_offset; 63 return 0; 64 } 65 { 66 krb5_int32 usecs; 67 krb5_error_code kret; 68 69 if (kret = krb5_crypto_us_timeofday(&tval, 70 &usecs)) 71 return kret; 72 } 73 if (tval == (timetype) -1) 74 #ifdef _KERNEL 75 return 1; 76 #else 77 return (krb5_error_code) errno; 78 #endif 79 if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) 80 tval += os_ctx->time_offset; 81 *timeret = tval; 82 83 return 0; 84 } 85