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.

123 lines
2.1 KiB

  1. /*
  2. ISC License
  3. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #pragma once
  16. #include <string>
  17. #include <sys/stat.h>
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20. namespace fs
  21. {
  22. static
  23. inline
  24. int
  25. stat(const char *path_,
  26. struct stat *st_)
  27. {
  28. return ::stat(path_,st_);
  29. }
  30. static
  31. inline
  32. int
  33. stat(const std::string &path_,
  34. struct stat *st_)
  35. {
  36. return fs::stat(path_.c_str(),st_);
  37. }
  38. static
  39. inline
  40. int
  41. lstat(const char *path_,
  42. struct stat *st_)
  43. {
  44. return ::lstat(path_,st_);
  45. }
  46. static
  47. inline
  48. int
  49. lstat(const std::string &path_,
  50. struct stat *st_)
  51. {
  52. return fs::lstat(path_.c_str(),st_);
  53. }
  54. static
  55. inline
  56. int
  57. fstat(const int fd_,
  58. struct stat *st_)
  59. {
  60. return ::fstat(fd_,st_);
  61. }
  62. static
  63. inline
  64. timespec *
  65. stat_atime(struct stat *st_)
  66. {
  67. #if __APPLE__
  68. return &st_->st_atimespec;
  69. #else
  70. return &st_->st_atim;
  71. #endif
  72. }
  73. static
  74. inline
  75. const
  76. timespec *
  77. stat_atime(const struct stat *st_)
  78. {
  79. #if __APPLE__
  80. return &st_->st_atimespec;
  81. #else
  82. return &st_->st_atim;
  83. #endif
  84. }
  85. static
  86. inline
  87. timespec *
  88. stat_mtime(struct stat *st_)
  89. {
  90. #if __APPLE__
  91. return &st_->st_mtimespec;
  92. #else
  93. return &st_->st_mtim;
  94. #endif
  95. }
  96. static
  97. inline
  98. const
  99. timespec *
  100. stat_mtime(const struct stat *st_)
  101. {
  102. #if __APPLE__
  103. return &st_->st_mtimespec;
  104. #else
  105. return &st_->st_mtim;
  106. #endif
  107. }
  108. }