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.

68 lines
1.6 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #ifndef __FS_BASE_UTIME_HPP__
  15. #define __FS_BASE_UTIME_HPP__
  16. #ifdef __linux__
  17. # include "fs_base_utime_utimensat.hpp"
  18. #elif __FreeBSD__ >= 11
  19. # include "fs_base_utime_utimensat.hpp"
  20. #else
  21. # include "fs_base_utime_generic.hpp"
  22. #endif
  23. namespace fs
  24. {
  25. static
  26. inline
  27. int
  28. utime(const std::string &path,
  29. const struct stat &st)
  30. {
  31. struct timespec times[2];
  32. times[0] = st.st_atim;
  33. times[1] = st.st_mtim;
  34. return fs::utime(AT_FDCWD,path,times,0);
  35. }
  36. static
  37. inline
  38. int
  39. utime(const int fd,
  40. const struct stat &st)
  41. {
  42. struct timespec times[2];
  43. times[0] = st.st_atim;
  44. times[1] = st.st_mtim;
  45. return fs::utime(fd,times);
  46. }
  47. static
  48. inline
  49. int
  50. lutime(const std::string &path,
  51. const struct timespec times[2])
  52. {
  53. return fs::utime(AT_FDCWD,path,times,AT_SYMLINK_NOFOLLOW);
  54. }
  55. }
  56. #endif