diff options
author | Louis Dionne <ldionne.2@gmail.com> | 2023-06-12 10:43:55 -0700 |
---|---|---|
committer | Louis Dionne <ldionne.2@gmail.com> | 2023-06-19 09:07:05 -0400 |
commit | c7d3c84449f403716a8866e50491a1860a935b30 (patch) | |
tree | 5efe617b7cb38ccec14c5690d0c192ddc0e07a7d /libcxx/src/filesystem/filesystem_clock.cpp | |
parent | dc71a77d33620830020c939bba25ebdfdd1b6194 (diff) | |
download | llvm-c7d3c84449f403716a8866e50491a1860a935b30.zip llvm-c7d3c84449f403716a8866e50491a1860a935b30.tar.gz llvm-c7d3c84449f403716a8866e50491a1860a935b30.tar.bz2 |
[libc++] Split sources for <filesystem>
The operations.cpp file contained the implementation of a ton of
functionality unrelated to just the filesystem operations, and
filesystem_common.h contained a lot of unrelated functionality as well.
Splitting this up into more files will make it possible in the future
to support parts of <filesystem> (e.g. path) on systems where there is
no notion of a filesystem.
Differential Revision: https://reviews.llvm.org/D152377
Diffstat (limited to 'libcxx/src/filesystem/filesystem_clock.cpp')
-rw-r--r-- | libcxx/src/filesystem/filesystem_clock.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp new file mode 100644 index 0000000..c6b3c89 --- /dev/null +++ b/libcxx/src/filesystem/filesystem_clock.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <__config> +#include <chrono> +#include <filesystem> +#include <time.h> + +#include "posix_compat.h" // TimeSpec + +#if defined(_LIBCPP_WIN32API) +# define WIN32_LEAN_AND_MEAN +# define NOMINMAX +# include <windows.h> +#endif + +#if !defined(CLOCK_REALTIME) && !defined(_LIBCPP_WIN32API) +# include <sys/time.h> // for gettimeofday and timeval +#endif + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +const bool _FilesystemClock::is_steady; + +_FilesystemClock::time_point _FilesystemClock::now() noexcept { + typedef chrono::duration<rep> __secs; +#if defined(_LIBCPP_WIN32API) + typedef chrono::duration<rep, nano> __nsecs; + FILETIME time; + GetSystemTimeAsFileTime(&time); + detail::TimeSpec tp = detail::filetime_to_timespec(time); + return time_point(__secs(tp.tv_sec) + + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec))); +#elif defined(CLOCK_REALTIME) + typedef chrono::duration<rep, nano> __nsecs; + struct timespec tp; + if (0 != clock_gettime(CLOCK_REALTIME, &tp)) + __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed"); + return time_point(__secs(tp.tv_sec) + + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec))); +#else + typedef chrono::duration<rep, micro> __microsecs; + timeval tv; + gettimeofday(&tv, 0); + return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec)); +#endif // CLOCK_REALTIME +} + +_LIBCPP_END_NAMESPACE_FILESYSTEM |