This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Implement ISO/IEC TS 18822 C++ File system TS
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: Daniel Krügler <daniel dot kruegler at gmail dot com>, Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>, Luke Allardyce <lukeallardyce at gmail dot com>
- Date: Sat, 2 May 2015 10:51:55 +0100
- Subject: Re: [patch] Implement ISO/IEC TS 18822 C++ File system TS
- Authentication-results: sourceware.org; auth=none
- References: <20150430173236 dot GT3618 at redhat dot com> <20150430191353 dot GW3618 at redhat dot com> <CAFW6PZB9WvskzrKCsNKK4s-5oXWjcwkuZGMrWbrfgJ7fpJiCXQ at mail dot gmail dot com> <20150501105351 dot GY3618 at redhat dot com> <20150501194853 dot GK3618 at redhat dot com>
Another portability fix, to avoid using &stat::st_atime because
st_atime might be a macro, and &stat::st_atim.tv_sec is not valid.
Also POSIX doesn't actually require any particular structure for
timespec, so set the fields explicitly instead of using braces.
Tested powerpc64le-linux and powerpc-aix7, committed to trunk.
commit 2a89701d33798b1b5425e56e3050024327879b5f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri May 1 23:46:21 2015 +0100
* src/filesystem/ops.cc (last_write_time) [_GLIBCXX_USE_UTIMENSAT]:
Set timespec members explicitly instead of with a braced-init-list.
[_GLIBCXX_HAVE_UTIME_H]: Use lambda to handle st_atime being a macro.
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index c7e3960..aa1ab04 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -871,20 +871,22 @@ fs::last_write_time(const path& p __attribute__((__unused__)),
{
auto d = new_time.time_since_epoch();
auto s = chrono::duration_cast<chrono::seconds>(d);
+#if _GLIBCXX_USE_UTIMENSAT
auto ns = chrono::duration_cast<chrono::nanoseconds>(d - s);
-#ifdef _GLIBCXX_USE_UTIMENSAT
- struct ::timespec ts[2] = {
- { 0, UTIME_OMIT },
- { static_cast<std::time_t>(s.count()), static_cast<long>(ns.count()) }
- };
- if (utimensat(AT_FDCWD, p.c_str(), ts, 0))
+ struct ::timespec ts[2];
+ ts[0].tv_sec = 0;
+ ts[0].tv_nsec = UTIME_OMIT;
+ ts[1].tv_sec = static_cast<std::time_t>(s.count());
+ ts[1].tv_nsec = static_cast<long>(ns.count());
+ if (::utimensat(AT_FDCWD, p.c_str(), ts, 0))
ec.assign(errno, std::generic_category());
else
ec.clear();
#elif _GLIBCXX_HAVE_UTIME_H
::utimbuf times;
times.modtime = s.count();
- times.actime = do_stat(p, ec, std::mem_fn(&stat::st_atime), times.modtime);
+ times.actime = do_stat(p, ec, [](const auto& st) { return st.st_atime; },
+ times.modtime);
if (::utime(p.c_str(), ×))
ec.assign(errno, std::generic_category());
else