Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / filesystem / src / windows_tools.hpp
1 //  windows_tools.hpp  -----------------------------------------------------------------//
2
3 //  Copyright 2002-2009, 2014 Beman Dawes
4 //  Copyright 2001 Dietmar Kuehl
5
6 //  Distributed under the Boost Software License, Version 1.0.
7 //  See http://www.boost.org/LICENSE_1_0.txt
8
9 //  See library home page at http://www.boost.org/libs/filesystem
10
11 //--------------------------------------------------------------------------------------//
12
13 #ifndef BOOST_FILESYSTEM_SRC_WINDOWS_TOOLS_HPP_
14 #define BOOST_FILESYSTEM_SRC_WINDOWS_TOOLS_HPP_
15
16 #include <boost/filesystem/path.hpp>
17 #include <boost/filesystem/file_status.hpp>
18
19 #include <windows.h>
20
21 namespace boost {
22 namespace filesystem {
23 namespace detail {
24
25 inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5])
26 {
27   return
28     (p[0] == x1[0] || p[0] == x2[0]) &&
29     (p[1] == x1[1] || p[1] == x2[1]) &&
30     (p[2] == x1[2] || p[2] == x2[2]) &&
31     (p[3] == x1[3] || p[3] == x2[3]) &&
32     p[4] == 0;
33 }
34
35 inline boost::filesystem::perms make_permissions(const boost::filesystem::path& p, DWORD attr)
36 {
37   boost::filesystem::perms prms = boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read;
38   if  ((attr & FILE_ATTRIBUTE_READONLY) == 0u)
39     prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
40   boost::filesystem::path ext = p.extension();
41   wchar_t const* q = ext.c_str();
42   if (equal_extension(q, L".exe", L".EXE")
43     || equal_extension(q, L".com", L".COM")
44     || equal_extension(q, L".bat", L".BAT")
45     || equal_extension(q, L".cmd", L".CMD"))
46     prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
47   return prms;
48 }
49
50 } // namespace detail
51 } // namespace filesystem
52 } // namespace boost
53
54 #endif // BOOST_FILESYSTEM_SRC_WINDOWS_TOOLS_HPP_