2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A * lib/krb5/os/timeofday.c
2N/A *
2N/A * Copyright 1990 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A *
2N/A * libos: krb5_timeofday function for BSD 4.3
2N/A */
2N/A
2N/A
2N/A#include "k5-int.h"
2N/A
2N/A#ifdef _KERNEL
2N/A#include <sys/time.h>
2N/A#else
2N/A#include <time.h>
2N/A#include <errno.h>
2N/A#endif
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_timeofday(krb5_context context, register krb5_timestamp *timeret)
2N/A{
2N/A krb5_os_context os_ctx = context->os_context;
2N/A /* Solaris Kerberos */
2N/A krb5_int32 tval;
2N/A
2N/A if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) {
2N/A *timeret = os_ctx->time_offset;
2N/A return 0;
2N/A }
2N/A {
2N/A krb5_int32 usecs;
2N/A krb5_error_code kret;
2N/A
2N/A if (kret = krb5_crypto_us_timeofday(&tval,
2N/A &usecs))
2N/A return kret;
2N/A }
2N/A /* Solaris Kerberos */
2N/A if (tval == (krb5_int32) -1)
2N/A#ifdef _KERNEL
2N/A return 1;
2N/A#else
2N/A return (krb5_error_code) errno;
2N/A#endif
2N/A if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID)
2N/A tval += os_ctx->time_offset;
2N/A *timeret = tval;
2N/A return 0;
2N/A}
2N/A