File indexing completed on 2024-11-15 09:05:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_FILESYSTEM_CSTDIO_HPP
0013 #define BOOST_FILESYSTEM_CSTDIO_HPP
0014
0015 #include <boost/filesystem/config.hpp>
0016 #include <boost/filesystem/path.hpp>
0017 #include <cstdio>
0018 #if defined(BOOST_WINDOWS_API)
0019 #include <wchar.h>
0020 #include <cstddef>
0021 #include <cstring>
0022 #include <cstdlib>
0023 #endif
0024
0025 #include <boost/filesystem/detail/header.hpp> // must be the last #include
0026
0027 namespace boost {
0028 namespace filesystem {
0029
0030 #if defined(BOOST_WINDOWS_API)
0031
0032 inline std::FILE* fopen(filesystem::path const& p, const char* mode)
0033 {
0034 #if defined(__CYGWIN__) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) && defined(__STRICT_ANSI__))
0035
0036 return std::fopen(p.string().c_str(), mode);
0037 #else
0038
0039 struct small_array
0040 {
0041 wchar_t buf[128u];
0042 wchar_t* p;
0043
0044 small_array() BOOST_NOEXCEPT : p(buf) {}
0045 ~small_array() BOOST_NOEXCEPT
0046 {
0047 if (BOOST_UNLIKELY(p != buf))
0048 std::free(p);
0049 }
0050 }
0051 wmode;
0052 std::size_t wmode_len = std::mbstowcs(wmode.p, mode, sizeof(wmode.buf) / sizeof(wchar_t));
0053 if (BOOST_UNLIKELY(wmode_len >= (sizeof(wmode.buf) / sizeof(wchar_t))))
0054 {
0055 wmode_len = std::mbstowcs(NULL, mode, 0u);
0056
0057 if (BOOST_UNLIKELY(wmode_len >= (static_cast< std::size_t >(-1) / sizeof(wchar_t))))
0058 return NULL;
0059
0060 wmode.p = static_cast< wchar_t* >(std::malloc((wmode_len + 1u) * sizeof(wchar_t)));
0061 if (BOOST_UNLIKELY(!wmode.p))
0062 return NULL;
0063
0064 std::size_t wmode_len2 = std::mbstowcs(wmode.p, mode, wmode_len + 1u);
0065 if (BOOST_UNLIKELY(wmode_len2 > wmode_len))
0066 return NULL;
0067 }
0068
0069 return ::_wfopen(p.c_str(), wmode.p);
0070 #endif
0071 }
0072
0073 #else
0074
0075 inline std::FILE* fopen(filesystem::path const& p, const char* mode)
0076 {
0077 return std::fopen(p.c_str(), mode);
0078 }
0079
0080 #endif
0081
0082 }
0083 }
0084
0085 #include <boost/filesystem/detail/footer.hpp>
0086
0087 #endif