summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-07-26 03:57:26 +0000
committerEric Fiselier <eric@efcs.ca>2018-07-26 03:57:26 +0000
commitd1759cf0e989daeb2b93f62636519cda177d8498 (patch)
treeaed49728e521b0ef7ad71bb8e1137c791c5f6319 /src
parentcff3d7b20271a256e87b84cb09193f12ec659efe (diff)
downloadlibcxx-d1759cf0e989daeb2b93f62636519cda177d8498.tar.gz
Cleanup the last_write_time internals
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@338001 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src')
-rw-r--r--src/experimental/filesystem/filesystem_common.h40
-rw-r--r--src/experimental/filesystem/operations.cpp3
2 files changed, 26 insertions, 17 deletions
diff --git a/src/experimental/filesystem/filesystem_common.h b/src/experimental/filesystem/filesystem_common.h
index 5d2a5ed4e..94f4d41cc 100644
--- a/src/experimental/filesystem/filesystem_common.h
+++ b/src/experimental/filesystem/filesystem_common.h
@@ -19,6 +19,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
+#include <sys/time.h> // for ::utimes as used in __last_write_time
#include <fcntl.h> /* values for fchmodat */
#include <experimental/filesystem>
@@ -33,14 +34,6 @@
#endif
#endif
-#if !defined(_LIBCPP_USE_UTIMENSAT)
-#include <sys/time.h> // for ::utimes as used in __last_write_time
-#endif
-
-#if !defined(UTIME_OMIT)
-#include <sys/time.h> // for ::utimes as used in __last_write_time
-#endif
-
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -389,9 +382,11 @@ TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
#endif
-bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
+// allow the utimes implementation to compile even it we're not going
+// to use it.
+
+bool posix_utimes(const path& p, std::array<TimeSpec, 2> const& TS,
error_code& ec) {
-#if !defined(_LIBCPP_USE_UTIMENSAT)
using namespace chrono;
auto Convert = [](long nsec) {
using int_type = decltype(std::declval<::timeval>().tv_usec);
@@ -400,22 +395,35 @@ bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
};
struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)},
{TS[1].tv_sec, Convert(TS[1].tv_nsec)}};
- if (::utimes(p.c_str(), ConvertedTS) == -1)
-#else
+ if (::utimes(p.c_str(), ConvertedTS) == -1) {
+ ec = capture_errno();
+ return true;
+ }
+ return false;
+}
+
+#if defined(_LIBCPP_USE_UTIMENSAT)
+bool posix_utimensat(const path& p, std::array<TimeSpec, 2> const& TS,
+ error_code& ec) {
if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1)
-#endif
{
ec = capture_errno();
return true;
}
return false;
}
+#endif
-bool set_time_spec_to(TimeSpec& TS, file_time_type NewTime) {
- return !fs_time::set_times_checked(
- &TS.tv_sec, &TS.tv_nsec, NewTime);
+bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
+ error_code& ec) {
+#if !defined(_LIBCPP_USE_UTIMENSAT)
+ return posix_utimes(p, TS, ec);
+#else
+ return posix_utimensat(p, TS, ec);
+#endif
}
+
} // namespace
} // end namespace detail
diff --git a/src/experimental/filesystem/operations.cpp b/src/experimental/filesystem/operations.cpp
index d57066875..028d5bf0b 100644
--- a/src/experimental/filesystem/operations.cpp
+++ b/src/experimental/filesystem/operations.cpp
@@ -1017,6 +1017,7 @@ file_time_type __last_write_time(const path& p, error_code *ec)
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);
error_code m_ec;
@@ -1034,7 +1035,7 @@ void __last_write_time(const path& p, file_time_type new_time,
tbuf[0].tv_sec = 0;
tbuf[0].tv_nsec = UTIME_OMIT;
#endif
- if (detail::set_time_spec_to(tbuf[1], new_time))
+ if (!fs_time::convert_to_timespec(tbuf[1], new_time))
return err.report(errc::value_too_large);
detail::set_file_times(p, tbuf, m_ec);