This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 5454#cmakedefine01 HAVE_GETDOMAINNAME_SIZET
5555#cmakedefine01 HAVE_INOTIFY
5656#cmakedefine01 HAVE_CLOCK_MONOTONIC
57+ #cmakedefine01 HAVE_CLOCK_REALTIME
5758#cmakedefine01 HAVE_MACH_ABSOLUTE_TIME
5859#cmakedefine01 HAVE_MACH_TIMEBASE_INFO
5960#cmakedefine01 HAVE_CURLM_ADDED_ALREADY
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ set(NATIVE_SOURCES
1818 pal_tcpstate.cpp
1919 pal_time.cpp
2020 pal_uid.cpp
21+ pal_datetime.cpp
2122)
2223
2324if (CMAKE_SYSTEM_NAME STREQUAL Linux)
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+ // See the LICENSE file in the project root for more information.
4+
5+ #include " pal_config.h"
6+
7+ #include < stdlib.h>
8+ #include < stdint.h>
9+ #include < time.h>
10+ #include < sys/time.h>
11+
12+ static const int64_t TICKS_PER_SECOND = 10000000 ; /* 10^7 */
13+ #if HAVE_CLOCK_REALTIME
14+ static const int64_t NANOSECONDS_PER_TICK = 100 ;
15+ #else
16+ static const int64_t TICKS_PER_MICROSECOND = 10 ; /* 1000 / 100 */
17+ #endif
18+
19+ //
20+ // SystemNative_GetSystemTimeAsTicks return the system time as ticks (100 nanoseconds)
21+ // since 00:00 01 January 1970 UTC (Unix epoch)
22+ //
23+ extern " C" int64_t SystemNative_GetSystemTimeAsTicks ()
24+ {
25+ #if HAVE_CLOCK_REALTIME
26+ struct timespec time;
27+ if (clock_gettime (CLOCK_REALTIME, &time) == 0 )
28+ {
29+ return static_cast <int64_t >(time.tv_sec ) * TICKS_PER_SECOND + (time.tv_nsec / NANOSECONDS_PER_TICK);
30+ }
31+ #else
32+ struct timeval time;
33+ if (gettimeofday (&time, NULL ) == 0 )
34+ {
35+ return static_cast <int64_t >(time.tv_sec ) * TICKS_PER_SECOND + (time.tv_usec * TICKS_PER_MICROSECOND);
36+ }
37+ #endif
38+ // in failure we return 00:00 01 January 1970 UTC (Unix epoch)
39+ return 0 ;
40+ }
Original file line number Diff line number Diff line change @@ -339,6 +339,21 @@ check_cxx_source_runs(
339339 "
340340 HAVE_CLOCK_MONOTONIC)
341341
342+ check_cxx_source_runs(
343+ "
344+ #include <stdlib.h>
345+ #include <time.h>
346+ #include <sys/time.h>
347+ int main()
348+ {
349+ int ret;
350+ struct timespec ts;
351+ ret = clock_gettime(CLOCK_REALTIME, &ts);
352+ exit(ret);
353+ }
354+ "
355+ HAVE_CLOCK_REALTIME)
356+
342357check_function_exists(
343358 mach_absolute_time
344359 HAVE_MACH_ABSOLUTE_TIME)
You can’t perform that action at this time.
0 commit comments