File indexing completed on 2025-01-18 09:38:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
0018 #define BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
0019
0020 #include <boost/config.hpp> // make sure size_t is in std.
0021 #include <cstddef> // size_t
0022 #include <string>
0023 #include <boost/iostreams/detail/buffer.hpp>
0024 #include <boost/iostreams/detail/config/windows_posix.hpp>
0025 #include <boost/iostreams/detail/system_failure.hpp>
0026 #ifdef BOOST_IOSTREAMS_WINDOWS
0027 # define WIN32_LEAN_AND_MEAN
0028 # include <windows.h>
0029 #else
0030 # include <unistd.h> // sysconf.
0031 #endif
0032
0033
0034 #include <boost/iostreams/detail/config/disable_warnings.hpp>
0035
0036 namespace boost { namespace iostreams { namespace detail {
0037
0038
0039 inline std::string current_directory()
0040 {
0041 #ifdef BOOST_IOSTREAMS_WINDOWS
0042 DWORD length;
0043 basic_buffer<char> buf(MAX_PATH);
0044 while (true) {
0045 length = ::GetCurrentDirectoryA(buf.size(), buf.data());
0046 if (!length)
0047 throw_system_failure("failed determining current directory");
0048 if (length < static_cast<DWORD>(buf.size()))
0049 break;
0050 buf.resize(buf.size() * 2);
0051 }
0052 return std::string(buf.data(), length);
0053 #else
0054 basic_buffer<char> buf(pathconf(".", _PC_PATH_MAX));
0055 if (!getcwd(buf.data(), static_cast<size_t>(buf.size())))
0056 throw_system_failure("failed determining current directory");
0057 return std::string(buf.data());
0058 #endif
0059 }
0060
0061 } } }
0062
0063 #include <boost/iostreams/detail/config/enable_warnings.hpp>
0064
0065 #endif