Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:49

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.(See accompanying 
0003  * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0004  * 
0005  * See http://www.boost.org/libs/iostreams for documentation.
0006 
0007  * File:        boost/iostreams/detail/execute.hpp
0008  * Date:        Thu Dec 06 13:21:54 MST 2007
0009  * Copyright:   2007-2008 CodeRage, LLC
0010  * Author:      Jonathan Turkanis
0011  * Contact:     turkanis at coderage dot com
0012  *
0013  * Defines the function boost::iostreams::detail::current_directory, used by 
0014  * boost::iostreams::detail::absolute_path.
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  // Exclude rarely-used stuff from Windows headers
0028 # include <windows.h>
0029 #else
0030 # include <unistd.h>        // sysconf.
0031 #endif
0032 
0033 // Must come last.
0034 #include <boost/iostreams/detail/config/disable_warnings.hpp>
0035 
0036 namespace boost { namespace iostreams { namespace detail {
0037 
0038 // Returns the current working directory
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 // #ifdef BOOST_IOSTREAMS_WINDOWS
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 // #ifdef BOOST_IOSTREAMS_WINDOWS
0059 }
0060 
0061 } } } // End namespaces detail, iostreams, boost.
0062 
0063 #include <boost/iostreams/detail/config/enable_warnings.hpp>
0064 
0065 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED