1 // Filesystem declarations -*- C++ -*-
3 // Copyright (C) 2014-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/bits/fs_fwd.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{filesystem}
30 #ifndef _GLIBCXX_FS_FWD_H
31 #define _GLIBCXX_FS_FWD_H 1
33 #if __cplusplus >= 201703L
35 #include <system_error>
37 #include <bits/chrono.h>
39 namespace std
_GLIBCXX_VISIBILITY(default)
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 /// ISO C++ 2017 namespace for File System library
46 #if _GLIBCXX_USE_CXX11_ABI
47 /// @cond undocumented
48 inline namespace __cxx11
__attribute__((__abi_tag__ ("cxx11"))) { }
52 /** @addtogroup filesystem
57 _GLIBCXX_BEGIN_NAMESPACE_CXX11
59 class filesystem_error
;
60 class directory_entry
;
61 class directory_iterator
;
62 class recursive_directory_iterator
;
63 _GLIBCXX_END_NAMESPACE_CXX11
65 /// Information about free space on a disk
72 #if __cpp_impl_three_way_comparison >= 201907L
73 friend bool operator==(const space_info
&, const space_info
&) = default;
77 /// Enumerated type representing the type of a file
78 enum class file_type
: signed char {
79 none
= 0, not_found
= -1, regular
= 1, directory
= 2, symlink
= 3,
80 block
= 4, character
= 5, fifo
= 6, socket
= 7, unknown
= 8
83 /// Bitmask type controlling effects of `filesystem::copy`
84 enum class copy_options
: unsigned short {
86 skip_existing
= 1, overwrite_existing
= 2, update_existing
= 4,
88 copy_symlinks
= 16, skip_symlinks
= 32,
89 directories_only
= 64, create_symlinks
= 128, create_hard_links
= 256
93 /// @relates copy_options
95 constexpr copy_options
96 operator&(copy_options __x
, copy_options __y
) noexcept
98 using __utype
= typename
std::underlying_type
<copy_options
>::type
;
99 return static_cast<copy_options
>(
100 static_cast<__utype
>(__x
) & static_cast<__utype
>(__y
));
104 constexpr copy_options
105 operator|(copy_options __x
, copy_options __y
) noexcept
107 using __utype
= typename
std::underlying_type
<copy_options
>::type
;
108 return static_cast<copy_options
>(
109 static_cast<__utype
>(__x
) | static_cast<__utype
>(__y
));
113 constexpr copy_options
114 operator^(copy_options __x
, copy_options __y
) noexcept
116 using __utype
= typename
std::underlying_type
<copy_options
>::type
;
117 return static_cast<copy_options
>(
118 static_cast<__utype
>(__x
) ^ static_cast<__utype
>(__y
));
122 constexpr copy_options
123 operator~(copy_options __x
) noexcept
125 using __utype
= typename
std::underlying_type
<copy_options
>::type
;
126 return static_cast<copy_options
>(~static_cast<__utype
>(__x
));
130 operator&=(copy_options
& __x
, copy_options __y
) noexcept
131 { return __x
= __x
& __y
; }
134 operator|=(copy_options
& __x
, copy_options __y
) noexcept
135 { return __x
= __x
| __y
; }
138 operator^=(copy_options
& __x
, copy_options __y
) noexcept
139 { return __x
= __x
^ __y
; }
143 /// Bitmask type representing file access permissions
144 enum class perms
: unsigned {
170 operator&(perms __x
, perms __y
) noexcept
172 using __utype
= typename
std::underlying_type
<perms
>::type
;
173 return static_cast<perms
>(
174 static_cast<__utype
>(__x
) & static_cast<__utype
>(__y
));
179 operator|(perms __x
, perms __y
) noexcept
181 using __utype
= typename
std::underlying_type
<perms
>::type
;
182 return static_cast<perms
>(
183 static_cast<__utype
>(__x
) | static_cast<__utype
>(__y
));
188 operator^(perms __x
, perms __y
) noexcept
190 using __utype
= typename
std::underlying_type
<perms
>::type
;
191 return static_cast<perms
>(
192 static_cast<__utype
>(__x
) ^ static_cast<__utype
>(__y
));
197 operator~(perms __x
) noexcept
199 using __utype
= typename
std::underlying_type
<perms
>::type
;
200 return static_cast<perms
>(~static_cast<__utype
>(__x
));
204 operator&=(perms
& __x
, perms __y
) noexcept
205 { return __x
= __x
& __y
; }
208 operator|=(perms
& __x
, perms __y
) noexcept
209 { return __x
= __x
| __y
; }
212 operator^=(perms
& __x
, perms __y
) noexcept
213 { return __x
= __x
^ __y
; }
216 /// Bitmask type controlling changes to permissions
217 enum class perm_options
: unsigned {
225 /// @relates perm_options
227 constexpr perm_options
228 operator&(perm_options __x
, perm_options __y
) noexcept
230 using __utype
= typename
std::underlying_type
<perm_options
>::type
;
231 return static_cast<perm_options
>(
232 static_cast<__utype
>(__x
) & static_cast<__utype
>(__y
));
236 constexpr perm_options
237 operator|(perm_options __x
, perm_options __y
) noexcept
239 using __utype
= typename
std::underlying_type
<perm_options
>::type
;
240 return static_cast<perm_options
>(
241 static_cast<__utype
>(__x
) | static_cast<__utype
>(__y
));
245 constexpr perm_options
246 operator^(perm_options __x
, perm_options __y
) noexcept
248 using __utype
= typename
std::underlying_type
<perm_options
>::type
;
249 return static_cast<perm_options
>(
250 static_cast<__utype
>(__x
) ^ static_cast<__utype
>(__y
));
254 constexpr perm_options
255 operator~(perm_options __x
) noexcept
257 using __utype
= typename
std::underlying_type
<perm_options
>::type
;
258 return static_cast<perm_options
>(~static_cast<__utype
>(__x
));
262 operator&=(perm_options
& __x
, perm_options __y
) noexcept
263 { return __x
= __x
& __y
; }
266 operator|=(perm_options
& __x
, perm_options __y
) noexcept
267 { return __x
= __x
| __y
; }
270 operator^=(perm_options
& __x
, perm_options __y
) noexcept
271 { return __x
= __x
^ __y
; }
274 /// Bitmask type controlling directory iteration
275 enum class directory_options
: unsigned char {
276 none
= 0, follow_directory_symlink
= 1, skip_permission_denied
= 2
280 /// @relates directory_options
282 constexpr directory_options
283 operator&(directory_options __x
, directory_options __y
) noexcept
285 using __utype
= typename
std::underlying_type
<directory_options
>::type
;
286 return static_cast<directory_options
>(
287 static_cast<__utype
>(__x
) & static_cast<__utype
>(__y
));
291 constexpr directory_options
292 operator|(directory_options __x
, directory_options __y
) noexcept
294 using __utype
= typename
std::underlying_type
<directory_options
>::type
;
295 return static_cast<directory_options
>(
296 static_cast<__utype
>(__x
) | static_cast<__utype
>(__y
));
300 constexpr directory_options
301 operator^(directory_options __x
, directory_options __y
) noexcept
303 using __utype
= typename
std::underlying_type
<directory_options
>::type
;
304 return static_cast<directory_options
>(
305 static_cast<__utype
>(__x
) ^ static_cast<__utype
>(__y
));
309 constexpr directory_options
310 operator~(directory_options __x
) noexcept
312 using __utype
= typename
std::underlying_type
<directory_options
>::type
;
313 return static_cast<directory_options
>(~static_cast<__utype
>(__x
));
316 inline directory_options
&
317 operator&=(directory_options
& __x
, directory_options __y
) noexcept
318 { return __x
= __x
& __y
; }
320 inline directory_options
&
321 operator|=(directory_options
& __x
, directory_options __y
) noexcept
322 { return __x
= __x
| __y
; }
324 inline directory_options
&
325 operator^=(directory_options
& __x
, directory_options __y
) noexcept
326 { return __x
= __x
^ __y
; }
329 /// The type used for file timestamps
330 using file_time_type
= __file_clock::time_point
;
332 // operational functions
334 void copy(const path
& __from
, const path
& __to
, copy_options __options
);
335 void copy(const path
& __from
, const path
& __to
, copy_options __options
,
338 bool copy_file(const path
& __from
, const path
& __to
, copy_options __option
);
339 bool copy_file(const path
& __from
, const path
& __to
, copy_options __option
,
344 bool exists(file_status
) noexcept
;
346 bool is_other(file_status
) noexcept
;
348 uintmax_t file_size(const path
&);
349 uintmax_t file_size(const path
&, error_code
&) noexcept
;
350 uintmax_t hard_link_count(const path
&);
351 uintmax_t hard_link_count(const path
&, error_code
&) noexcept
;
352 file_time_type
last_write_time(const path
&);
353 file_time_type
last_write_time(const path
&, error_code
&) noexcept
;
355 void permissions(const path
&, perms
, perm_options
, error_code
&) noexcept
;
357 path
proximate(const path
& __p
, const path
& __base
, error_code
& __ec
);
358 path
proximate(const path
& __p
, const path
& __base
, error_code
& __ec
);
360 path
relative(const path
& __p
, const path
& __base
, error_code
& __ec
);
362 file_status
status(const path
&);
363 file_status
status(const path
&, error_code
&) noexcept
;
365 bool status_known(file_status
) noexcept
;
367 file_status
symlink_status(const path
&);
368 file_status
symlink_status(const path
&, error_code
&) noexcept
;
370 bool is_regular_file(file_status
) noexcept
;
371 bool is_symlink(file_status
) noexcept
;
373 bool remove(const path
&, error_code
&) noexcept
;
374 uintmax_t remove_all(const path
&);
375 uintmax_t remove_all(const path
&, error_code
&);
378 } // namespace filesystem
379 _GLIBCXX_END_NAMESPACE_VERSION
382 #endif // _GLIBCXX_FS_FWD_H