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 using stat_t = struct stat; 24 using posix_stat_t = struct stat; 25 26 using ::stat; 27 #else 28 /// \brief Typedef for the file info structure. 29 /// Able to hold 64 bit filesize and timestamps on Windows and usually also on other 64 Bit systems 30 /// This allows to write portable code with option LFS support 31 typedef struct ::__stat64 stat_t; 32 /// \brief Typedef for the file info structure used in the POSIX stat call 33 /// Resolves to `struct _stat` on Windows and `struct stat` otherwise 34 /// This allows to write portable code using the default stat function 35 typedef struct ::_stat posix_stat_t; 36 37 /// \cond INTERNAL 38 namespace detail { 39 BOOST_NOWIDE_DECL int stat(const char* path, posix_stat_t* buffer, size_t buffer_size); 40 } 41 /// \endcond 42 43 /// 44 /// \brief UTF-8 aware stat function, returns 0 on success 45 /// 46 /// Return information about a file from an UTF-8 encoded path 47 /// 48 BOOST_NOWIDE_DECL int stat(const char* path, stat_t* buffer); 49 /// 50 /// \brief UTF-8 aware stat function, returns 0 on success 51 /// 52 /// Return information about a file from an UTF-8 encoded path 53 /// 54 inline int stat(const char* path, posix_stat_t* buffer) 55 { 56 return detail::stat(path, buffer, sizeof(*buffer)); 57 } 58 #endif 59 } // namespace nowide 60 } // namespace boost 61 62 #endif 63