Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:08

0001 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
0002 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
0003 // Copyright (c) 2009 Boris Schaeling
0004 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
0005 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef BOOST_PROCESS_WINDOWS_SEARCH_PATH_HPP
0011 #define BOOST_PROCESS_WINDOWS_SEARCH_PATH_HPP
0012 
0013 #include <boost/process/detail/config.hpp>
0014 #include <boost/process/filesystem.hpp>
0015 #include <boost/system/error_code.hpp>
0016 #include <string>
0017 #include <stdexcept>
0018 #include <array>
0019 #include <atomic>
0020 #include <cstdlib>
0021 #include <boost/winapi/shell.hpp>
0022 #include <boost/process/environment.hpp>
0023 
0024 namespace boost { namespace process { namespace detail { namespace windows {
0025 
0026 inline boost::process::filesystem::path search_path(
0027         const boost::process::filesystem::path &filename,
0028         const std::vector<boost::process::filesystem::path> &path)
0029 {
0030     const ::boost::process::wnative_environment ne{};
0031     typedef typename ::boost::process::wnative_environment::const_entry_type value_type;
0032     const auto id = L"PATHEXT";
0033 
0034     auto itr = std::find_if(ne.cbegin(), ne.cend(),
0035             [&](const value_type & e)
0036              {return id == ::boost::to_upper_copy(e.get_name(), ::boost::process::detail::process_locale());});
0037 
0038     std::vector<std::wstring> extensions_in;
0039     if (itr != ne.cend())
0040         extensions_in = itr->to_vector();
0041 
0042     std::vector<std::wstring> extensions((extensions_in.size() * 2) + 1);
0043 
0044     auto it_ex = extensions.begin();
0045     it_ex++;
0046     it_ex = std::transform(extensions_in.begin(), extensions_in.end(), it_ex,
0047                 [](const std::wstring & ws){return boost::to_lower_copy(ws, ::boost::process::detail::process_locale());});
0048 
0049     std::transform(extensions_in.begin(), extensions_in.end(), it_ex,
0050                 [](const std::wstring & ws){return boost::to_upper_copy(ws, ::boost::process::detail::process_locale());});
0051 
0052 
0053     std::copy(std::make_move_iterator(extensions_in.begin()), std::make_move_iterator(extensions_in.end()), extensions.begin() + 1);
0054 
0055 
0056     for (auto & ext : extensions)
0057         boost::to_lower(ext);
0058 
0059     for (const boost::process::filesystem::path & pp_ : path)
0060     {
0061         auto p = pp_ / filename;
0062         for (boost::process::filesystem::path ext : extensions)
0063         {
0064             boost::process::filesystem::path pp_ext = p;
0065             pp_ext += ext;
0066 #if defined(BOOST_PROCESS_USE_STD_FS)
0067             std::error_code ec;
0068 #else
0069             boost::system::error_code ec;
0070 #endif
0071             bool file = boost::process::filesystem::is_regular_file(pp_ext, ec);
0072             if (!ec && file &&
0073                 ::boost::winapi::sh_get_file_info(pp_ext.native().c_str(), 0, 0, 0, ::boost::winapi::SHGFI_EXETYPE_))
0074             {
0075                 return pp_ext;
0076             }
0077         }
0078     }
0079     return "";
0080 }
0081 
0082 }}}}
0083 
0084 #endif