ReactOS  0.4.14-dev-315-gbb6fece
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
4 static 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
32 const __int64 MS_FTIME_ADD = 0x2b6109100i64;
33 const __int64 MS_FTIME_SECS = 10000000i64;
34 #else
35 const Int64_t MS_FTIME_ADD = 0x2b6109100LL;
36 const Int64_t MS_FTIME_SECS = 10000000LL;
37 #endif
38 
39 EXPORT 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 
70 EXPORT 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) */
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define LL
Definition: tui.h:85
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
static UConst char sccsid[]
Definition: gettimeofday.c:4
#define UConst
Definition: ccomdefs.h:72
GLdouble GLdouble t
Definition: gl.h:2047
__u16 time
Definition: mkdosfs.c:366
#define T
Definition: mbstring.h:31
DWORD dwHighDateTime
Definition: mapidefs.h:66
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2855
int gettimeofday(struct timeval *tv, struct timezone *tz)
Definition: gettimeofday.c:11
__kernel_time_t time_t
Definition: linux.h:252
unsigned char dummy
Definition: maze.c:118
#define long
Definition: qsort.c:33
DWORD dwLowDateTime
Definition: mapidefs.h:65
#define __int64
Definition: basetyps.h:16