source: lib/gettimeofday.c @ 9d7d9e9

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 9d7d9e9 was e641bdc, checked in by Matt Brown <mattb@…>, 16 years ago

Added WIN32 build environment infrastructure. See docs/WIN32.TXT for details.

  • Property mode set to 100755
File size: 2.2 KB
Line 
1/*
2 * Defines gettimeofday
3 *
4 * Based on timeval.h by Wu Yongwei
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20#include "config.h"
21
22/* AFAIK windows doesn't run on any Big Endian machines... If it does
23 * winlibtrace will break! - MattB
24 */
25#ifdef _MSC_VER
26#pragma warning(disable:4996)
27#endif
28
29#ifndef WIN32_LEAN_AND_MEAN
30#define WIN32_LEAN_AND_MEAN
31#endif
32
33#include <winsock2.h>
34#include <time.h>
35
36#ifndef _FILETIME_
37#define _FILETIME_
38typedef struct _FILETIME
39{
40    DWORD dwLowDateTime;
41    DWORD dwHighDateTime;
42} FILETIME;
43#endif
44
45#ifdef _MSC_VER
46#define EPOCHFILETIME (116444736000000000i64)
47#else
48#define EPOCHFILETIME (116444736000000000LL)
49#endif
50
51struct timezone {
52        int tz_minuteswest; /* minutes W of Greenwich */
53        int tz_dsttime;         /* type of dst correction */
54};
55
56
57int gettimeofday(struct timeval *tv, struct timezone *tz)
58{
59    FILETIME        ft;
60    LARGE_INTEGER   li;
61    __int64         t;
62    static int      tzflag;
63
64    if (tv)
65    {
66        GetSystemTimeAsFileTime(&ft);
67        li.LowPart  = ft.dwLowDateTime;
68        li.HighPart = ft.dwHighDateTime;
69        t  = li.QuadPart;       /* In 100-nanosecond intervals */
70        t -= EPOCHFILETIME;     /* Offset to the Epoch time */
71        t /= 10;                /* In microseconds */
72        tv->tv_sec  = (long)(t / 1000000);
73        tv->tv_usec = (long)(t % 1000000);
74    }
75
76    if (tz)
77    {
78        if (!tzflag)
79        {
80            _tzset();
81            tzflag++;
82        }
83        tz->tz_minuteswest = _timezone / 60;
84        tz->tz_dsttime = _daylight;
85    }
86
87    return 0;
88}
Note: See TracBrowser for help on using the repository browser.