2 * Distributed under the Boost Software License, Version 1.0.(See accompanying
3 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 * See http://www.boost.org/libs/iostreams for documentation.
7 * File: boost/iostreams/detail/execute.hpp
8 * Date: Thu Dec 06 13:21:54 MST 2007
9 * Copyright: 2007-2008 CodeRage, LLC
10 * Author: Jonathan Turkanis
11 * Contact: turkanis at coderage dot com
13 * Defines the function boost::iostreams::detail::current_directory, used by
14 * boost::iostreams::detail::absolute_path.
17 #ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
18 #define BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
20 #include <boost/config.hpp> // make sure size_t is in std.
21 #include <cstddef> // size_t
23 #include <boost/iostreams/detail/buffer.hpp>
24 #include <boost/iostreams/detail/config/windows_posix.hpp>
25 #include <boost/iostreams/detail/system_failure.hpp>
26 #ifdef BOOST_IOSTREAMS_WINDOWS
27 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
30 # include <unistd.h> // sysconf.
34 #include <boost/iostreams/detail/config/disable_warnings.hpp>
36 namespace boost
{ namespace iostreams
{ namespace detail
{
38 // Returns the current working directory
39 inline std::string
current_directory()
41 #ifdef BOOST_IOSTREAMS_WINDOWS
43 basic_buffer
<char> buf(MAX_PATH
);
45 length
= ::GetCurrentDirectoryA(buf
.size(), buf
.data());
47 throw_system_failure("failed determining current directory");
48 if (length
< static_cast<DWORD
>(buf
.size()))
50 buf
.resize(buf
.size() * 2);
52 return std::string(buf
.data(), length
);
53 #else // #ifdef BOOST_IOSTREAMS_WINDOWS
54 basic_buffer
<char> buf(pathconf(".", _PC_PATH_MAX
));
55 if (!getcwd(buf
.data(), static_cast<size_t>(buf
.size())))
56 throw_system_failure("failed determining current directory");
57 return std::string(buf
.data());
58 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS
61 } } } // End namespaces detail, iostreams, boost.
63 #include <boost/iostreams/detail/config/enable_warnings.hpp>
65 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED