stat.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright (c) 2020 Alexander Grund
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_NOWIDE_STAT_HPP_INCLUDED
  8. #define BOOST_NOWIDE_STAT_HPP_INCLUDED
  9. #include <boost/nowide/config.hpp>
  10. #include <sys/types.h>
  11. // Include after sys/types.h
  12. #include <sys/stat.h>
  13. #if defined(__MINGW32__) && defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x0601
  14. /// Forward declaration in case MinGW32 is used and __MSVCRT_VERSION__ is defined lower than 6.1
  15. struct __stat64;
  16. #endif
  17. namespace boost {
  18. namespace nowide {
  19. #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
  20. // Note: `using x = struct ::stat` causes a bogus warning in GCC < 11
  21. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66159
  22. typedef struct ::stat stat_t;
  23. typedef struct ::stat posix_stat_t;
  24. using ::stat;
  25. #else
  26. /// \brief Typedef for the file info structure.
  27. /// Able to hold 64 bit filesize and timestamps on Windows and usually also on other 64 Bit systems
  28. /// This allows to write portable code with option LFS support
  29. typedef struct ::__stat64 stat_t;
  30. /// \brief Typedef for the file info structure used in the POSIX stat call
  31. /// Resolves to `struct _stat` on Windows and `struct stat` otherwise
  32. /// This allows to write portable code using the default stat function
  33. typedef struct ::_stat posix_stat_t;
  34. /// \cond INTERNAL
  35. namespace detail {
  36. BOOST_NOWIDE_DECL int stat(const char* path, posix_stat_t* buffer, size_t buffer_size);
  37. }
  38. /// \endcond
  39. ///
  40. /// \brief UTF-8 aware stat function, returns 0 on success
  41. ///
  42. /// Return information about a file from an UTF-8 encoded path
  43. ///
  44. BOOST_NOWIDE_DECL int stat(const char* path, stat_t* buffer);
  45. ///
  46. /// \brief UTF-8 aware stat function, returns 0 on success
  47. ///
  48. /// Return information about a file from an UTF-8 encoded path
  49. ///
  50. inline int stat(const char* path, posix_stat_t* buffer)
  51. {
  52. return detail::stat(path, buffer, sizeof(*buffer));
  53. }
  54. #endif
  55. } // namespace nowide
  56. } // namespace boost
  57. #endif