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