<div dir="ltr">OK. I also added debug print statements to the test to give more information. I'm just waiting for the bots to cycle now.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 25, 2018 at 7:18 PM Alex L <<a href="mailto:arphaman@gmail.com">arphaman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I couldn't reproduce it on my machine, and I don't have access to the bot ATM, but I will try it on an older OS to see if it's an issue with the particular OS that's used on our bot.<div><br></div><div>Cheers,</div><div>Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2018 at 17:43, Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'll take a look and will try to reproduce it right now.</div><div class="m_6747764441411225383HOEnZb"><div class="m_6747764441411225383h5"><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2018 at 17:37, Eric Fiselier <span dir="ltr"><<a href="mailto:eric@efcs.ca" target="_blank">eric@efcs.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Wed, Jul 25, 2018 at 6:03 PM Alex L <<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hmm, looks like the added test is failing on Darwin even after your fixes.<div><br></div><div>Do you have an idea of why that could be?</div></div></blockquote><div> </div></span><div>Not yet, working on it now.</div><div>I'm failing to reproduce it on my macbook though. If you can, any information about what's going on would be helpful.</div><div>Like what are those actual values?</div><div><div class="m_6747764441411225383m_-5557678886675019082h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div><a href="http://lab.llvm.org:8080/green/job/libcxx_master_cmake/4784/testReport/junit/libc++/std_experimental_filesystem_fs_op_funcs_fs_op_last_write_time/last_write_time_pass_cpp/" target="_blank">http://lab.llvm.org:8080/green/job/libcxx_master_cmake/4784/testReport/junit/libc++/std_experimental_filesystem_fs_op_funcs_fs_op_last_write_time/last_write_time_pass_cpp/</a><br></div><div><br></div><div><div>Compiled With: ['/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++', '-o', '/Users/buildslave/jenkins/sharedspace/libcxx/build/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/Output/last_write_time.pass.cpp.o', '-x', 'c++', '/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp', '-c', '-v', '-arch', 'x86_64', '-mmacosx-version-min=10.13', '-D_LIBCPP_DISABLE_AVAILABILITY', '-ftemplate-depth=270', '-Werror=thread-safety', '-std=c++11', '-include', '/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/support/nasty_macros.hpp', '-nostdinc++', '-I/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/include', '-I/Users/buildslave/jenkins/sharedspace/libcxx/build/include/c++build', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk', '-I/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/support', '-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/Inputs/static_test_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="/Users/buildslave/jenkins/sharedspace/libcxx/build/test/filesystem/Output/dynamic_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="/usr/local/opt/python@2/bin/python2.7 /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/support/filesystem_dynamic_test_helper.py"', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wno-aligned-allocation-unavailable', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-Wno-conversion', '-Wno-unused-local-typedef', '-c', '&&', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++', '-o', '/Users/buildslave/jenkins/sharedspace/libcxx/build/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/Output/last_write_time.pass.cpp.exe', '/Users/buildslave/jenkins/sharedspace/libcxx/build/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/Output/last_write_time.pass.cpp.o', '-v', '-arch', 'x86_64', '-mmacosx-version-min=10.13', '-D_LIBCPP_DISABLE_AVAILABILITY', '-ftemplate-depth=270', '-L/Users/buildslave/jenkins/sharedspace/libcxx/build/lib', '-Wl,-rpath,/Users/buildslave/jenkins/sharedspace/libcxx/build/lib', '-nodefaultlibs', '-lc++experimental', '-lc++', '-lSystem']</div><div>Command: ['/Users/buildslave/jenkins/sharedspace/libcxx/build/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/Output/last_write_time.pass.cpp.exe']</div><div>Exit Code: 1</div><div>Standard Error:</div><div>--</div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In set_last_write_time_dynamic_env_test():451 Assertion TEST_CHECK(CompareTime(got_time, TC.new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In last_write_time_symlink_test():477 Assertion TEST_CHECK(got_time == new_time) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>In last_write_time_symlink_test():479 Assertion TEST_CHECK(CompareTime(LastWriteTime(file), new_time)) failed.</div><div> in file: /Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp</div><div> </div><div>Summary for testsuite last_write_time_test_suite:</div><div> 7 of 9 test cases passed.</div><div> 78 of 88 assertions passed.</div><div> 0 unsupported test cases.</div><div>--</div><div><br></div><div>Compiled test failed unexpectedly!</div></div><div><br></div><div>Thanks,</div><div>Alex</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2018 at 17:00, Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sure! Fixed it up in r337984.</div><div class="gmail_extra"><br><div class="gmail_quote"><span>On 25 July 2018 at 15:03, Eric Fiselier <span dir="ltr"><<a href="mailto:eric@efcs.ca" target="_blank">eric@efcs.ca</a>></span> wrote:<br></span><div><div class="m_6747764441411225383m_-5557678886675019082m_3629139256100849010m_-6285619442336665827m_624462420802478192h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Wed, Jul 25, 2018 at 3:39 PM Alex L <<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Looks like this works:<div><br></div><div><div>+++ b/src/experimental/filesystem/filesystem_common.h</div><div>@@ -393,7 +393,7 @@ bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,</div><div> error_code& ec) {</div><div> #if !defined(_LIBCPP_USE_UTIMENSAT)</div><div> using namespace chrono;</div><div>- auto Convert = [](long nsec) {</div><div>+ auto Convert = [](long nsec) -> decltype(std::declval<::timeval>().tv_usec) {</div><div> return duration_cast<microseconds>(nanoseconds(nsec)).count();</div><div> };</div><div> struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)},</div></div><div><br></div><div>I will commit this fix in a couple of minutes.</div></div></blockquote><div><br></div></span><div>I think I would prefer an explicit cast to an implicit one since the narrowing is intended, and should be safe.</div><div><br></div><div>Maybe:</div><div><br></div><div>auto Convert [](long nsec) { </div><div> using int_type = decltype(::timeval::tv_usec);</div><div> auto dur = duration_cast<microseconds>(nanoseconds(nsec)).count();</div><div> return static_cast<int_type>(dur);</div><div>};</div><div><br></div><div>?</div><div><div class="m_6747764441411225383m_-5557678886675019082m_3629139256100849010m_-6285619442336665827m_624462420802478192m_-7273343445799591636h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2018 at 14:27, Eric Fiselier <span dir="ltr"><<a href="mailto:eric@efcs.ca" target="_blank">eric@efcs.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Thanks. let me know if you want me to take over </div><div class="m_6747764441411225383m_-5557678886675019082m_3629139256100849010m_-6285619442336665827m_624462420802478192m_-7273343445799591636m_8166487320056533479m_-6165504667961413298HOEnZb"><div class="m_6747764441411225383m_-5557678886675019082m_3629139256100849010m_-6285619442336665827m_624462420802478192m_-7273343445799591636m_8166487320056533479m_-6165504667961413298h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 25, 2018, 3:22 PM Alex L, <<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 25 July 2018 at 13:51, Eric Fiselier via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" rel="noreferrer" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Author: ericwf<br>
Date: Wed Jul 25 13:51:49 2018<br>
New Revision: 337960<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=337960&view=rev" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=337960&view=rev</a><br>
Log:<br>
[libc++] Use __int128_t to represent file_time_type.<br>
<br>
Summary:<br>
The ``file_time_type`` time point is used to represent the write times for files.<br>
Its job is to act as part of a C++ wrapper for less ideal system interfaces. The<br>
underlying filesystem uses the ``timespec`` struct for the same purpose.<br>
<br>
However, the initial implementation of ``file_time_type`` could not represent<br>
either the range or resolution of ``timespec``, making it unsuitable. Fixing<br>
this requires an implementation which uses more than 64 bits to store the<br>
time point.<br>
<br>
I primarily considered two solutions: Using ``__int128_t`` and using a<br>
arithmetic emulation of ``timespec``. Each has its pros and cons, and both<br>
come with more than one complication.<br>
<br>
However, after a lot of consideration, I decided on using `__int128_t`. This patch implements that change.<br>
<br>
Please see the [FileTimeType Design Document](<a href="http://libcxx.llvm.org/docs/DesignDocs/FileTimeType.html" rel="noreferrer noreferrer" target="_blank">http://libcxx.llvm.org/docs/DesignDocs/FileTimeType.html</a>) for more information.<br>
<br>
Reviewers: mclow.lists, ldionne, joerg, arthur.j.odwyer, EricWF<br>
<br>
Reviewed By: EricWF<br>
<br>
Subscribers: christof, K-ballo, cfe-commits, BillyONeal<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D49774" rel="noreferrer noreferrer" target="_blank">https://reviews.llvm.org/D49774</a><br>
<br>
Added:<br>
libcxx/trunk/src/include/apple_availability.h<br>
Modified:<br>
libcxx/trunk/include/experimental/filesystem<br>
libcxx/trunk/src/chrono.cpp<br>
libcxx/trunk/src/experimental/filesystem/filesystem_common.h<br>
libcxx/trunk/src/experimental/filesystem/operations.cpp<br>
libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp<br>
libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp<br>
libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp<br>
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp<br>
<br>
Modified: libcxx/trunk/include/experimental/filesystem<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/include/experimental/filesystem (original)<br>
+++ libcxx/trunk/include/experimental/filesystem Wed Jul 25 13:51:49 2018<br>
@@ -260,7 +260,37 @@ _LIBCPP_PUSH_MACROS<br>
<br>
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM<br>
<br>
-typedef chrono::time_point<std::chrono::system_clock> file_time_type;<br>
+struct _FilesystemClock {<br>
+#if !defined(_LIBCPP_HAS_NO_INT128)<br>
+ typedef __int128_t rep;<br>
+ typedef nano period;<br>
+#else<br>
+ typedef long long rep;<br>
+ typedef nano period;<br>
+#endif<br>
+<br>
+ typedef chrono::duration<rep, period> duration;<br>
+ typedef chrono::time_point<_FilesystemClock> time_point;<br>
+<br>
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;<br>
+<br>
+ _LIBCPP_FUNC_VIS static time_point now() noexcept;<br>
+<br>
+ _LIBCPP_INLINE_VISIBILITY<br>
+ static time_t to_time_t(const time_point& __t) noexcept {<br>
+ typedef chrono::duration<rep> __secs;<br>
+ return time_t(<br>
+ chrono::duration_cast<__secs>(__t.time_since_epoch()).count());<br>
+ }<br>
+<br>
+ _LIBCPP_INLINE_VISIBILITY<br>
+ static time_point from_time_t(time_t __t) noexcept {<br>
+ typedef chrono::duration<rep> __secs;<br>
+ return time_point(__secs(__t));<br>
+ }<br>
+};<br>
+<br>
+typedef chrono::time_point<_FilesystemClock> file_time_type;<br>
<br>
struct _LIBCPP_TYPE_VIS space_info<br>
{<br>
<br>
Modified: libcxx/trunk/src/chrono.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/chrono.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/chrono.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/src/chrono.cpp (original)<br>
+++ libcxx/trunk/src/chrono.cpp Wed Jul 25 13:51:49 2018<br>
@@ -11,27 +11,10 @@<br>
#include "cerrno" // errno<br>
#include "system_error" // __throw_system_error<br>
#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME<br>
+#include "include/apple_availability.h"<br>
<br>
-#if (__APPLE__)<br>
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200<br>
-#define _LIBCXX_USE_CLOCK_GETTIME<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 100000<br>
-#define _LIBCXX_USE_CLOCK_GETTIME<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 100000<br>
-#define _LIBCXX_USE_CLOCK_GETTIME<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 30000<br>
-#define _LIBCXX_USE_CLOCK_GETTIME<br>
-#endif<br>
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__<br>
-#else<br>
-#define _LIBCXX_USE_CLOCK_GETTIME<br>
+#if !defined(__APPLE__)<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
#endif // __APPLE__<br>
<br>
#if defined(_LIBCPP_WIN32API)<br>
@@ -42,7 +25,7 @@<br>
#include <winapifamily.h><br>
#endif<br>
#else<br>
-#if !defined(CLOCK_REALTIME) || !defined(_LIBCXX_USE_CLOCK_GETTIME)<br>
+#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)<br>
#include <sys/time.h> // for gettimeofday and timeval<br>
#endif // !defined(CLOCK_REALTIME)<br>
#endif // defined(_LIBCPP_WIN32API)<br>
@@ -92,16 +75,16 @@ system_clock::now() _NOEXCEPT<br>
static_cast<__int64>(ft.dwLowDateTime)};<br>
return time_point(duration_cast<duration>(d - nt_to_unix_epoch));<br>
#else<br>
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)<br>
- struct timespec tp;<br>
- if (0 != clock_gettime(CLOCK_REALTIME, &tp))<br>
- __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");<br>
- return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));<br>
+#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)<br>
+ struct timespec tp;<br>
+ if (0 != clock_gettime(CLOCK_REALTIME, &tp))<br>
+ __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");<br>
+ return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));<br>
#else<br>
timeval tv;<br>
gettimeofday(&tv, 0);<br>
return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));<br>
-#endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME<br>
+#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME<br>
#endif<br>
}<br>
<br>
@@ -129,7 +112,7 @@ const bool steady_clock::is_steady;<br>
#if defined(__APPLE__)<br>
<br>
// Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW<br>
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)<br>
+#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)<br>
steady_clock::time_point<br>
steady_clock::now() _NOEXCEPT<br>
{<br>
@@ -191,7 +174,7 @@ steady_clock::now() _NOEXCEPT<br>
static FP fp = init_steady_clock();<br>
return time_point(duration(fp()));<br>
}<br>
-#endif // defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)<br>
+#endif // defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)<br>
<br>
#elif defined(_LIBCPP_WIN32API)<br>
<br>
<br>
Modified: libcxx/trunk/src/experimental/filesystem/filesystem_common.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/filesystem_common.h?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/filesystem_common.h?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/src/experimental/filesystem/filesystem_common.h (original)<br>
+++ libcxx/trunk/src/experimental/filesystem/filesystem_common.h Wed Jul 25 13:51:49 2018<br>
@@ -23,33 +23,17 @@<br>
<br>
#include <experimental/filesystem><br>
<br>
-#if (__APPLE__)<br>
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101300<br>
-#define _LIBCXX_USE_UTIMENSAT<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 110000<br>
-#define _LIBCXX_USE_UTIMENSAT<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 110000<br>
-#define _LIBCXX_USE_UTIMENSAT<br>
-#endif<br>
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)<br>
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 40000<br>
-#define _LIBCXX_USE_UTIMENSAT<br>
-#endif<br>
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__<br>
-#else<br>
+#include "../../include/apple_availability.h"<br>
+<br>
+#if !defined(__APPLE__)<br>
// We can use the presence of UTIME_OMIT to detect platforms that provide<br>
// utimensat.<br>
#if defined(UTIME_OMIT)<br>
-#define _LIBCXX_USE_UTIMENSAT<br>
+#define _LIBCPP_USE_UTIMENSAT<br>
+#endif<br>
#endif<br>
-#endif // __APPLE__<br>
<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
+#if !defined(_LIBCPP_USE_UTIMENSAT)<br>
#include <sys/time.h> // for ::utimes as used in __last_write_time<br>
#endif<br>
<br>
@@ -212,76 +196,119 @@ private:<br>
ErrorHandler& operator=(ErrorHandler const&) = delete;<br>
};<br>
<br>
-namespace time_util {<br>
+using chrono::duration;<br>
+using chrono::duration_cast;<br>
<br>
-using namespace chrono;<br>
+using TimeSpec = struct ::timespec;<br>
+using StatT = struct ::stat;<br>
<br>
-template <class FileTimeT,<br>
+template <class FileTimeT, class TimeT,<br>
bool IsFloat = is_floating_point<typename FileTimeT::rep>::value><br>
-struct fs_time_util_base {<br>
- static constexpr seconds::rep max_seconds =<br>
- duration_cast<seconds>(FileTimeT::duration::max()).count();<br>
-<br>
- static constexpr nanoseconds::rep max_nsec =<br>
- duration_cast<nanoseconds>(FileTimeT::duration::max() -<br>
- seconds(max_seconds))<br>
+struct time_util_base {<br>
+ using rep = typename FileTimeT::rep;<br>
+ using fs_duration = typename FileTimeT::duration;<br>
+ using fs_seconds = duration<rep>;<br>
+ using fs_nanoseconds = duration<rep, nano>;<br>
+ using fs_microseconds = duration<rep, micro>;<br>
+<br>
+ static constexpr rep max_seconds =<br>
+ duration_cast<fs_seconds>(FileTimeT::duration::max()).count();<br>
+<br>
+ static constexpr rep max_nsec =<br>
+ duration_cast<fs_nanoseconds>(FileTimeT::duration::max() -<br>
+ fs_seconds(max_seconds))<br>
.count();<br>
<br>
- static constexpr seconds::rep min_seconds =<br>
- duration_cast<seconds>(FileTimeT::duration::min()).count();<br>
+ static constexpr rep min_seconds =<br>
+ duration_cast<fs_seconds>(FileTimeT::duration::min()).count();<br>
<br>
- static constexpr nanoseconds::rep min_nsec_timespec =<br>
- duration_cast<nanoseconds>(<br>
- (FileTimeT::duration::min() - seconds(min_seconds)) + seconds(1))<br>
+ static constexpr rep min_nsec_timespec =<br>
+ duration_cast<fs_nanoseconds>(<br>
+ (FileTimeT::duration::min() - fs_seconds(min_seconds)) +<br>
+ fs_seconds(1))<br>
.count();<br>
<br>
+private:<br>
+#if _LIBCPP_STD_VER > 11<br>
+ static constexpr fs_duration get_min_nsecs() {<br>
+ return duration_cast<fs_duration>(<br>
+ fs_nanoseconds(min_nsec_timespec) -<br>
+ duration_cast<fs_nanoseconds>(fs_seconds(1)));<br>
+ }<br>
// Static assert that these values properly round trip.<br>
- static_assert((seconds(min_seconds) +<br>
- duration_cast<microseconds>(nanoseconds(min_nsec_timespec))) -<br>
- duration_cast<microseconds>(seconds(1)) ==<br>
+ static_assert(fs_seconds(min_seconds) + get_min_nsecs() ==<br>
FileTimeT::duration::min(),<br>
- "");<br>
+ "value doesn't roundtrip");<br>
+<br>
+ static constexpr bool check_range() {<br>
+ // This kinda sucks, but it's what happens when we don't have __int128_t.<br>
+ if (sizeof(TimeT) == sizeof(rep)) {<br>
+ typedef duration<long long, ratio<3600 * 24 * 365> > Years;<br>
+ return duration_cast<Years>(fs_seconds(max_seconds)) > Years(250) &&<br>
+ duration_cast<Years>(fs_seconds(min_seconds)) < Years(-250);<br>
+ }<br>
+ return max_seconds >= numeric_limits<TimeT>::max() &&<br>
+ min_seconds <= numeric_limits<TimeT>::min();<br>
+ }<br>
+ static_assert(check_range(), "the representable range is unacceptable small");<br>
+#endif<br>
};<br>
<br>
-template <class FileTimeT><br>
-struct fs_time_util_base<FileTimeT, true> {<br>
- static const long long max_seconds;<br>
- static const long long max_nsec;<br>
- static const long long min_seconds;<br>
- static const long long min_nsec_timespec;<br>
+template <class FileTimeT, class TimeT><br>
+struct time_util_base<FileTimeT, TimeT, true> {<br>
+ using rep = typename FileTimeT::rep;<br>
+ using fs_duration = typename FileTimeT::duration;<br>
+ using fs_seconds = duration<rep>;<br>
+ using fs_nanoseconds = duration<rep, nano>;<br>
+ using fs_microseconds = duration<rep, micro>;<br>
+<br>
+ static const rep max_seconds;<br>
+ static const rep max_nsec;<br>
+ static const rep min_seconds;<br>
+ static const rep min_nsec_timespec;<br>
};<br>
<br>
-template <class FileTimeT><br>
-const long long fs_time_util_base<FileTimeT, true>::max_seconds =<br>
- duration_cast<seconds>(FileTimeT::duration::max()).count();<br>
-<br>
-template <class FileTimeT><br>
-const long long fs_time_util_base<FileTimeT, true>::max_nsec =<br>
- duration_cast<nanoseconds>(FileTimeT::duration::max() -<br>
- seconds(max_seconds))<br>
+template <class FileTimeT, class TimeT><br>
+const typename FileTimeT::rep<br>
+ time_util_base<FileTimeT, TimeT, true>::max_seconds =<br>
+ duration_cast<fs_seconds>(FileTimeT::duration::max()).count();<br>
+<br>
+template <class FileTimeT, class TimeT><br>
+const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::max_nsec =<br>
+ duration_cast<fs_nanoseconds>(FileTimeT::duration::max() -<br>
+ fs_seconds(max_seconds))<br>
.count();<br>
<br>
-template <class FileTimeT><br>
-const long long fs_time_util_base<FileTimeT, true>::min_seconds =<br>
- duration_cast<seconds>(FileTimeT::duration::min()).count();<br>
-<br>
-template <class FileTimeT><br>
-const long long fs_time_util_base<FileTimeT, true>::min_nsec_timespec =<br>
- duration_cast<nanoseconds>(<br>
- (FileTimeT::duration::min() - seconds(min_seconds)) + seconds(1))<br>
- .count();<br>
+template <class FileTimeT, class TimeT><br>
+const typename FileTimeT::rep<br>
+ time_util_base<FileTimeT, TimeT, true>::min_seconds =<br>
+ duration_cast<fs_seconds>(FileTimeT::duration::min()).count();<br>
+<br>
+template <class FileTimeT, class TimeT><br>
+const typename FileTimeT::rep<br>
+ time_util_base<FileTimeT, TimeT, true>::min_nsec_timespec =<br>
+ duration_cast<fs_nanoseconds>((FileTimeT::duration::min() -<br>
+ fs_seconds(min_seconds)) +<br>
+ fs_seconds(1))<br>
+ .count();<br>
<br>
template <class FileTimeT, class TimeT, class TimeSpecT><br>
-struct fs_time_util : fs_time_util_base<FileTimeT> {<br>
- using Base = fs_time_util_base<FileTimeT>;<br>
+struct time_util : time_util_base<FileTimeT, TimeT> {<br>
+ using Base = time_util_base<FileTimeT, TimeT>;<br>
using Base::max_nsec;<br>
using Base::max_seconds;<br>
using Base::min_nsec_timespec;<br>
using Base::min_seconds;<br>
<br>
+ using typename Base::fs_duration;<br>
+ using typename Base::fs_microseconds;<br>
+ using typename Base::fs_nanoseconds;<br>
+ using typename Base::fs_seconds;<br>
+<br>
public:<br>
template <class CType, class ChronoType><br>
- static bool checked_set(CType* out, ChronoType time) {<br>
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool checked_set(CType* out,<br>
+ ChronoType time) {<br>
using Lim = numeric_limits<CType>;<br>
if (time > Lim::max() || time < Lim::min())<br>
return false;<br>
@@ -291,21 +318,21 @@ public:<br>
<br>
static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(TimeSpecT tm) {<br>
if (tm.tv_sec >= 0) {<br>
- return (tm.tv_sec < max_seconds) ||<br>
+ return tm.tv_sec < max_seconds ||<br>
(tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec);<br>
} else if (tm.tv_sec == (min_seconds - 1)) {<br>
return tm.tv_nsec >= min_nsec_timespec;<br>
} else {<br>
- return (tm.tv_sec >= min_seconds);<br>
+ return tm.tv_sec >= min_seconds;<br>
}<br>
}<br>
<br>
static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(FileTimeT tm) {<br>
- auto secs = duration_cast<seconds>(tm.time_since_epoch());<br>
- auto nsecs = duration_cast<nanoseconds>(tm.time_since_epoch() - secs);<br>
+ auto secs = duration_cast<fs_seconds>(tm.time_since_epoch());<br>
+ auto nsecs = duration_cast<fs_nanoseconds>(tm.time_since_epoch() - secs);<br>
if (nsecs.count() < 0) {<br>
- secs = secs + seconds(1);<br>
- nsecs = nsecs + seconds(1);<br>
+ secs = secs + fs_seconds(1);<br>
+ nsecs = nsecs + fs_seconds(1);<br>
}<br>
using TLim = numeric_limits<TimeT>;<br>
if (secs.count() >= 0)<br>
@@ -314,49 +341,45 @@ public:<br>
}<br>
<br>
static _LIBCPP_CONSTEXPR_AFTER_CXX11 FileTimeT<br>
- convert_timespec(TimeSpecT tm) {<br>
- auto adj_msec = duration_cast<microseconds>(nanoseconds(tm.tv_nsec));<br>
- if (tm.tv_sec >= 0) {<br>
- auto Dur = seconds(tm.tv_sec) + microseconds(adj_msec);<br>
- return FileTimeT(Dur);<br>
- } else if (duration_cast<microseconds>(nanoseconds(tm.tv_nsec)).count() ==<br>
- 0) {<br>
- return FileTimeT(seconds(tm.tv_sec));<br>
+ convert_from_timespec(TimeSpecT tm) {<br>
+ if (tm.tv_sec >= 0 || tm.tv_nsec == 0) {<br>
+ return FileTimeT(fs_seconds(tm.tv_sec) +<br>
+ duration_cast<fs_duration>(fs_nanoseconds(tm.tv_nsec)));<br>
} else { // tm.tv_sec < 0<br>
- auto adj_subsec =<br>
- duration_cast<microseconds>(seconds(1) - nanoseconds(tm.tv_nsec));<br>
- auto Dur = seconds(tm.tv_sec + 1) - adj_subsec;<br>
+ auto adj_subsec = duration_cast<fs_duration>(fs_seconds(1) -<br>
+ fs_nanoseconds(tm.tv_nsec));<br>
+ auto Dur = fs_seconds(tm.tv_sec + 1) - adj_subsec;<br>
return FileTimeT(Dur);<br>
}<br>
}<br>
<br>
- template <class SubSecDurT, class SubSecT><br>
- static bool set_times_checked(TimeT* sec_out, SubSecT* subsec_out,<br>
- FileTimeT tp) {<br>
+ template <class SubSecT><br>
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool<br>
+ set_times_checked(TimeT* sec_out, SubSecT* subsec_out, FileTimeT tp) {<br>
auto dur = tp.time_since_epoch();<br>
- auto sec_dur = duration_cast<seconds>(dur);<br>
- auto subsec_dur = duration_cast<SubSecDurT>(dur - sec_dur);<br>
+ auto sec_dur = duration_cast<fs_seconds>(dur);<br>
+ auto subsec_dur = duration_cast<fs_nanoseconds>(dur - sec_dur);<br>
// The tv_nsec and tv_usec fields must not be negative so adjust accordingly<br>
if (subsec_dur.count() < 0) {<br>
if (sec_dur.count() > min_seconds) {<br>
- sec_dur -= seconds(1);<br>
- subsec_dur += seconds(1);<br>
+ sec_dur -= fs_seconds(1);<br>
+ subsec_dur += fs_seconds(1);<br>
} else {<br>
- subsec_dur = SubSecDurT::zero();<br>
+ subsec_dur = fs_nanoseconds::zero();<br>
}<br>
}<br>
return checked_set(sec_out, sec_dur.count()) &&<br>
checked_set(subsec_out, subsec_dur.count());<br>
}<br>
+ static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool convert_to_timespec(TimeSpecT& dest,<br>
+ FileTimeT tp) {<br>
+ if (!is_representable(tp))<br>
+ return false;<br>
+ return set_times_checked(&dest.tv_sec, &dest.tv_nsec, tp);<br>
+ }<br>
};<br>
<br>
-} // namespace time_util<br>
-<br>
-<br>
-using TimeSpec = struct ::timespec;<br>
-using StatT = struct ::stat;<br>
-<br>
-using FSTime = time_util::fs_time_util<file_time_type, time_t, struct timespec>;<br>
+using fs_time = time_util<file_time_type, time_t, TimeSpec>;<br>
<br>
#if defined(__APPLE__)<br>
TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }<br>
@@ -366,20 +389,18 @@ TimeSpec extract_mtime(StatT const& st)<br>
TimeSpec extract_atime(StatT const& st) { return st.st_atim; }<br>
#endif<br>
<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
-using TimeStruct = struct ::timeval;<br>
-using TimeStructArray = TimeStruct[2];<br>
-#else<br>
-using TimeStruct = TimeSpec;<br>
-using TimeStructArray = TimeStruct[2];<br>
-#endif<br>
-<br>
-bool SetFileTimes(const path& p, TimeStructArray const& TS,<br>
- error_code& ec) {<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
- if (::utimes(p.c_str(), TS) == -1)<br>
+bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,<br>
+ error_code& ec) {<br>
+#if !defined(_LIBCPP_USE_UTIMENSAT)<br>
+ using namespace chrono;<br>
+ auto Convert = [](long nsec) {<br>
+ return duration_cast<microseconds>(nanoseconds(nsec)).count();<br>
+ };<br>
+ struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)},<br>
+ {TS[1].tv_sec, Convert(TS[1].tv_nsec)}};<br></blockquote><div><br></div><div>This causes the '-Wc++11-narrowing' warning on Darwin:</div><div><br></div><div><span style="color:rgb(51,51,51);font-family:monospace;font-size:15px;white-space:pre-wrap">filesystem_common.h:399:53: error: non-constant-expression cannot be narrowed from type 'long long' to '__darwin_suseconds_t' (aka 'int') in initializer list [-Wc++11-narrowing]
struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)},
^~~~~~~~~~~~~~~~~~~~~~</span><br></div><div><font color="#333333" face="monospace"><span style="font-size:15px;white-space:pre-wrap">I'll work on a fix commit.</span></font></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
+ if (::utimes(p.c_str(), ConvertedTS) == -1)<br>
#else<br>
- if (::utimensat(AT_FDCWD, p.c_str(), TS, 0) == -1)<br>
+ if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1)<br>
#endif<br>
{<br>
ec = capture_errno();<br>
@@ -388,25 +409,9 @@ bool SetFileTimes(const path& p, TimeStr<br>
return false;<br>
}<br>
<br>
-void SetTimeStructTo(TimeStruct& TS, TimeSpec ToTS) {<br>
- using namespace chrono;<br>
- TS.tv_sec = ToTS.tv_sec;<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
- TS.tv_usec = duration_cast<microseconds>(nanoseconds(ToTS.tv_nsec)).count();<br>
-#else<br>
- TS.tv_nsec = ToTS.tv_nsec;<br>
-#endif<br>
-}<br>
-<br>
-bool SetTimeStructTo(TimeStruct& TS, file_time_type NewTime) {<br>
- using namespace chrono;<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
- return !FSTime::set_times_checked<microseconds>(&TS.tv_sec, &TS.tv_usec,<br>
- NewTime);<br>
-#else<br>
- return !FSTime::set_times_checked<nanoseconds>(&TS.tv_sec, &TS.tv_nsec,<br>
- NewTime);<br>
-#endif<br>
+bool set_time_spec_to(TimeSpec& TS, file_time_type NewTime) {<br>
+ return !fs_time::set_times_checked(<br>
+ &TS.tv_sec, &TS.tv_nsec, NewTime);<br>
}<br>
<br>
} // namespace<br>
<br>
Modified: libcxx/trunk/src/experimental/filesystem/operations.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/src/experimental/filesystem/operations.cpp (original)<br>
+++ libcxx/trunk/src/experimental/filesystem/operations.cpp Wed Jul 25 13:51:49 2018<br>
@@ -23,6 +23,7 @@<br>
#include <unistd.h><br>
#include <sys/stat.h><br>
#include <sys/statvfs.h><br>
+#include <time.h><br>
#include <fcntl.h> /* values for fchmodat */<br>
<br>
#if defined(__linux__)<br>
@@ -36,6 +37,14 @@<br>
# define _LIBCPP_USE_COPYFILE<br>
#endif<br>
<br>
+#if !defined(__APPLE__)<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
+#endif<br>
+<br>
+#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)<br>
+#include <sys/time.h> // for gettimeofday and timeval<br>
+#endif // !defined(CLOCK_REALTIME)<br>
+<br>
#if defined(_LIBCPP_COMPILER_GCC)<br>
#if _GNUC_VER < 500<br>
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"<br>
@@ -44,9 +53,6 @@<br>
<br>
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM<br>
<br>
-filesystem_error::~filesystem_error() {}<br>
-<br>
-<br>
namespace { namespace parser<br>
{<br>
<br>
@@ -355,7 +361,7 @@ private:<br>
explicit FileDescriptor(const path* p, int fd = -1) : name(*p), fd(fd) {}<br>
};<br>
<br>
-perms posix_get_perms(const struct ::stat& st) noexcept {<br>
+perms posix_get_perms(const StatT& st) noexcept {<br>
return static_cast<perms>(st.st_mode) & perms::mask;<br>
}<br>
<br>
@@ -364,8 +370,7 @@ perms posix_get_perms(const struct ::sta<br>
}<br>
<br>
file_status create_file_status(error_code& m_ec, path const& p,<br>
- const struct ::stat& path_stat,<br>
- error_code* ec) {<br>
+ const StatT& path_stat, error_code* ec) {<br>
if (ec)<br>
*ec = m_ec;<br>
if (m_ec && (m_ec.value() == ENOENT || m_ec.value() == ENOTDIR)) {<br>
@@ -400,8 +405,7 @@ file_status create_file_status(error_cod<br>
return fs_tmp;<br>
}<br>
<br>
-file_status posix_stat(path const& p, struct ::stat& path_stat,<br>
- error_code* ec) {<br>
+file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) {<br>
error_code m_ec;<br>
if (::stat(p.c_str(), &path_stat) == -1)<br>
m_ec = detail::capture_errno();<br>
@@ -409,12 +413,11 @@ file_status posix_stat(path const& p, st<br>
}<br>
<br>
file_status posix_stat(path const& p, error_code* ec) {<br>
- struct ::stat path_stat;<br>
+ StatT path_stat;<br>
return posix_stat(p, path_stat, ec);<br>
}<br>
<br>
-file_status posix_lstat(path const& p, struct ::stat& path_stat,<br>
- error_code* ec) {<br>
+file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) {<br>
error_code m_ec;<br>
if (::lstat(p.c_str(), &path_stat) == -1)<br>
m_ec = detail::capture_errno();<br>
@@ -422,7 +425,7 @@ file_status posix_lstat(path const& p, s<br>
}<br>
<br>
file_status posix_lstat(path const& p, error_code* ec) {<br>
- struct ::stat path_stat;<br>
+ StatT path_stat;<br>
return posix_lstat(p, path_stat, ec);<br>
}<br>
<br>
@@ -464,10 +467,32 @@ file_status FileDescriptor::refresh_stat<br>
using detail::capture_errno;<br>
using detail::ErrorHandler;<br>
using detail::StatT;<br>
+using detail::TimeSpec;<br>
using parser::createView;<br>
using parser::PathParser;<br>
using parser::string_view_t;<br>
<br>
+const bool _FilesystemClock::is_steady;<br>
+<br>
+_FilesystemClock::time_point _FilesystemClock::now() noexcept {<br>
+ typedef chrono::duration<rep> __secs;<br>
+#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)<br>
+ typedef chrono::duration<rep, nano> __nsecs;<br>
+ struct timespec tp;<br>
+ if (0 != clock_gettime(CLOCK_REALTIME, &tp))<br>
+ __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");<br>
+ return time_point(__secs(tp.tv_sec) +<br>
+ chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));<br>
+#else<br>
+ typedef chrono::duration<rep, micro> __microsecs;<br>
+ timeval tv;<br>
+ gettimeofday(&tv, 0);<br>
+ return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec));<br>
+#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME<br>
+}<br>
+<br>
+filesystem_error::~filesystem_error() {}<br>
+<br>
void filesystem_error::__create_what(int __num_paths) {<br>
const char* derived_what = system_error::what();<br>
__storage_->__what_ = [&]() -> string {<br>
@@ -525,14 +550,14 @@ void __copy(const path& from, const path<br>
const bool sym_status2 = bool(options & copy_options::copy_symlinks);<br>
<br>
error_code m_ec1;<br>
- struct ::stat f_st = {};<br>
+ StatT f_st = {};<br>
const file_status f = sym_status || sym_status2<br>
? detail::posix_lstat(from, f_st, &m_ec1)<br>
: detail::posix_stat(from, f_st, &m_ec1);<br>
if (m_ec1)<br>
return err.report(m_ec1);<br>
<br>
- struct ::stat t_st = {};<br>
+ StatT t_st = {};<br>
const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec1)<br>
: detail::posix_stat(to, t_st, &m_ec1);<br>
<br>
@@ -916,7 +941,7 @@ uintmax_t __file_size(const path& p, err<br>
ErrorHandler<uintmax_t> err("file_size", ec, &p);<br>
<br>
error_code m_ec;<br>
- struct ::stat st;<br>
+ StatT st;<br>
file_status fst = detail::posix_stat(p, st, &m_ec);<br>
if (!exists(fst) || !is_regular_file(fst)) {<br>
errc error_kind =<br>
@@ -966,14 +991,14 @@ bool __fs_is_empty(const path& p, error_<br>
<br>
static file_time_type __extract_last_write_time(const path& p, const StatT& st,<br>
error_code* ec) {<br>
- using detail::FSTime;<br>
+ using detail::fs_time;<br>
ErrorHandler<file_time_type> err("last_write_time", ec, &p);<br>
<br>
auto ts = detail::extract_mtime(st);<br>
- if (!FSTime::is_representable(ts))<br>
+ if (!fs_time::is_representable(ts))<br>
return err.report(errc::value_too_large);<br>
<br>
- return FSTime::convert_timespec(ts);<br>
+ return fs_time::convert_from_timespec(ts);<br>
}<br>
<br>
file_time_type __last_write_time(const path& p, error_code *ec)<br>
@@ -992,30 +1017,27 @@ file_time_type __last_write_time(const p<br>
void __last_write_time(const path& p, file_time_type new_time,<br>
error_code *ec)<br>
{<br>
- using namespace chrono;<br>
- using namespace detail;<br>
-<br>
ErrorHandler<void> err("last_write_time", ec, &p);<br>
<br>
error_code m_ec;<br>
- TimeStructArray tbuf;<br>
-#if !defined(_LIBCXX_USE_UTIMENSAT)<br>
+ array<TimeSpec, 2> tbuf;<br>
+#if !defined(_LIBCPP_USE_UTIMENSAT)<br>
// This implementation has a race condition between determining the<br>
// last access time and attempting to set it to the same value using<br>
// ::utimes<br>
- struct ::stat st;<br>
+ StatT st;<br>
file_status fst = detail::posix_stat(p, st, &m_ec);<br>
- if (m_ec && !status_known(fst))<br>
+ if (m_ec)<br>
return err.report(m_ec);<br>
- SetTimeStructTo(tbuf[0], detail::extract_atime(st));<br>
+ tbuf[0] = detail::extract_atime(st);<br>
#else<br>
tbuf[0].tv_sec = 0;<br>
tbuf[0].tv_nsec = UTIME_OMIT;<br>
#endif<br>
- if (SetTimeStructTo(tbuf[1], new_time))<br>
- return err.report(errc::invalid_argument);<br>
+ if (detail::set_time_spec_to(tbuf[1], new_time))<br>
+ return err.report(errc::value_too_large);<br>
<br>
- SetFileTimes(p, tbuf, m_ec);<br>
+ detail::set_file_times(p, tbuf, m_ec);<br>
if (m_ec)<br>
return err.report(m_ec);<br>
}<br>
@@ -1591,7 +1613,7 @@ error_code directory_entry::__do_refresh<br>
__data_.__reset();<br>
error_code failure_ec;<br>
<br>
- struct ::stat full_st;<br>
+ StatT full_st;<br>
file_status st = detail::posix_lstat(__p_, full_st, &failure_ec);<br>
if (!status_known(st)) {<br>
__data_.__reset();<br>
<br>
Added: libcxx/trunk/src/include/apple_availability.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/apple_availability.h?rev=337960&view=auto" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/apple_availability.h?rev=337960&view=auto</a><br>
==============================================================================<br>
--- libcxx/trunk/src/include/apple_availability.h (added)<br>
+++ libcxx/trunk/src/include/apple_availability.h Wed Jul 25 13:51:49 2018<br>
@@ -0,0 +1,52 @@<br>
+//===------------------------ apple_availability.h ------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is dual licensed under the MIT and the University of Illinois Open<br>
+// Source Licenses. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+#ifndef _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H<br>
+#define _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H<br>
+<br>
+#if defined(__APPLE__)<br>
+<br>
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101300<br>
+#define _LIBCPP_USE_UTIMENSAT<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 110000<br>
+#define _LIBCPP_USE_UTIMENSAT<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 110000<br>
+#define _LIBCPP_USE_UTIMENSAT<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 40000<br>
+#define _LIBCPP_USE_UTIMENSAT<br>
+#endif<br>
+#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__<br>
+<br>
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 100000<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 100000<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
+#endif<br>
+#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)<br>
+#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 30000<br>
+#define _LIBCPP_USE_CLOCK_GETTIME<br>
+#endif<br>
+#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__<br>
+<br>
+#endif // __APPLE__<br>
+<br>
+#endif // _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H<br>
<br>
Modified: libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp (original)<br>
+++ libcxx/trunk/test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp Wed Jul 25 13:51:49 2018<br>
@@ -41,9 +41,7 @@ TEST_CASE(last_write_time_not_representa<br>
ToTime.tv_sec = std::numeric_limits<decltype(ToTime.tv_sec)>::max();<br>
ToTime.tv_nsec = duration_cast<nanoseconds>(seconds(1)).count() - 1;<br>
<br>
- TimeStructArray TS;<br>
- SetTimeStructTo(TS[0], ToTime);<br>
- SetTimeStructTo(TS[1], ToTime);<br>
+ std::array<TimeSpec, 2> TS = {ToTime, ToTime};<br>
<br>
file_time_type old_time = last_write_time(file);<br>
directory_entry ent(file);<br>
@@ -57,9 +55,7 @@ TEST_CASE(last_write_time_not_representa<br>
file_time_type rep_value;<br>
{<br>
std::error_code ec;<br>
- if (SetFileTimes(file, TS, ec)) {<br>
- TEST_REQUIRE(false && "unsupported");<br>
- }<br>
+ TEST_REQUIRE(!set_file_times(file, TS, ec));<br>
ec.clear();<br>
rep_value = last_write_time(file, ec);<br>
IsRepresentable = !bool(ec);<br>
@@ -82,7 +78,7 @@ TEST_CASE(last_write_time_not_representa<br>
<br>
ExceptionChecker CheckExcept(file, expected_err,<br>
"directory_entry::last_write_time");<br>
- TEST_CHECK_THROW_RESULT(fs::filesystem_error, CheckExcept,<br>
+ TEST_CHECK_THROW_RESULT(filesystem_error, CheckExcept,<br>
ent.last_write_time());<br>
<br>
} else {<br>
<br>
Modified: libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp (original)<br>
+++ libcxx/trunk/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp Wed Jul 25 13:51:49 2018<br>
@@ -25,15 +25,23 @@<br>
<br>
#include "filesystem_common.h"<br>
<br>
+#ifndef __SIZEOF_INT128__<br>
+#define TEST_HAS_NO_INT128_T<br>
+#endif<br>
+<br>
using namespace std::chrono;<br>
namespace fs = std::experimental::filesystem;<br>
using fs::file_time_type;<br>
-using fs::detail::time_util::fs_time_util;<br>
+using fs::detail::time_util;<br>
+<br>
+#ifdef TEST_HAS_NO_INT128_T<br>
+static_assert(sizeof(fs::file_time_type::rep) <= 8, "");<br>
+#endif<br>
<br>
-enum TestKind { TK_64Bit, TK_32Bit, TK_FloatingPoint };<br>
+enum TestKind { TK_128Bit, TK_64Bit, TK_32Bit, TK_FloatingPoint };<br>
<br>
-template <class FileTimeT, class TimeT, class TimeSpec><br>
-constexpr TestKind getTestKind() {<br>
+template <class TimeT><br>
+constexpr TestKind getTimeTTestKind() {<br>
if (sizeof(TimeT) == 8 && !std::is_floating_point<TimeT>::value)<br>
return TK_64Bit;<br>
else if (sizeof(TimeT) == 4 && !std::is_floating_point<TimeT>::value)<br>
@@ -43,17 +51,99 @@ constexpr TestKind getTestKind() {<br>
else<br>
assert(false && "test kind not supported");<br>
}<br>
+template <class FileTimeT><br>
+constexpr TestKind getFileTimeTestKind() {<br>
+ using Rep = typename FileTimeT::rep;<br>
+ if (std::is_floating_point<Rep>::value)<br>
+ return TK_FloatingPoint;<br>
+ if (sizeof(Rep) == 16)<br>
+ return TK_128Bit;<br>
+ if (sizeof(Rep) == 8)<br>
+ return TK_64Bit;<br>
+ assert(false && "test kind not supported");<br>
+}<br>
<br>
template <class FileTimeT, class TimeT, class TimeSpecT,<br>
- class Base = fs_time_util<FileTimeT, TimeT, TimeSpecT>,<br>
- TestKind = getTestKind<FileTimeT, TimeT, TimeSpecT>()><br>
-struct check_is_representable;<br>
+ class Base = time_util<FileTimeT, TimeT, TimeSpecT>,<br>
+ TestKind = getTimeTTestKind<TimeT>(),<br>
+ TestKind = getFileTimeTestKind<FileTimeT>()><br>
+struct test_case;<br>
<br>
template <class FileTimeT, class TimeT, class TimeSpecT, class Base><br>
-struct check_is_representable<FileTimeT, TimeT, TimeSpecT, Base, TK_64Bit><br>
+struct test_case<FileTimeT, TimeT, TimeSpecT, Base, TK_64Bit, TK_128Bit><br>
: public Base {<br>
<br>
- using Base::convert_timespec;<br>
+ using Base::convert_from_timespec;<br>
+ using Base::convert_to_timespec;<br>
+ using Base::is_representable;<br>
+ using Base::max_nsec;<br>
+ using Base::max_seconds;<br>
+ using Base::min_nsec_timespec;<br>
+ using Base::min_seconds;<br>
+<br>
+ static constexpr auto max_time_t = std::numeric_limits<TimeT>::max();<br>
+ static constexpr auto min_time_t = std::numeric_limits<TimeT>::min();<br>
+<br>
+ static constexpr bool test_timespec() {<br>
+ static_assert(is_representable(TimeSpecT{max_time_t, 0}), "");<br>
+ static_assert(is_representable(TimeSpecT{max_time_t, 999999999}), "");<br>
+ static_assert(is_representable(TimeSpecT{max_time_t, 1000000000}), "");<br>
+ static_assert(is_representable(TimeSpecT{max_time_t, max_nsec}), "");<br>
+<br>
+ static_assert(is_representable(TimeSpecT{min_time_t, 0}), "");<br>
+ static_assert(is_representable(TimeSpecT{min_time_t, 999999999}), "");<br>
+ static_assert(is_representable(TimeSpecT{min_time_t, 1000000000}), "");<br>
+ static_assert(is_representable(TimeSpecT{min_time_t, min_nsec_timespec}),<br>
+ "");<br>
+<br>
+ return true;<br>
+ }<br>
+<br>
+ static constexpr bool test_file_time_type() {<br>
+ // This kinda sucks. Oh well.<br>
+ static_assert(!Base::is_representable(FileTimeT::max()), "");<br>
+ static_assert(!Base::is_representable(FileTimeT::min()), "");<br>
+ return true;<br>
+ }<br>
+<br>
+ static constexpr bool check_round_trip(TimeSpecT orig) {<br>
+ TimeSpecT new_ts = {};<br>
+ FileTimeT out = convert_from_timespec(orig);<br>
+ assert(convert_to_timespec(new_ts, out));<br>
+ return new_ts.tv_sec == orig.tv_sec && new_ts.tv_nsec == orig.tv_nsec;<br>
+ }<br>
+<br>
+ static constexpr bool test_convert_timespec() {<br>
+ static_assert(check_round_trip({0, 0}), "");<br>
+ static_assert(check_round_trip({0, 1}), "");<br>
+ static_assert(check_round_trip({1, 1}), "");<br>
+ static_assert(check_round_trip({-1, 1}), "");<br>
+ static_assert(check_round_trip({max_time_t, max_nsec}), "");<br>
+ static_assert(check_round_trip({max_time_t, 123}), "");<br>
+ static_assert(check_round_trip({min_time_t, min_nsec_timespec}), "");<br>
+ static_assert(check_round_trip({min_time_t, 123}), "");<br>
+ return true;<br>
+ }<br>
+<br>
+ static bool test() {<br>
+ static_assert(test_timespec(), "");<br>
+ static_assert(test_file_time_type(), "");<br>
+ static_assert(test_convert_timespec(), "");<br>
+ return true;<br>
+ }<br>
+};<br>
+<br>
+template <class FileTimeT, class TimeT, class TimeSpecT, class Base><br>
+struct test_case<FileTimeT, TimeT, TimeSpecT, Base, TK_32Bit, TK_128Bit><br>
+ : public test_case<FileTimeT, TimeT, TimeSpecT, Base, TK_64Bit, TK_128Bit> {<br>
+<br>
+};<br>
+<br>
+template <class FileTimeT, class TimeT, class TimeSpecT, class Base><br>
+struct test_case<FileTimeT, TimeT, TimeSpecT, Base, TK_64Bit, TK_64Bit><br>
+ : public Base {<br>
+<br>
+ using Base::convert_from_timespec;<br>
using Base::is_representable;<br>
using Base::max_nsec;<br>
using Base::max_seconds;<br>
@@ -88,24 +178,25 @@ struct check_is_representable<FileTimeT,<br>
}<br>
<br>
static constexpr bool test_convert_timespec() {<br>
- static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec}) ==<br>
+ static_assert(convert_from_timespec(TimeSpecT{max_seconds, max_nsec}) ==<br>
FileTimeT::max(),<br>
"");<br>
- static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec - 1}) <<br>
+ static_assert(convert_from_timespec(TimeSpecT{max_seconds, max_nsec - 1}) <<br>
FileTimeT::max(),<br>
"");<br>
- static_assert(convert_timespec(TimeSpecT{max_seconds - 1, 999999999}) <<br>
+ static_assert(convert_from_timespec(TimeSpecT{max_seconds - 1, 999999999}) <<br>
FileTimeT::max(),<br>
"");<br>
- static_assert(convert_timespec(TimeSpecT{<br>
+ static_assert(convert_from_timespec(TimeSpecT{<br>
min_seconds - 1, min_nsec_timespec}) == FileTimeT::min(),<br>
"");<br>
- static_assert(<br>
- convert_timespec(TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}) ><br>
- FileTimeT::min(),<br>
- "");<br>
- static_assert(<br>
- convert_timespec(TimeSpecT{min_seconds, 0}) > FileTimeT::min(), "");<br>
+ static_assert(convert_from_timespec(<br>
+ TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}) ><br>
+ FileTimeT::min(),<br>
+ "");<br>
+ static_assert(convert_from_timespec(TimeSpecT{min_seconds, 0}) ><br>
+ FileTimeT::min(),<br>
+ "");<br>
return true;<br>
}<br>
<br>
@@ -118,12 +209,12 @@ struct check_is_representable<FileTimeT,<br>
};<br>
<br>
template <class FileTimeT, class TimeT, class TimeSpecT, class Base><br>
-struct check_is_representable<FileTimeT, TimeT, TimeSpecT, Base, TK_32Bit><br>
+struct test_case<FileTimeT, TimeT, TimeSpecT, Base, TK_32Bit, TK_64Bit><br>
: public Base {<br>
static constexpr auto max_time_t = std::numeric_limits<TimeT>::max();<br>
static constexpr auto min_time_t = std::numeric_limits<TimeT>::min();<br>
<br>
- using Base::convert_timespec;<br>
+ using Base::convert_from_timespec;<br>
using Base::is_representable;<br>
using Base::max_nsec;<br>
using Base::max_seconds;<br>
@@ -158,9 +249,10 @@ struct check_is_representable<FileTimeT,<br>
}<br>
};<br>
<br>
-template <class FileTimeT, class TimeT, class TimeSpec, class Base><br>
-struct check_is_representable<FileTimeT, TimeT, TimeSpec, Base,<br>
- TK_FloatingPoint> : public Base {<br>
+template <class FileTimeT, class TimeT, class TimeSpec, class Base,<br>
+ TestKind FileTimeTKind><br>
+struct test_case<FileTimeT, TimeT, TimeSpec, Base, TK_FloatingPoint,<br>
+ FileTimeTKind> : public Base {<br>
<br>
static bool test() { return true; }<br>
};<br>
@@ -182,19 +274,33 @@ struct TestClock {<br>
static time_point now() noexcept { return {}; }<br>
};<br>
<br>
-template <class IntType, class Dur = duration<IntType, std::micro> ><br>
-using TestFileTimeT = time_point<TestClock<Dur> >;<br>
+template <class IntType, class Period = std::micro><br>
+using TestFileTimeT = time_point<TestClock<duration<IntType, Period> > >;<br>
<br>
int main() {<br>
- assert((<br>
- check_is_representable<file_time_type, time_t, struct timespec>::test()));<br>
- assert((check_is_representable<TestFileTimeT<int64_t>, int64_t,<br>
- TestTimeSpec<int64_t, long> >::test()));<br>
- assert((check_is_representable<TestFileTimeT<long long>, int32_t,<br>
- TestTimeSpec<int32_t, int32_t> >::test()));<br>
-<br>
- // Test that insane platforms like ppc64 linux, which use long double as time_t,<br>
- // at least compile.<br>
- assert((check_is_representable<TestFileTimeT<long double>, double,<br>
- TestTimeSpec<long double, long> >::test()));<br>
+ { assert((test_case<file_time_type, time_t, struct timespec>::test())); }<br>
+ {<br>
+ assert((test_case<TestFileTimeT<int64_t>, int64_t,<br>
+ TestTimeSpec<int64_t, long> >::test()));<br>
+ }<br>
+ {<br>
+ assert((test_case<TestFileTimeT<long long>, int32_t,<br>
+ TestTimeSpec<int32_t, int32_t> >::test()));<br>
+ }<br>
+ {<br>
+ // Test that insane platforms like ppc64 linux, which use long double as time_t,<br>
+ // at least compile.<br>
+ assert((test_case<TestFileTimeT<long double>, double,<br>
+ TestTimeSpec<long double, long> >::test()));<br>
+ }<br>
+#ifndef TEST_HAS_NO_INT128_T<br>
+ {<br>
+ assert((test_case<TestFileTimeT<__int128_t, std::nano>, int64_t,<br>
+ TestTimeSpec<int64_t, long> >::test()));<br>
+ }<br>
+ {<br>
+ assert((test_case<TestFileTimeT<__int128_t, std::nano>, int32_t,<br>
+ TestTimeSpec<int32_t, int32_t> >::test()));<br>
+ }<br>
+#endif<br>
}<br>
<br>
Modified: libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp (original)<br>
+++ libcxx/trunk/test/std/experimental/filesystem/fs.filesystem.synopsis/file_time_type.pass.cpp Wed Jul 25 13:51:49 2018<br>
@@ -17,15 +17,30 @@<br>
#include <chrono><br>
#include <type_traits><br>
<br>
+#include "test_macros.h"<br>
+<br>
// system_clock is used because it meets the requirements of TrivialClock,<br>
// and the resolution and range of system_clock should match the operating<br>
// system's file time type.<br>
-typedef std::chrono::system_clock ExpectedClock;<br>
-typedef std::chrono::time_point<ExpectedClock> ExpectedTimePoint;<br>
+<br>
+void test_trivial_clock() {<br>
+ using namespace fs;<br>
+ using Clock = file_time_type::clock;<br>
+ ASSERT_NOEXCEPT(Clock::now());<br>
+ ASSERT_SAME_TYPE(decltype(Clock::now()), file_time_type);<br>
+ ASSERT_SAME_TYPE(Clock::time_point, file_time_type);<br>
+ volatile auto* odr_use = &Clock::is_steady;<br>
+ ((void)odr_use);<br>
+}<br>
+<br>
+void test_time_point_resolution_and_range() {<br>
+ using namespace fs;<br>
+ using Dur = file_time_type::duration;<br>
+ using Period = Dur::period;<br>
+ ASSERT_SAME_TYPE(Period, std::nano);<br>
+}<br>
<br>
int main() {<br>
- static_assert(std::is_same<<br>
- fs::file_time_type,<br>
- ExpectedTimePoint<br>
- >::value, "");<br>
+ test_trivial_clock();<br>
+ test_time_point_resolution_and_range();<br>
}<br>
<br>
Modified: libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp?rev=337960&r1=337959&r2=337960&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp?rev=337960&r1=337959&r2=337960&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp (original)<br>
+++ libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp Wed Jul 25 13:51:49 2018<br>
@@ -30,13 +30,86 @@<br>
#include <sys/stat.h><br>
#include <iostream><br>
<br>
+#include <fcntl.h><br>
+#include <sys/time.h><br>
+<br>
using namespace fs;<br>
<br>
-struct Times { std::time_t access, write; };<br>
+using TimeSpec = struct ::timespec;<br>
+using StatT = struct ::stat;<br>
+<br>
+using Sec = std::chrono::duration<file_time_type::rep>;<br>
+using Hours = std::chrono::hours;<br>
+using Minutes = std::chrono::minutes;<br>
+using MicroSec = std::chrono::duration<file_time_type::rep, std::micro>;<br>
+using NanoSec = std::chrono::duration<file_time_type::rep, std::nano>;<br>
+using std::chrono::duration_cast;<br>
+<br>
+#if defined(__APPLE__)<br>
+TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }<br>
+TimeSpec extract_atime(StatT const& st) { return st.st_atimespec; }<br>
+#else<br>
+TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }<br>
+TimeSpec extract_atime(StatT const& st) { return st.st_atim; }<br>
+#endif<br>
+<br>
+bool ConvertToTimeSpec(TimeSpec& ts, file_time_type ft) {<br>
+ using SecFieldT = decltype(TimeSpec::tv_sec);<br>
+ using NSecFieldT = decltype(TimeSpec::tv_nsec);<br>
+ using SecLim = std::numeric_limits<SecFieldT>;<br>
+ using NSecLim = std::numeric_limits<NSecFieldT>;<br>
+<br>
+ auto secs = duration_cast<Sec>(ft.time_since_epoch());<br>
+ auto nsecs = duration_cast<NanoSec>(ft.time_since_epoch() - secs);<br>
+ if (nsecs.count() < 0) {<br>
+ if (Sec::min().count() > SecLim::min()) {<br>
+ secs += Sec(1);<br>
+ nsecs -= Sec(1);<br>
+ } else {<br>
+ nsecs = NanoSec(0);<br>
+ }<br>
+ }<br>
+ if (SecLim::max() < secs.count() || SecLim::min() > secs.count())<br>
+ return false;<br>
+ if (NSecLim::max() < nsecs.count() || NSecLim::min() > nsecs.count())<br>
+ return false;<br>
+ ts.tv_sec = secs.count();<br>
+ ts.tv_nsec = nsecs.count();<br>
+ return true;<br>
+}<br>
+<br>
+bool ConvertFromTimeSpec(file_time_type& ft, TimeSpec ts) {<br>
+ auto secs_part = duration_cast<file_time_type::duration>(Sec(ts.tv_sec));<br>
+ if (duration_cast<Sec>(secs_part).count() != ts.tv_sec)<br>
+ return false;<br>
+ auto subsecs = duration_cast<file_time_type::duration>(NanoSec(ts.tv_nsec));<br>
+ auto dur = secs_part + subsecs;<br>
+ if (dur < secs_part && subsecs.count() >= 0)<br>
+ return false;<br>
+ ft = file_time_type(dur);<br>
+ return true;<br>
+}<br>
+<br>
+bool CompareTimeExact(TimeSpec ts, TimeSpec ts2) {<br>
+ return ts2.tv_sec == ts.tv_sec && ts2.tv_nsec == ts.tv_nsec;<br>
+}<br>
+bool CompareTimeExact(file_time_type ft, TimeSpec ts) {<br>
+ TimeSpec ts2 = {};<br>
+ if (!ConvertToTimeSpec(ts2, ft))<br>
+ return false;<br>
+ return CompareTimeExact(ts, ts2);<br>
+}<br>
+bool CompareTimeExact(TimeSpec ts, file_time_type ft) {<br>
+ return CompareTimeExact(ft, ts);<br>
+}<br>
+<br>
+struct Times {<br>
+ TimeSpec access, write;<br>
+};<br>
<br>
Times GetTimes(path const& p) {<br>
using Clock = file_time_type::clock;<br>
- struct ::stat st;<br>
+ StatT st;<br>
if (::stat(p.c_str(), &st) == -1) {<br>
std::error_code ec(errno, std::generic_category());<br>
#ifndef TEST_HAS_NO_EXCEPTIONS<br>
@@ -46,22 +119,18 @@ Times GetTimes(path const& p) {<br>
std::exit(EXIT_FAILURE);<br>
#endif<br>
}<br>
- return {st.st_atime, st.st_mtime};<br>
+ return {extract_atime(st), extract_mtime(st)};<br>
}<br>
<br>
-std::time_t LastAccessTime(path const& p) {<br>
- return GetTimes(p).access;<br>
-}<br>
+TimeSpec LastAccessTime(path const& p) { return GetTimes(p).access; }<br>
<br>
-std::time_t LastWriteTime(path const& p) {<br>
- return GetTimes(p).write;<br>
-}<br>
+TimeSpec LastWriteTime(path const& p) { return GetTimes(p).write; }<br>
<br>
-std::pair<std::time_t, std::time_t> GetSymlinkTimes(path const& p) {<br>
- using Clock = file_time_type::clock;<br>
- struct ::stat st;<br>
- if (::lstat(p.c_str(), &st) == -1) {<br>
- std::error_code ec(errno, std::generic_category());<br>
+std::pair<TimeSpec, TimeSpec> GetSymlinkTimes(path const& p) {<br>
+ using Clock = file_time_type::clock;<br>
+ StatT st;<br>
+ if (::lstat(p.c_str(), &st) == -1) {<br>
+ std::error_code ec(errno, std::generic_category());<br>
#ifndef TEST_HAS_NO_EXCEPTIONS<br>
throw ec;<br>
#else<br>
@@ -69,24 +138,10 @@ std::pair<std::time_t, std::time_t> GetS<br>
std::exit(EXIT_FAILURE);<br>
#endif<br>
}<br>
- return {st.st_atime, st.st_mtime};<br>
+ return {extract_atime(st), extract_mtime(st)};<br>
}<br>
<br>
namespace {<br>
-bool TestSupportsNegativeTimes() {<br>
- using namespace std::chrono;<br>
- std::error_code ec;<br>
- std::time_t old_write_time, new_write_time;<br>
- { // WARNING: Do not assert in this scope.<br>
- scoped_test_env env;<br>
- const path file = env.create_file("file", 42);<br>
- old_write_time = LastWriteTime(file);<br>
- file_time_type tp(seconds(-5));<br>
- fs::last_write_time(file, tp, ec);<br>
- new_write_time = LastWriteTime(file);<br>
- }<br>
- return !ec && new_write_time <= -5;<br>
-}<br>
<br>
// In some configurations, the comparison is tautological and the test is valid.<br>
// We disable the warning so that we can actually test it regardless. Also, that<br>
@@ -98,61 +153,131 @@ bool TestSupportsNegativeTimes() {<br>
#pragma clang diagnostic ignored "-Wtautological-constant-compare"<br>
#endif<br>
<br>
-bool TestSupportsMaxTime() {<br>
- using namespace std::chrono;<br>
- using Lim = std::numeric_limits<std::time_t>;<br>
- auto max_sec = duration_cast<seconds>(file_time_type::max().time_since_epoch()).count();<br>
- if (max_sec > Lim::max()) return false;<br>
- std::error_code ec;<br>
- std::time_t old_write_time, new_write_time;<br>
- { // WARNING: Do not assert in this scope.<br>
- scoped_test_env env;<br>
- const path file = env.create_file("file", 42);<br>
- old_write_time = LastWriteTime(file);<br>
- file_time_type tp = file_time_type::max();<br>
- fs::last_write_time(file, tp, ec);<br>
- new_write_time = LastWriteTime(file);<br>
- }<br>
- return !ec && new_write_time > max_sec - 1;<br>
-}<br>
-<br>
-bool TestSupportsMinTime() {<br>
- using namespace std::chrono;<br>
- using Lim = std::numeric_limits<std::time_t>;<br>
- auto min_sec = duration_cast<seconds>(file_time_type::min().time_since_epoch()).count();<br>
- if (min_sec < Lim::min()) return false;<br>
- std::error_code ec;<br>
- std::time_t old_write_time, new_write_time;<br>
- { // WARNING: Do not assert in this scope.<br>
- scoped_test_env env;<br>
- const path file = env.create_file("file", 42);<br>
- old_write_time = LastWriteTime(file);<br>
- file_time_type tp = file_time_type::min();<br>
- fs::last_write_time(file, tp, ec);<br>
- new_write_time = LastWriteTime(file);<br>
- }<br>
- return !ec && new_write_time < min_sec + 1;<br>
-}<br>
-<br>
-#if defined(__clang__)<br>
-#pragma clang diagnostic pop<br>
-#endif<br>
-<br>
-static const bool SupportsNegativeTimes = TestSupportsNegativeTimes();<br>
-static const bool SupportsMaxTime = TestSupportsMaxTime();<br>
-static const bool SupportsMinTime = TestSupportsMinTime();<br>
+static const bool SupportsNegativeTimes = [] {<br>
+ using namespace std::chrono;<br>
+ std::error_code ec;<br>
+ TimeSpec old_write_time, new_write_time;<br>
+ { // WARNING: Do not assert in this scope.<br>
+ scoped_test_env env;<br>
+ const path file = env.create_file("file", 42);<br>
+ old_write_time = LastWriteTime(file);<br>
+ file_time_type tp(seconds(-5));<br>
+ fs::last_write_time(file, tp, ec);<br>
+ new_write_time = LastWriteTime(file);<br>
+ }<br>
+<br>
+ return !ec && new_write_time.tv_sec < 0;<br>
+}();<br>
+<br>
+static const bool SupportsMaxTime = [] {<br>
+ using namespace std::chrono;<br>
+ TimeSpec max_ts = {};<br>
+ if (!ConvertToTimeSpec(max_ts, file_time_type::max()))<br>
+ return false;<br>
+<br>
+ std::error_code ec;<br>
+ TimeSpec old_write_time, new_write_time;<br>
+ { // WARNING: Do not assert in this scope.<br>
+ scoped_test_env env;<br>
+ const path file = env.create_file("file", 42);<br>
+ old_write_time = LastWriteTime(file);<br>
+ file_time_type tp = file_time_type::max();<br>
+ fs::last_write_time(file, tp, ec);<br>
+ new_write_time = LastWriteTime(file);<br>
+ }<br>
+ return !ec && new_write_time.tv_sec > max_ts.tv_sec - 1;<br>
+}();<br>
+<br>
+static const bool SupportsMinTime = [] {<br>
+ using namespace std::chrono;<br>
+ TimeSpec min_ts = {};<br>
+ if (!ConvertToTimeSpec(min_ts, file_time_type::min()))<br>
+ return false;<br>
+ std::error_code ec;<br>
+ TimeSpec old_write_time, new_write_time;<br>
+ { // WARNING: Do not assert in this scope.<br>
+ scoped_test_env env;<br>
+ const path file = env.create_file("file", 42);<br>
+ old_write_time = LastWriteTime(file);<br>
+ file_time_type tp = file_time_type::min();<br>
+ fs::last_write_time(file, tp, ec);<br>
+ new_write_time = LastWriteTime(file);<br>
+ }<br>
+ return !ec && new_write_time.tv_sec < min_ts.tv_sec + 1;<br>
+}();<br>
+<br>
+static const bool SupportsNanosecondRoundTrip = [] {<br>
+ NanoSec ns(3);<br>
+<br>
+ // Test if the file_time_type period is less than that of nanoseconds.<br>
+ auto ft_dur = duration_cast<file_time_type::duration>(ns);<br>
+ if (duration_cast<NanoSec>(ft_dur) != ns)<br>
+ return false;<br>
+<br>
+ // Test that the system call we use to set the times also supports nanosecond<br>
+ // resolution. (utimes does not)<br>
+ file_time_type ft(ft_dur);<br>
+ {<br>
+ scoped_test_env env;<br>
+ const path p = env.create_file("file", 42);<br>
+ last_write_time(p, ft);<br>
+ return last_write_time(p) == ft;<br>
+ }<br>
+}();<br>
+<br>
+static const bool SupportsMinRoundTrip = [] {<br>
+ TimeSpec ts = {};<br>
+ if (!ConvertToTimeSpec(ts, file_time_type::min()))<br>
+ return false;<br>
+ file_time_type min_val = {};<br>
+ if (!ConvertFromTimeSpec(min_val, ts))<br>
+ return false;<br>
+ return min_val == file_time_type::min();<br>
+}();<br>
<br>
} // end namespace<br>
<br>
-// In some configurations, the comparison is tautological and the test is valid.<br>
-// We disable the warning so that we can actually test it regardless. Also, that<br>
-// diagnostic is pretty new, so also don't fail if old clang does not support it<br>
-#if defined(__clang__)<br>
-#pragma clang diagnostic push<br>
-#pragma clang diagnostic ignored "-Wunknown-warning-option"<br>
-#pragma clang diagnostic ignored "-Wunknown-pragmas"<br>
-#pragma clang diagnostic ignored "-Wtautological-constant-compare"<br>
-#endif<br>
+static bool CompareTime(TimeSpec t1, TimeSpec t2) {<br>
+ if (SupportsNanosecondRoundTrip)<br>
+ return CompareTimeExact(t1, t2);<br>
+ if (t1.tv_sec != t2.tv_sec)<br>
+ return false;<br>
+<br>
+ auto diff = std::abs(t1.tv_nsec - t2.tv_nsec);<br>
+<br>
+ return diff < duration_cast<NanoSec>(MicroSec(1)).count();<br>
+}<br>
+<br>
+static bool CompareTime(file_time_type t1, TimeSpec t2) {<br>
+ TimeSpec ts1 = {};<br>
+ if (!ConvertToTimeSpec(ts1, t1))<br>
+ return false;<br>
+ return CompareTime(ts1, t2);<br>
+}<br>
+<br>
+static bool CompareTime(TimeSpec t1, file_time_type t2) {<br>
+ return CompareTime(t2, t1);<br>
+}<br>
+<br>
+static bool CompareTime(file_time_type t1, file_time_type t2) {<br>
+ auto min_secs = duration_cast<Sec>(file_time_type::min().time_since_epoch());<br>
+ bool IsMin =<br>
+ t1.time_since_epoch() < min_secs || t2.time_since_epoch() < min_secs;<br>
+<br>
+ if (SupportsNanosecondRoundTrip && (!IsMin || SupportsMinRoundTrip))<br>
+ return t1 == t2;<br>
+ if (IsMin) {<br>
+ return duration_cast<Sec>(t1.time_since_epoch()) ==<br>
+ duration_cast<Sec>(t2.time_since_epoch());<br>
+ }<br>
+ file_time_type::duration dur;<br>
+ if (t1 > t2)<br>
+ dur = t1 - t2;<br>
+ else<br>
+ dur = t2 - t1;<br>
+<br>
+ return duration_cast<MicroSec>(dur).count() < 1;<br>
+}<br>
<br>
// Check if a time point is representable on a given filesystem. Check that:<br>
// (A) 'tp' is representable as a time_t<br>
@@ -162,22 +287,33 @@ static const bool SupportsMinTime = Test<br>
// (D) 'tp' is not 'file_time_type::min()' or the filesystem supports the min<br>
// value.<br>
inline bool TimeIsRepresentableByFilesystem(file_time_type tp) {<br>
- using namespace std::chrono;<br>
- using Lim = std::numeric_limits<std::time_t>;<br>
- auto sec = duration_cast<seconds>(tp.time_since_epoch()).count();<br>
- auto microsec = duration_cast<microseconds>(tp.time_since_epoch()).count();<br>
- if (sec < Lim::min() || sec > Lim::max()) return false;<br>
- else if (microsec < 0 && !SupportsNegativeTimes) return false;<br>
- else if (tp == file_time_type::max() && !SupportsMaxTime) return false;<br>
- else if (tp == file_time_type::min() && !SupportsMinTime) return false;<br>
- return true;<br>
+ TimeSpec ts = {};<br>
+ if (!ConvertToTimeSpec(ts, tp))<br>
+ return false;<br>
+ else if (tp.time_since_epoch().count() < 0 && !SupportsNegativeTimes)<br>
+ return false;<br>
+ else if (tp == file_time_type::max() && !SupportsMaxTime)<br>
+ return false;<br>
+ else if (tp == file_time_type::min() && !SupportsMinTime)<br>
+ return false;<br>
+ return true;<br>
}<br>
<br>
#if defined(__clang__)<br>
#pragma clang diagnostic pop<br>
#endif<br>
<br>
-TEST_SUITE(exists_test_suite)<br>
+// Create a sub-second duration using the smallest period the filesystem supports.<br>
+file_time_type::duration SubSec(long long val) {<br>
+ using SubSecT = file_time_type::duration;<br>
+ if (SupportsNanosecondRoundTrip) {<br>
+ return duration_cast<SubSecT>(NanoSec(val));<br>
+ } else {<br>
+ return duration_cast<SubSecT>(MicroSec(val));<br>
+ }<br>
+}<br>
+<br>
+TEST_SUITE(last_write_time_test_suite)<br>
<br>
TEST_CASE(signature_test)<br>
{<br>
@@ -202,21 +338,21 @@ TEST_CASE(read_last_write_time_static_en<br>
file_time_type ret = last_write_time(StaticEnv::File);<br>
TEST_CHECK(ret != min);<br>
TEST_CHECK(ret < C::now());<br>
- TEST_CHECK(C::to_time_t(ret) == LastWriteTime(StaticEnv::File));<br>
+ TEST_CHECK(CompareTime(ret, LastWriteTime(StaticEnv::File)));<br>
<br>
file_time_type ret2 = last_write_time(StaticEnv::SymlinkToFile);<br>
- TEST_CHECK(ret == ret2);<br>
- TEST_CHECK(C::to_time_t(ret2) == LastWriteTime(StaticEnv::SymlinkToFile));<br>
+ TEST_CHECK(CompareTime(ret, ret2));<br>
+ TEST_CHECK(CompareTime(ret2, LastWriteTime(StaticEnv::SymlinkToFile)));<br>
}<br>
{<br>
file_time_type ret = last_write_time(StaticEnv::Dir);<br>
TEST_CHECK(ret != min);<br>
TEST_CHECK(ret < C::now());<br>
- TEST_CHECK(C::to_time_t(ret) == LastWriteTime(StaticEnv::Dir));<br>
+ TEST_CHECK(CompareTime(ret, LastWriteTime(StaticEnv::Dir)));<br>
<br>
file_time_type ret2 = last_write_time(StaticEnv::SymlinkToDir);<br>
- TEST_CHECK(ret == ret2);<br>
- TEST_CHECK(C::to_time_t(ret2) == LastWriteTime(StaticEnv::SymlinkToDir));<br>
+ TEST_CHECK(CompareTime(ret, ret2));<br>
+ TEST_CHECK(CompareTime(ret2, LastWriteTime(StaticEnv::SymlinkToDir)));<br>
}<br>
}<br>
<br>
@@ -230,15 +366,17 @@ TEST_CASE(get_last_write_time_dynamic_en<br>
const path dir = env.create_dir("dir");<br>
<br>
const auto file_times = GetTimes(file);<br>
- const std::time_t file_write_time = file_times.write;<br>
+ const TimeSpec file_write_time = file_times.write;<br>
const auto dir_times = GetTimes(dir);<br>
- const std::time_t dir_write_time = dir_times.write;<br>
+ const TimeSpec dir_write_time = dir_times.write;<br>
<br>
file_time_type ftime = last_write_time(file);<br>
- TEST_CHECK(Clock::to_time_t(ftime) == file_write_time);<br>
+ TEST_CHECK(Clock::to_time_t(ftime) == file_write_time.tv_sec);<br>
+ TEST_CHECK(CompareTime(ftime, file_write_time));<br>
<br>
file_time_type dtime = last_write_time(dir);<br>
- TEST_CHECK(Clock::to_time_t(dtime) == dir_write_time);<br>
+ TEST_CHECK(Clock::to_time_t(dtime) == dir_write_time.tv_sec);<br>
+ TEST_CHECK(CompareTime(dtime, dir_write_time));<br>
<br>
SleepFor(Sec(2));<br>
<br>
@@ -253,18 +391,15 @@ TEST_CASE(get_last_write_time_dynamic_en<br>
<br>
TEST_CHECK(ftime2 > ftime);<br>
TEST_CHECK(dtime2 > dtime);<br>
- TEST_CHECK(LastWriteTime(file) == Clock::to_time_t(ftime2));<br>
- TEST_CHECK(LastWriteTime(dir) == Clock::to_time_t(dtime2));<br>
+ TEST_CHECK(CompareTime(LastWriteTime(file), ftime2));<br>
+ TEST_CHECK(CompareTime(LastWriteTime(dir), dtime2));<br>
}<br>
<br>
<br>
TEST_CASE(set_last_write_time_dynamic_env_test)<br>
{<br>
using Clock = file_time_type::clock;<br>
- using Sec = std::chrono::seconds;<br>
- using Hours = std::chrono::hours;<br>
- using Minutes = std::chrono::minutes;<br>
- using MicroSec = std::chrono::microseconds;<br>
+ using SubSecT = file_time_type::duration;<br>
scoped_test_env env;<br>
<br>
const path file = env.create_file("file", 42);<br>
@@ -272,15 +407,17 @@ TEST_CASE(set_last_write_time_dynamic_en<br>
const auto now = Clock::now();<br>
const file_time_type epoch_time = now - now.time_since_epoch();<br>
<br>
- const file_time_type future_time = now + Hours(3) + Sec(42) + MicroSec(17);<br>
- const file_time_type past_time = now - Minutes(3) - Sec(42) - MicroSec(17);<br>
- const file_time_type before_epoch_time = epoch_time - Minutes(3) - Sec(42) - MicroSec(17);<br>
+ const file_time_type future_time = now + Hours(3) + Sec(42) + SubSec(17);<br>
+ const file_time_type past_time = now - Minutes(3) - Sec(42) - SubSec(17);<br>
+ const file_time_type before_epoch_time =<br>
+ epoch_time - Minutes(3) - Sec(42) - SubSec(17);<br>
// FreeBSD has a bug in their utimes implementation where the time is not update<br>
// when the number of seconds is '-1'.<br>
#if defined(__FreeBSD__)<br>
- const file_time_type just_before_epoch_time = epoch_time - Sec(2) - MicroSec(17);<br>
+ const file_time_type just_before_epoch_time =<br>
+ epoch_time - Sec(2) - SubSec(17);<br>
#else<br>
- const file_time_type just_before_epoch_time = epoch_time - MicroSec(17);<br>
+ const file_time_type just_before_epoch_time = epoch_time - SubSec(17);<br>
#endif<br>
<br>
struct TestCase {<br>
@@ -300,7 +437,8 @@ TEST_CASE(set_last_write_time_dynamic_en<br>
};<br>
for (const auto& TC : cases) {<br>
const auto old_times = GetTimes(TC.p);<br>
- file_time_type old_time(Sec(old_times.write));<br>
+ file_time_type old_time;<br>
+ TEST_REQUIRE(ConvertFromTimeSpec(old_time, old_times.write));<br>
<br>
std::error_code ec = GetTestEC();<br>
last_write_time(TC.p, TC.new_time, ec);<br>
@@ -310,14 +448,8 @@ TEST_CASE(set_last_write_time_dynamic_en<br>
<br>
if (TimeIsRepresentableByFilesystem(TC.new_time)) {<br>
TEST_CHECK(got_time != old_time);<br>
- if (TC.new_time < epoch_time) {<br>
- TEST_CHECK(got_time <= TC.new_time);<br>
- TEST_CHECK(got_time > TC.new_time - Sec(1));<br>
- } else {<br>
- TEST_CHECK(got_time <= TC.new_time + Sec(1));<br>
- TEST_CHECK(got_time >= TC.new_time - Sec(1));<br>
- }<br>
- TEST_CHECK(LastAccessTime(TC.p) == old_times.access);<br>
+ TEST_CHECK(CompareTime(got_time, TC.new_time));<br>
+ TEST_CHECK(CompareTime(LastAccessTime(TC.p), old_times.access));<br>
}<br>
}<br>
}<br>
@@ -325,9 +457,6 @@ TEST_CASE(set_last_write_time_dynamic_en<br>
TEST_CASE(last_write_time_symlink_test)<br>
{<br>
using Clock = file_time_type::clock;<br>
- using Sec = std::chrono::seconds;<br>
- using Hours = std::chrono::hours;<br>
- using Minutes = std::chrono::minutes;<br>
<br>
scoped_test_env env;<br>
<br>
@@ -343,77 +472,75 @@ TEST_CASE(last_write_time_symlink_test)<br>
last_write_time(sym, new_time, ec);<br>
TEST_CHECK(!ec);<br>
<br>
- const std::time_t new_time_t = Clock::to_time_t(new_time);<br>
file_time_type got_time = last_write_time(sym);<br>
- std::time_t got_time_t = Clock::to_time_t(got_time);<br>
+ TEST_CHECK(!CompareTime(got_time, old_times.write));<br>
+ TEST_CHECK(got_time == new_time);<br>
<br>
- TEST_CHECK(got_time_t != old_times.write);<br>
- TEST_CHECK(got_time_t == new_time_t);<br>
- TEST_CHECK(LastWriteTime(file) == new_time_t);<br>
- TEST_CHECK(LastAccessTime(sym) == old_times.access);<br>
- TEST_CHECK(GetSymlinkTimes(sym) == old_sym_times);<br>
+ TEST_CHECK(CompareTime(LastWriteTime(file), new_time));<br>
+ TEST_CHECK(CompareTime(LastAccessTime(sym), old_times.access));<br>
+ std::pair<TimeSpec, TimeSpec> sym_times = GetSymlinkTimes(sym);<br>
+ TEST_CHECK(CompareTime(sym_times.first, old_sym_times.first));<br>
+ TEST_CHECK(CompareTime(sym_times.second, old_sym_times.second));<br>
}<br>
<br>
<br>
TEST_CASE(test_write_min_time)<br>
{<br>
using Clock = file_time_type::clock;<br>
- using Sec = std::chrono::seconds;<br>
- using MicroSec = std::chrono::microseconds;<br>
- using Lim = std::numeric_limits<std::time_t>;<br>
scoped_test_env env;<br>
const path p = env.create_file("file", 42);<br>
-<br>
- std::error_code ec = GetTestEC();<br>
+ const file_time_type old_time = last_write_time(p);<br>
file_time_type new_time = file_time_type::min();<br>
<br>
+ std::error_code ec = GetTestEC();<br>
last_write_time(p, new_time, ec);<br>
file_time_type tt = last_write_time(p);<br>
<br>
if (TimeIsRepresentableByFilesystem(new_time)) {<br>
TEST_CHECK(!ec);<br>
- TEST_CHECK(tt >= new_time);<br>
- TEST_CHECK(tt < new_time + Sec(1));<br>
-<br>
- ec = GetTestEC();<br>
- last_write_time(p, Clock::now());<br>
+ TEST_CHECK(CompareTime(tt, new_time));<br>
<br>
- new_time = file_time_type::min() + MicroSec(1);<br>
+ last_write_time(p, old_time);<br>
+ new_time = file_time_type::min() + SubSec(1);<br>
<br>
+ ec = GetTestEC();<br>
last_write_time(p, new_time, ec);<br>
tt = last_write_time(p);<br>
<br>
if (TimeIsRepresentableByFilesystem(new_time)) {<br>
TEST_CHECK(!ec);<br>
- TEST_CHECK(tt >= new_time);<br>
- TEST_CHECK(tt < new_time + Sec(1));<br>
+ TEST_CHECK(CompareTime(tt, new_time));<br>
+ } else {<br>
+ TEST_CHECK(ErrorIs(ec, std::errc::value_too_large));<br>
+ TEST_CHECK(tt == old_time);<br>
}<br>
+ } else {<br>
+ TEST_CHECK(ErrorIs(ec, std::errc::value_too_large));<br>
+ TEST_CHECK(tt == old_time);<br>
}<br>
}<br>
<br>
+TEST_CASE(test_write_max_time) {<br>
+ using Clock = file_time_type::clock;<br>
+ using Sec = std::chrono::seconds;<br>
+ using Hours = std::chrono::hours;<br>
+<br>
+ scoped_test_env env;<br>
+ const path p = env.create_file("file", 42);<br>
+ const file_time_type old_time = last_write_time(p);<br>
+ file_time_type new_time = file_time_type::max();<br>
+<br>
+ std::error_code ec = GetTestEC();<br>
+ last_write_time(p, new_time, ec);<br>
+ file_time_type tt = last_write_time(p);<br>
<br>
-<br>
-TEST_CASE(test_write_min_max_time)<br>
-{<br>
- using Clock = file_time_type::clock;<br>
- using Sec = std::chrono::seconds;<br>
- using Hours = std::chrono::hours;<br>
- using Lim = std::numeric_limits<std::time_t>;<br>
- scoped_test_env env;<br>
- const path p = env.create_file("file", 42);<br>
-<br>
- std::error_code ec = GetTestEC();<br>
- file_time_type new_time = file_time_type::max();<br>
-<br>
- ec = GetTestEC();<br>
- last_write_time(p, new_time, ec);<br>
- file_time_type tt = last_write_time(p);<br>
-<br>
- if (TimeIsRepresentableByFilesystem(new_time)) {<br>
- TEST_CHECK(!ec);<br>
- TEST_CHECK(tt > new_time - Sec(1));<br>
- TEST_CHECK(tt <= new_time);<br>
- }<br>
+ if (TimeIsRepresentableByFilesystem(new_time)) {<br>
+ TEST_CHECK(!ec);<br>
+ TEST_CHECK(CompareTime(tt, new_time));<br>
+ } else {<br>
+ TEST_CHECK(ErrorIs(ec, std::errc::value_too_large));<br>
+ TEST_CHECK(tt == old_time);<br>
+ }<br>
}<br>
<br>
TEST_CASE(test_value_on_failure)<br>
@@ -421,8 +548,7 @@ TEST_CASE(test_value_on_failure)<br>
const path p = StaticEnv::DNE;<br>
std::error_code ec = GetTestEC();<br>
TEST_CHECK(last_write_time(p, ec) == file_time_type::min());<br>
- TEST_CHECK(ec);<br>
- TEST_CHECK(ec != GetTestEC());<br>
+ TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));<br>
}<br>
<br>
TEST_CASE(test_exists_fails)<br>
@@ -434,10 +560,30 @@ TEST_CASE(test_exists_fails)<br>
<br>
std::error_code ec = GetTestEC();<br>
TEST_CHECK(last_write_time(file, ec) == file_time_type::min());<br>
- TEST_CHECK(ec);<br>
- TEST_CHECK(ec != GetTestEC());<br>
+ TEST_CHECK(ErrorIs(ec, std::errc::permission_denied));<br>
<br>
- TEST_CHECK_THROW(filesystem_error, last_write_time(file));<br>
+ ExceptionChecker Checker(file, std::errc::permission_denied,<br>
+ "last_write_time");<br>
+ TEST_CHECK_THROW_RESULT(filesystem_error, Checker, last_write_time(file));<br>
+}<br>
+<br>
+TEST_CASE(my_test) {<br>
+ scoped_test_env env;<br>
+ const path p = env.create_file("file", 42);<br>
+ using namespace std::chrono;<br>
+ using TimeSpec = struct ::timespec;<br>
+ TimeSpec ts[2];<br>
+ ts[0].tv_sec = 0;<br>
+ ts[0].tv_nsec = UTIME_OMIT;<br>
+ ts[1].tv_sec = -1;<br>
+ ts[1].tv_nsec =<br>
+ duration_cast<nanoseconds>(seconds(1) - nanoseconds(13)).count();<br>
+ if (::utimensat(AT_FDCWD, p.c_str(), ts, 0) == -1) {<br>
+ TEST_CHECK(false);<br>
+ }<br>
+ TimeSpec new_ts = LastWriteTime(p);<br>
+ TEST_CHECK(ts[1].tv_sec == new_ts.tv_sec);<br>
+ TEST_CHECK(ts[1].tv_nsec == new_ts.tv_nsec);<br>
}<br>
<br>
TEST_SUITE_END()<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" rel="noreferrer" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div></div></div></div>
</blockquote></div></div></div><br></div>
</blockquote></div><br></div>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</blockquote></div>