00001 /* 00002 * gettimeofday.c 00003 * Win32 gettimeofday() replacement 00004 * 00005 * src/port/gettimeofday.c 00006 * 00007 * Copyright (c) 2003 SRA, Inc. 00008 * Copyright (c) 2003 SKC, Inc. 00009 * 00010 * Permission to use, copy, modify, and distribute this software and 00011 * its documentation for any purpose, without fee, and without a 00012 * written agreement is hereby granted, provided that the above 00013 * copyright notice and this paragraph and the following two 00014 * paragraphs appear in all copies. 00015 * 00016 * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 00017 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 00018 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 00019 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED 00020 * OF THE POSSIBILITY OF SUCH DAMAGE. 00021 * 00022 * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS 00025 * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, 00026 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00027 */ 00028 00029 #include "c.h" 00030 00031 #include <sys/time.h> 00032 00033 00034 /* FILETIME of Jan 1 1970 00:00:00. */ 00035 static const unsigned __int64 epoch = UINT64CONST(116444736000000000); 00036 00037 /* 00038 * timezone information is stored outside the kernel so tzp isn't used anymore. 00039 * 00040 * Note: this function is not for Win32 high precision timing purpose. See 00041 * elapsed_time(). 00042 */ 00043 int 00044 gettimeofday(struct timeval * tp, struct timezone * tzp) 00045 { 00046 FILETIME file_time; 00047 SYSTEMTIME system_time; 00048 ULARGE_INTEGER ularge; 00049 00050 GetSystemTime(&system_time); 00051 SystemTimeToFileTime(&system_time, &file_time); 00052 ularge.LowPart = file_time.dwLowDateTime; 00053 ularge.HighPart = file_time.dwHighDateTime; 00054 00055 tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); 00056 tp->tv_usec = (long) (system_time.wMilliseconds * 1000); 00057 00058 return 0; 00059 }