You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. From 83b989ecee478be083db8dc0cc7a5387615bd3cb Mon Sep 17 00:00:00 2001
  2. From: Andrey Semashev <andrey.semashev@gmail.com>
  3. Date: Wed, 31 Jul 2019 16:28:05 +0300
  4. Subject: [PATCH] Added support for utimensat for better POSIX.1-2008
  5. compliance.
  6. POSIX.1-2008 marks utime as obsolete and replaces it with utimensat.
  7. uClibc-ng has an option for removing utime, including the corresponding
  8. header.
  9. Closes https://github.com/boostorg/filesystem/pull/115.
  10. ---
  11. libs/filesystem/src/operations.cpp | 24 ++++++++++++++++++++++--
  12. 1 file changed, 22 insertions(+), 2 deletions(-)
  13. diff --git a/src/operations.cpp b/src/operations.cpp
  14. index 9bba1cf7a..038109d35 100644
  15. --- a/libs/filesystem/src/operations.cpp
  16. +++ b/libs/filesystem/src/operations.cpp
  17. @@ -62,7 +62,7 @@
  18. #endif
  19. #ifndef _POSIX_PTHREAD_SEMANTICS
  20. -# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r()needs this
  21. +# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this
  22. #endif
  23. #include <boost/filesystem/operations.hpp>
  24. @@ -119,7 +119,9 @@ using std::wstring;
  25. # include <dirent.h>
  26. # include <unistd.h>
  27. # include <fcntl.h>
  28. -# include <utime.h>
  29. +# if _POSIX_C_SOURCE < 200809L
  30. +# include <utime.h>
  31. +# endif
  32. # include "limits.h"
  33. # else // BOOST_WINDOW_API
  34. @@ -1451,6 +1453,22 @@ namespace detail
  35. system::error_code* ec)
  36. {
  37. # ifdef BOOST_POSIX_API
  38. +# if _POSIX_C_SOURCE >= 200809L
  39. +
  40. + struct timespec times[2] = {};
  41. +
  42. + // Keep the last access time unchanged
  43. + times[0].tv_nsec = UTIME_OMIT;
  44. +
  45. + times[1].tv_sec = new_time;
  46. +
  47. + if (BOOST_UNLIKELY(::utimensat(AT_FDCWD, p.c_str(), times, 0) != 0))
  48. + {
  49. + error(BOOST_ERRNO, p, ec, "boost::filesystem::last_write_time");
  50. + return;
  51. + }
  52. +
  53. +# else // _POSIX_C_SOURCE >= 200809L
  54. struct stat path_stat;
  55. if (error(::stat(p.c_str(), &path_stat)!= 0,
  56. @@ -1462,6 +1480,8 @@ namespace detail
  57. error(::utime(p.c_str(), &buf)!= 0 ? BOOST_ERRNO : 0,
  58. p, ec, "boost::filesystem::last_write_time");
  59. +# endif // _POSIX_C_SOURCE >= 200809L
  60. +
  61. # else
  62. handle_wrapper hw(