Path: blob/main/crypto/krb5/src/util/support/gettimeofday.c
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* util/support/gettimeofday.c */2/*3* Copyright (C) 2011 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/25/*26* Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan27* (Royal Institute of Technology, Stockholm, Sweden).28* All rights reserved.29*30* Redistribution and use in source and binary forms, with or without31* modification, are permitted provided that the following conditions32* are met:33*34* 1. Redistributions of source code must retain the above copyright35* notice, this list of conditions and the following disclaimer.36*37* 2. Redistributions in binary form must reproduce the above copyright38* notice, this list of conditions and the following disclaimer in the39* documentation and/or other materials provided with the distribution.40*41* 3. Neither the name of the Institute nor the names of its contributors42* may be used to endorse or promote products derived from this software43* without specific prior written permission.44*45* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND46* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE47* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE48* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE49* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL50* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS51* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)52* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT53* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY54* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF55* SUCH DAMAGE.56*/5758#include "k5-platform.h"5960#ifdef _WIN326162#include <winsock2.h>6364int65krb5int_gettimeofday (struct timeval *tp, void *ignore)66{67FILETIME ft;68ULARGE_INTEGER li;69ULONGLONG ull;7071GetSystemTimeAsFileTime(&ft);72li.LowPart = ft.dwLowDateTime;73li.HighPart = ft.dwHighDateTime;74ull = li.QuadPart;7576ull -= 116444736000000000i64;77ull /= 10i64; /* ull is now in microseconds */7879tp->tv_usec = (long)(ull % 1000000i64);80tp->tv_sec = (long)(ull / 1000000i64);8182return 0;83}8485#else8687/*88* Simple gettimeofday that only returns seconds.89*/90int91krb5int_gettimeofday (struct timeval *tp, void *ignore)92{93time_t t;9495t = time(NULL);96tp->tv_sec = (long) t;97tp->tv_usec = 0;98return 0;99}100101#endif /* !_WIN32 */102103104