ReactOS 0.4.15-dev-8422-g6219a1a
gettimeofday.c
Go to the documentation of this file.
1/* @(#)gettimeofday.c 1.9 12/11/29 Copyright 2007-2012 J. Schilling */
2#include <schily/mconfig.h>
3#ifndef lint
4static UConst char sccsid[] =
5 "@(#)gettimeofday.c 1.9 12/11/29 Copyright 2007-2012 J. Schilling";
6#endif
7/*
8 * Emulate gettimeofday where it does not exist
9 *
10 * Copyright (c) 2007-2012 J. Schilling
11 */
12/*
13 * The contents of this file are subject to the terms of the
14 * Common Development and Distribution License, Version 1.0 only
15 * (the "License"). You may not use this file except in compliance
16 * with the License.
17 *
18 * See the file CDDL.Schily.txt in this distribution for details.
19 *
20 * When distributing Covered Code, include this CDDL HEADER in each
21 * file and include the License file CDDL.Schily.txt from this distribution.
22 */
23
24#if !defined(HAVE_GETTIMEOFDAY)
25#if (defined(_MSC_VER) || defined(__MINGW32__))
26#include <schily/windows.h>
27#include <schily/time.h>
28#include <schily/utypes.h>
29#include <schily/standard.h>
30
31#ifdef _MSC_VER
32const __int64 MS_FTIME_ADD = 0x2b6109100i64;
33const __int64 MS_FTIME_SECS = 10000000i64;
34#else
35const Int64_t MS_FTIME_ADD = 0x2b6109100LL;
36const Int64_t MS_FTIME_SECS = 10000000LL;
37#endif
38
39EXPORT int
41 struct timeval *tp;
42 void *dummy; /* tzp is unspecified by POSIX */
43{
44 FILETIME ft;
45 Int64_t T;
46
47 if (tp == 0)
48 return (0);
49
50 GetSystemTimeAsFileTime(&ft); /* 100ns time since 1601 */
51 T = ft.dwHighDateTime;
52 T <<= 32;
53 T += ft.dwLowDateTime;
54
55 /*
56 * Cast to avoid a loss of data warning
57 * MSVC uses long instead of time_t for tv_sec
58 */
59 tp->tv_sec = (long) (T / MS_FTIME_SECS - MS_FTIME_ADD);
60 tp->tv_usec = (long) (T % MS_FTIME_SECS) / 10;
61
62 return (0);
63}
64#else /* (defined(_MSC_VER) || defined(__MINGW32__)) */
65
66#ifdef HAVE_TIME
67#include <schily/time.h>
68#include <schily/standard.h>
69
70EXPORT int
72 struct timeval *tp;
73 void *dummy; /* tzp is unspecified by POSIX */
74{
75 time_t t;
76
77 if (tp == 0)
78 return (0);
79
80 (void) time(&t);
81 tp->tv_sec = t;
82 tp->tv_usec = 0;
83
84 return (0);
85}
86#endif
87
88#endif /* (defined(_MSC_VER) || defined(__MINGW32__)) */
89#endif /* !defined(HAVE_GETTIMEOFDAY) */
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
#define __int64
Definition: basetyps.h:16
#define UConst
Definition: ccomdefs.h:72
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
__kernel_time_t time_t
Definition: linux.h:252
GLdouble GLdouble t
Definition: gl.h:2047
#define T
Definition: mbstring.h:31
__u16 time
Definition: mkdosfs.c:8
#define long
Definition: qsort.c:33
static UConst char sccsid[]
Definition: gettimeofday.c:4
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65