| 4302 | } |
| 4303 | |
| 4304 | BOOST_FILESYSTEM_DECL |
| 4305 | void last_write_time(path const& p, const std::time_t new_time, system::error_code* ec) |
| 4306 | { |
| 4307 | if (ec) |
| 4308 | ec->clear(); |
| 4309 | |
| 4310 | #if defined(BOOST_FILESYSTEM_POSIX_API) |
| 4311 | |
| 4312 | #if defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) |
| 4313 | |
| 4314 | struct timespec times[2] = {}; |
| 4315 | |
| 4316 | // Keep the last access time unchanged |
| 4317 | times[0].tv_nsec = UTIME_OMIT; |
| 4318 | |
| 4319 | times[1].tv_sec = new_time; |
| 4320 | |
| 4321 | if (BOOST_UNLIKELY(::utimensat(AT_FDCWD, p.c_str(), times, 0) != 0)) |
| 4322 | { |
| 4323 | emit_error(BOOST_ERRNO, p, ec, "boost::filesystem::last_write_time"); |
| 4324 | return; |
| 4325 | } |
| 4326 | |
| 4327 | #else // defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) |
| 4328 | |
| 4329 | struct ::stat st; |
| 4330 | if (BOOST_UNLIKELY(::stat(p.c_str(), &st) < 0)) |
| 4331 | { |
| 4332 | emit_error(BOOST_ERRNO, p, ec, "boost::filesystem::last_write_time"); |
| 4333 | return; |
| 4334 | } |
| 4335 | |
| 4336 | ::utimbuf buf; |
| 4337 | buf.actime = st.st_atime; // utime() updates access time too :-( |
| 4338 | buf.modtime = new_time; |
| 4339 | if (BOOST_UNLIKELY(::utime(p.c_str(), &buf) < 0)) |
| 4340 | emit_error(BOOST_ERRNO, p, ec, "boost::filesystem::last_write_time"); |
| 4341 | |
| 4342 | #endif // defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) |
| 4343 | |
| 4344 | #else // defined(BOOST_FILESYSTEM_POSIX_API) |
| 4345 | |
| 4346 | unique_handle hw(create_file_handle( |
| 4347 | p.c_str(), |
| 4348 | FILE_WRITE_ATTRIBUTES, |
| 4349 | FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 4350 | nullptr, |
| 4351 | OPEN_EXISTING, |
| 4352 | FILE_FLAG_BACKUP_SEMANTICS)); |
| 4353 | |
| 4354 | DWORD err; |
| 4355 | if (BOOST_UNLIKELY(!hw)) |
| 4356 | { |
| 4357 | fail_errno: |
| 4358 | err = BOOST_ERRNO; |
| 4359 | fail: |
| 4360 | emit_error(err, p, ec, "boost::filesystem::last_write_time"); |
| 4361 | return; |