Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:10:08

0001 //  boost/filesystem/file_status.hpp  --------------------------------------------------//
0002 
0003 //  Copyright Beman Dawes 2002-2009
0004 //  Copyright Jan Langer 2002
0005 //  Copyright Dietmar Kuehl 2001
0006 //  Copyright Vladimir Prus 2002
0007 //  Copyright Andrey Semashev 2019
0008 
0009 //  Distributed under the Boost Software License, Version 1.0.
0010 //  See http://www.boost.org/LICENSE_1_0.txt
0011 
0012 //  Library home page: http://www.boost.org/libs/filesystem
0013 
0014 //--------------------------------------------------------------------------------------//
0015 
0016 #ifndef BOOST_FILESYSTEM_FILE_STATUS_HPP
0017 #define BOOST_FILESYSTEM_FILE_STATUS_HPP
0018 
0019 #include <boost/filesystem/config.hpp>
0020 #include <boost/detail/bitmask.hpp>
0021 
0022 #include <boost/filesystem/detail/header.hpp> // must be the last #include
0023 
0024 //--------------------------------------------------------------------------------------//
0025 
0026 namespace boost {
0027 namespace filesystem {
0028 
0029 //--------------------------------------------------------------------------------------//
0030 //                                     file_type                                        //
0031 //--------------------------------------------------------------------------------------//
0032 
0033 enum file_type
0034 {
0035     status_error,
0036     file_not_found,
0037     regular_file,
0038     directory_file,
0039     // the following may not apply to some operating systems or file systems
0040     symlink_file,
0041     block_file,
0042     character_file,
0043     fifo_file,
0044     socket_file,
0045     reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
0046     type_unknown  // file does exist, but isn't one of the above types or
0047                   // we don't have strong enough permission to find its type
0048 };
0049 
0050 //--------------------------------------------------------------------------------------//
0051 //                                       perms                                          //
0052 //--------------------------------------------------------------------------------------//
0053 
0054 enum perms
0055 {
0056     no_perms = 0, // file_not_found is no_perms rather than perms_not_known
0057 
0058     // POSIX equivalent macros given in comments.
0059     // Values are from POSIX and are given in octal per the POSIX standard.
0060 
0061     // permission bits
0062 
0063     owner_read = 0400,  // S_IRUSR, Read permission, owner
0064     owner_write = 0200, // S_IWUSR, Write permission, owner
0065     owner_exe = 0100,   // S_IXUSR, Execute/search permission, owner
0066     owner_all = 0700,   // S_IRWXU, Read, write, execute/search by owner
0067 
0068     group_read = 040,  // S_IRGRP, Read permission, group
0069     group_write = 020, // S_IWGRP, Write permission, group
0070     group_exe = 010,   // S_IXGRP, Execute/search permission, group
0071     group_all = 070,   // S_IRWXG, Read, write, execute/search by group
0072 
0073     others_read = 04,  // S_IROTH, Read permission, others
0074     others_write = 02, // S_IWOTH, Write permission, others
0075     others_exe = 01,   // S_IXOTH, Execute/search permission, others
0076     others_all = 07,   // S_IRWXO, Read, write, execute/search by others
0077 
0078     all_all = 0777, // owner_all|group_all|others_all
0079 
0080     // other POSIX bits
0081 
0082     set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
0083     set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
0084     sticky_bit = 01000,     // S_ISVTX,
0085                             // (POSIX XSI) On directories, restricted deletion flag
0086                             // (V7) 'sticky bit': save swapped text even after use
0087                             // (SunOS) On non-directories: don't cache this file
0088                             // (SVID-v4.2) On directories: restricted deletion flag
0089                             // Also see http://en.wikipedia.org/wiki/Sticky_bit
0090 
0091     perms_mask = 07777, // all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit
0092 
0093     perms_not_known = 0xFFFF, // present when directory_entry cache not loaded
0094 
0095     // options for permissions() function
0096 
0097     add_perms = 0x1000,    // adds the given permission bits to the current bits
0098     remove_perms = 0x2000, // removes the given permission bits from the current bits;
0099                            // choose add_perms or remove_perms, not both; if neither add_perms
0100                            // nor remove_perms is given, replace the current bits with
0101                            // the given bits.
0102 
0103     symlink_perms = 0x4000, // on POSIX, don't resolve symlinks; implied on Windows
0104 
0105     // BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values
0106     _detail_extend_perms_32_1 = 0x7fffffff,
0107     _detail_extend_perms_32_2 = -0x7fffffff - 1
0108 };
0109 
0110 BOOST_BITMASK(perms)
0111 
0112 //--------------------------------------------------------------------------------------//
0113 //                                    file_status                                       //
0114 //--------------------------------------------------------------------------------------//
0115 
0116 class file_status
0117 {
0118 public:
0119     BOOST_CONSTEXPR file_status() noexcept :
0120         m_value(status_error),
0121         m_perms(perms_not_known)
0122     {
0123     }
0124     explicit BOOST_CONSTEXPR file_status(file_type v) noexcept :
0125         m_value(v),
0126         m_perms(perms_not_known)
0127     {
0128     }
0129     BOOST_CONSTEXPR file_status(file_type v, perms prms) noexcept :
0130         m_value(v),
0131         m_perms(prms)
0132     {
0133     }
0134 
0135     BOOST_CONSTEXPR file_status(file_status const& rhs) noexcept :
0136         m_value(rhs.m_value),
0137         m_perms(rhs.m_perms)
0138     {
0139     }
0140     BOOST_CXX14_CONSTEXPR file_status& operator=(file_status const& rhs) noexcept
0141     {
0142         m_value = rhs.m_value;
0143         m_perms = rhs.m_perms;
0144         return *this;
0145     }
0146 
0147     // Note: std::move is not constexpr in C++11, that's why we're not using it here
0148     BOOST_CONSTEXPR file_status(file_status&& rhs) noexcept :
0149         m_value(static_cast< file_type&& >(rhs.m_value)),
0150         m_perms(static_cast< perms&& >(rhs.m_perms))
0151     {
0152     }
0153     BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) noexcept
0154     {
0155         m_value = static_cast< file_type&& >(rhs.m_value);
0156         m_perms = static_cast< perms&& >(rhs.m_perms);
0157         return *this;
0158     }
0159 
0160     // observers
0161     BOOST_CONSTEXPR file_type type() const noexcept { return m_value; }
0162     BOOST_CONSTEXPR perms permissions() const noexcept { return m_perms; }
0163 
0164     // modifiers
0165     BOOST_CXX14_CONSTEXPR void type(file_type v) noexcept { m_value = v; }
0166     BOOST_CXX14_CONSTEXPR void permissions(perms prms) noexcept { m_perms = prms; }
0167 
0168     BOOST_CONSTEXPR bool operator==(file_status const& rhs) const noexcept
0169     {
0170         return type() == rhs.type() && permissions() == rhs.permissions();
0171     }
0172     BOOST_CONSTEXPR bool operator!=(file_status const& rhs) const noexcept
0173     {
0174         return !(*this == rhs);
0175     }
0176 
0177 private:
0178     file_type m_value;
0179     perms m_perms;
0180 };
0181 
0182 inline BOOST_CONSTEXPR bool type_present(file_status f) noexcept
0183 {
0184     return f.type() != filesystem::status_error;
0185 }
0186 
0187 inline BOOST_CONSTEXPR bool permissions_present(file_status f) noexcept
0188 {
0189     return f.permissions() != filesystem::perms_not_known;
0190 }
0191 
0192 inline BOOST_CONSTEXPR bool status_known(file_status f) noexcept
0193 {
0194     return filesystem::type_present(f) && filesystem::permissions_present(f);
0195 }
0196 
0197 inline BOOST_CONSTEXPR bool exists(file_status f) noexcept
0198 {
0199     return f.type() != filesystem::status_error && f.type() != filesystem::file_not_found;
0200 }
0201 
0202 inline BOOST_CONSTEXPR bool is_regular_file(file_status f) noexcept
0203 {
0204     return f.type() == filesystem::regular_file;
0205 }
0206 
0207 inline BOOST_CONSTEXPR bool is_directory(file_status f) noexcept
0208 {
0209     return f.type() == filesystem::directory_file;
0210 }
0211 
0212 inline BOOST_CONSTEXPR bool is_symlink(file_status f) noexcept
0213 {
0214     return f.type() == filesystem::symlink_file;
0215 }
0216 
0217 inline BOOST_CONSTEXPR bool is_block_file(file_status f) noexcept
0218 {
0219     return f.type() == filesystem::block_file;
0220 }
0221 
0222 inline BOOST_CONSTEXPR bool is_character_file(file_status f) noexcept
0223 {
0224     return f.type() == filesystem::character_file;
0225 }
0226 
0227 inline BOOST_CONSTEXPR bool is_fifo(file_status f) noexcept
0228 {
0229     return f.type() == filesystem::fifo_file;
0230 }
0231 
0232 inline BOOST_CONSTEXPR bool is_socket(file_status f) noexcept
0233 {
0234     return f.type() == filesystem::socket_file;
0235 }
0236 
0237 inline BOOST_CONSTEXPR bool is_reparse_file(file_status f) noexcept
0238 {
0239     return f.type() == filesystem::reparse_file;
0240 }
0241 
0242 inline BOOST_CONSTEXPR bool is_other(file_status f) noexcept
0243 {
0244     return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
0245 }
0246 
0247 } // namespace filesystem
0248 } // namespace boost
0249 
0250 #include <boost/filesystem/detail/footer.hpp> // pops abi_prefix.hpp pragmas
0251 
0252 #endif // BOOST_FILESYSTEM_FILE_STATUS_HPP