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.

100 lines
2.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  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 "ghc/filesystem.hpp"
  17. #include <string>
  18. #include <errno.h>
  19. #include <fcntl.h>
  20. #include <sys/stat.h>
  21. #include <sys/types.h>
  22. namespace fs
  23. {
  24. static
  25. inline
  26. int
  27. open(const char *path_,
  28. const int flags_)
  29. {
  30. int rv;
  31. rv = ::open(path_,flags_);
  32. if(rv == -1)
  33. return -errno;
  34. return rv;
  35. }
  36. static
  37. inline
  38. int
  39. open(const char *path_,
  40. const int flags_,
  41. const mode_t mode_)
  42. {
  43. int rv;
  44. rv = ::open(path_,flags_,mode_);
  45. if(rv == -1)
  46. return -errno;
  47. return rv;
  48. }
  49. static
  50. inline
  51. int
  52. open(const ghc::filesystem::path &path_,
  53. const int flags_,
  54. const mode_t mode_)
  55. {
  56. return fs::open(path_.c_str(),flags_,mode_);
  57. }
  58. static
  59. inline
  60. int
  61. open(const std::string &path_,
  62. const int flags_)
  63. {
  64. return fs::open(path_.c_str(),flags_);
  65. }
  66. static
  67. inline
  68. int
  69. open(const std::string &path_,
  70. const int flags_,
  71. const mode_t mode_)
  72. {
  73. return fs::open(path_.c_str(),flags_,mode_);
  74. }
  75. static
  76. inline
  77. int
  78. open_dir_ro(const std::string &path_)
  79. {
  80. return fs::open(path_,O_RDONLY|O_DIRECTORY);
  81. }
  82. }