Subversion Repositories f9daq

Rev

Rev 197 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * gettimeofday.c
  3.  *    Win32 gettimeofday() replacement
  4.  *
  5.  * src/port/gettimeofday.c
  6.  *
  7.  * Copyright (c) 2003 SRA, Inc.
  8.  * Copyright (c) 2003 SKC, Inc.
  9.  *
  10.  * Permission to use, copy, modify, and distribute this software and
  11.  * its documentation for any purpose, without fee, and without a
  12.  * written agreement is hereby granted, provided that the above
  13.  * copyright notice and this paragraph and the following two
  14.  * paragraphs appear in all copies.
  15.  *
  16.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
  17.  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
  18.  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
  19.  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
  20.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  21.  *
  22.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
  23.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24.  * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
  25.  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
  26.  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  27.  */
  28.  
  29. //#include "c.h"
  30. #include <windows.h>
  31. #include <time.h>
  32.  
  33.  
  34. /* FILETIME of Jan 1 1970 00:00:00. */
  35. static const unsigned __int64 epoch = ((unsigned __int64) 116444736000000000ULL);
  36.  
  37. /*
  38.  * timezone information is stored outside the kernel so tzp isn't used anymore.
  39.  *
  40.  * Note: this function is not for Win32 high precision timing purpose. See
  41.  * elapsed_time().
  42.  */
  43. int gettimeofday(struct timeval * tp, struct timezone * tzp){
  44.     FILETIME    file_time;
  45.     SYSTEMTIME  system_time;
  46.     ULARGE_INTEGER ularge;
  47.  
  48.     GetSystemTime(&system_time);
  49.     SystemTimeToFileTime(&system_time, &file_time);
  50.     ularge.LowPart = file_time.dwLowDateTime;
  51.     ularge.HighPart = file_time.dwHighDateTime;
  52.  
  53.     tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
  54.     tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
  55.  
  56.     return 0;
  57. }