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