diff options
author | Martin Storsjö <martin@martin.st> | 2020-11-04 22:56:03 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2021-01-29 13:38:27 +0200 |
commit | 592d62352933d34af62334d172c6fc665933e0de (patch) | |
tree | 9e406798a95ccbc66c449611636b985338b0b059 /libcxx/src/filesystem/operations.cpp | |
parent | 2ff8662b5d16129ec6d1ee60dcec4f6ff8f717e2 (diff) | |
download | llvm-592d62352933d34af62334d172c6fc665933e0de.zip llvm-592d62352933d34af62334d172c6fc665933e0de.tar.gz llvm-592d62352933d34af62334d172c6fc665933e0de.tar.bz2 |
[libcxx] Implement _FilesystemClock::now() and __last_write_time for windows
Differential Revision: https://reviews.llvm.org/D91142
Diffstat (limited to 'libcxx/src/filesystem/operations.cpp')
-rw-r--r-- | libcxx/src/filesystem/operations.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp index 548a027..40a863d 100644 --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -42,7 +42,7 @@ # define _LIBCPP_FILESYSTEM_USE_FSTREAM #endif -#if !defined(CLOCK_REALTIME) +#if !defined(CLOCK_REALTIME) && !defined(_LIBCPP_WIN32API) # include <sys/time.h> // for gettimeofday and timeval #endif @@ -567,7 +567,14 @@ const bool _FilesystemClock::is_steady; _FilesystemClock::time_point _FilesystemClock::now() noexcept { typedef chrono::duration<rep> __secs; -#if defined(CLOCK_REALTIME) +#if defined(_LIBCPP_WIN32API) + typedef chrono::duration<rep, nano> __nsecs; + FILETIME time; + GetSystemTimeAsFileTime(&time); + 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)) @@ -1121,6 +1128,17 @@ void __last_write_time(const path& p, file_time_type new_time, error_code* ec) { using detail::fs_time; ErrorHandler<void> err("last_write_time", ec, &p); +#if defined(_LIBCPP_WIN32API) + TimeSpec ts; + if (!fs_time::convert_to_timespec(ts, new_time)) + return err.report(errc::value_too_large); + detail::WinHandle h(p.c_str(), FILE_WRITE_ATTRIBUTES, 0); + if (!h) + return err.report(detail::make_windows_error(GetLastError())); + FILETIME last_write = timespec_to_filetime(ts); + if (!SetFileTime(h, nullptr, nullptr, &last_write)) + return err.report(detail::make_windows_error(GetLastError())); +#else error_code m_ec; array<TimeSpec, 2> tbuf; #if !defined(_LIBCPP_USE_UTIMENSAT) @@ -1142,6 +1160,7 @@ void __last_write_time(const path& p, file_time_type new_time, error_code* ec) { detail::set_file_times(p, tbuf, m_ec); if (m_ec) return err.report(m_ec); +#endif } void __permissions(const path& p, perms prms, perm_options opts, |