libstdc++
bits/fs_fwd.h
Go to the documentation of this file.
1// Filesystem declarations -*- C++ -*-
2
3// Copyright (C) 2014-2026 Free Software Foundation, Inc.
4//
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)
9// any later version.
10
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.
15
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.
19
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/>.
24
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}
28 */
29
30#ifndef _GLIBCXX_FS_FWD_H
31#define _GLIBCXX_FS_FWD_H 1
32
33#if __cplusplus >= 201703L
34
35#include <system_error>
36#include <cstdint>
37#include <bits/chrono.h>
38
39namespace std _GLIBCXX_VISIBILITY(default)
40{
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
42
43/// ISO C++ 2017 namespace for File System library
44namespace filesystem
45{
46#if _GLIBCXX_USE_CXX11_ABI
47/// @cond undocumented
48inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
49/// @endcond
50#endif
51
52/** @addtogroup filesystem
53 * @{
54 */
55
56 class file_status;
57_GLIBCXX_BEGIN_NAMESPACE_CXX11
58 class path;
59 class filesystem_error;
60 class directory_entry;
63_GLIBCXX_END_NAMESPACE_CXX11
64
65 /// Information about free space on a disk
67 {
68 uintmax_t capacity;
69 uintmax_t free;
70 uintmax_t available;
71
72#if __cpp_impl_three_way_comparison >= 201907L
73 friend bool operator==(const space_info&, const space_info&) = default;
74#endif
75 };
76
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
81 };
82
83 /// Bitmask type controlling effects of `filesystem::copy`
84 enum class copy_options : unsigned short {
85 none = 0,
86 skip_existing = 1, overwrite_existing = 2, update_existing = 4,
87 recursive = 8,
88 copy_symlinks = 16, skip_symlinks = 32,
89 directories_only = 64, create_symlinks = 128, create_hard_links = 256
90 };
91
92 /// @{
93 /// @relates copy_options
94 [[nodiscard]]
95 constexpr copy_options
96 operator&(copy_options __x, copy_options __y) noexcept
97 {
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));
101 }
102
103 [[nodiscard]]
104 constexpr copy_options
105 operator|(copy_options __x, copy_options __y) noexcept
106 {
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));
110 }
111
112 [[nodiscard]]
113 constexpr copy_options
114 operator^(copy_options __x, copy_options __y) noexcept
115 {
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));
119 }
120
121 [[nodiscard]]
122 constexpr copy_options
123 operator~(copy_options __x) noexcept
124 {
125 using __utype = typename std::underlying_type<copy_options>::type;
126 return static_cast<copy_options>(~static_cast<__utype>(__x));
127 }
128
129 inline copy_options&
130 operator&=(copy_options& __x, copy_options __y) noexcept
131 { return __x = __x & __y; }
132
133 inline copy_options&
134 operator|=(copy_options& __x, copy_options __y) noexcept
135 { return __x = __x | __y; }
136
137 inline copy_options&
138 operator^=(copy_options& __x, copy_options __y) noexcept
139 { return __x = __x ^ __y; }
140 /// @}
141
142
143 /// Bitmask type representing file access permissions
144#pragma GCC diagnostic push
145#pragma GCC diagnostic ignored "-Wdeprecated-octal-literal"
146 enum class perms : unsigned {
147 none = 0,
148 owner_read = 0400,
149 owner_write = 0200,
150 owner_exec = 0100,
151 owner_all = 0700,
152 group_read = 040,
153 group_write = 020,
154 group_exec = 010,
155 group_all = 070,
156 others_read = 04,
157 others_write = 02,
158 others_exec = 01,
159 others_all = 07,
160 all = 0777,
161 set_uid = 04000,
162 set_gid = 02000,
163 sticky_bit = 01000,
164 mask = 07777,
165 unknown = 0xFFFF,
166 };
167#pragma GCC diagnostic pop
168
169 /// @{
170 /// @relates perms
171 [[nodiscard]]
172 constexpr perms
173 operator&(perms __x, perms __y) noexcept
174 {
175 using __utype = typename std::underlying_type<perms>::type;
176 return static_cast<perms>(
177 static_cast<__utype>(__x) & static_cast<__utype>(__y));
178 }
179
180 [[nodiscard]]
181 constexpr perms
182 operator|(perms __x, perms __y) noexcept
183 {
184 using __utype = typename std::underlying_type<perms>::type;
185 return static_cast<perms>(
186 static_cast<__utype>(__x) | static_cast<__utype>(__y));
187 }
188
189 [[nodiscard]]
190 constexpr perms
191 operator^(perms __x, perms __y) noexcept
192 {
193 using __utype = typename std::underlying_type<perms>::type;
194 return static_cast<perms>(
195 static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
196 }
197
198 [[nodiscard]]
199 constexpr perms
200 operator~(perms __x) noexcept
201 {
202 using __utype = typename std::underlying_type<perms>::type;
203 return static_cast<perms>(~static_cast<__utype>(__x));
204 }
205
206 inline perms&
207 operator&=(perms& __x, perms __y) noexcept
208 { return __x = __x & __y; }
209
210 inline perms&
211 operator|=(perms& __x, perms __y) noexcept
212 { return __x = __x | __y; }
213
214 inline perms&
215 operator^=(perms& __x, perms __y) noexcept
216 { return __x = __x ^ __y; }
217 /// @}
218
219 /// Bitmask type controlling changes to permissions
220 enum class perm_options : unsigned {
221 replace = 0x1,
222 add = 0x2,
223 remove = 0x4,
224 nofollow = 0x8
225 };
226
227 /// @{
228 /// @relates perm_options
229 [[nodiscard]]
230 constexpr perm_options
231 operator&(perm_options __x, perm_options __y) noexcept
232 {
233 using __utype = typename std::underlying_type<perm_options>::type;
234 return static_cast<perm_options>(
235 static_cast<__utype>(__x) & static_cast<__utype>(__y));
236 }
237
238 [[nodiscard]]
239 constexpr perm_options
240 operator|(perm_options __x, perm_options __y) noexcept
241 {
242 using __utype = typename std::underlying_type<perm_options>::type;
243 return static_cast<perm_options>(
244 static_cast<__utype>(__x) | static_cast<__utype>(__y));
245 }
246
247 [[nodiscard]]
248 constexpr perm_options
249 operator^(perm_options __x, perm_options __y) noexcept
250 {
251 using __utype = typename std::underlying_type<perm_options>::type;
252 return static_cast<perm_options>(
253 static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
254 }
255
256 [[nodiscard]]
257 constexpr perm_options
258 operator~(perm_options __x) noexcept
259 {
260 using __utype = typename std::underlying_type<perm_options>::type;
261 return static_cast<perm_options>(~static_cast<__utype>(__x));
262 }
263
264 inline perm_options&
265 operator&=(perm_options& __x, perm_options __y) noexcept
266 { return __x = __x & __y; }
267
268 inline perm_options&
269 operator|=(perm_options& __x, perm_options __y) noexcept
270 { return __x = __x | __y; }
271
272 inline perm_options&
273 operator^=(perm_options& __x, perm_options __y) noexcept
274 { return __x = __x ^ __y; }
275 /// @}
276
277 /// Bitmask type controlling directory iteration
278 enum class directory_options : unsigned char {
279 none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
280 };
281
282 /// @{
283 /// @relates directory_options
284 [[nodiscard]]
285 constexpr directory_options
286 operator&(directory_options __x, directory_options __y) noexcept
287 {
288 using __utype = typename std::underlying_type<directory_options>::type;
289 return static_cast<directory_options>(
290 static_cast<__utype>(__x) & static_cast<__utype>(__y));
291 }
292
293 [[nodiscard]]
294 constexpr directory_options
295 operator|(directory_options __x, directory_options __y) noexcept
296 {
297 using __utype = typename std::underlying_type<directory_options>::type;
298 return static_cast<directory_options>(
299 static_cast<__utype>(__x) | static_cast<__utype>(__y));
300 }
301
302 [[nodiscard]]
303 constexpr directory_options
304 operator^(directory_options __x, directory_options __y) noexcept
305 {
306 using __utype = typename std::underlying_type<directory_options>::type;
307 return static_cast<directory_options>(
308 static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
309 }
310
311 [[nodiscard]]
312 constexpr directory_options
313 operator~(directory_options __x) noexcept
314 {
315 using __utype = typename std::underlying_type<directory_options>::type;
316 return static_cast<directory_options>(~static_cast<__utype>(__x));
317 }
318
319 inline directory_options&
320 operator&=(directory_options& __x, directory_options __y) noexcept
321 { return __x = __x & __y; }
322
323 inline directory_options&
324 operator|=(directory_options& __x, directory_options __y) noexcept
325 { return __x = __x | __y; }
326
327 inline directory_options&
328 operator^=(directory_options& __x, directory_options __y) noexcept
329 { return __x = __x ^ __y; }
330 /// @}
331
332 /// The type used for file timestamps
333 using file_time_type = __file_clock::time_point;
334
335 // operational functions
336
337 void copy(const path& __from, const path& __to, copy_options __options);
338 void copy(const path& __from, const path& __to, copy_options __options,
339 error_code&);
340
341 bool copy_file(const path& __from, const path& __to, copy_options __option);
342 bool copy_file(const path& __from, const path& __to, copy_options __option,
343 error_code&);
344
345 path current_path();
346
347 bool exists(file_status) noexcept;
348
349 bool is_other(file_status) noexcept;
350
351 uintmax_t file_size(const path&);
352 uintmax_t file_size(const path&, error_code&) noexcept;
353 uintmax_t hard_link_count(const path&);
354 uintmax_t hard_link_count(const path&, error_code&) noexcept;
355 file_time_type last_write_time(const path&);
356 file_time_type last_write_time(const path&, error_code&) noexcept;
357
358 void permissions(const path&, perms, perm_options, error_code&) noexcept;
359
360 path proximate(const path& __p, const path& __base, error_code& __ec);
361 path proximate(const path& __p, const path& __base, error_code& __ec);
362
363 path relative(const path& __p, const path& __base, error_code& __ec);
364
365 file_status status(const path&);
366 file_status status(const path&, error_code&) noexcept;
367
368 bool status_known(file_status) noexcept;
369
370 file_status symlink_status(const path&);
371 file_status symlink_status(const path&, error_code&) noexcept;
372
373 bool is_regular_file(file_status) noexcept;
374 bool is_symlink(file_status) noexcept;
375
376 bool remove(const path&, error_code&) noexcept;
377 uintmax_t remove_all(const path&);
378 uintmax_t remove_all(const path&, error_code&);
379
380/// @}
381} // namespace filesystem
382_GLIBCXX_END_NAMESPACE_VERSION
383} // namespace std
384#endif // C++17
385#endif // _GLIBCXX_FS_FWD_H
copy_options
Bitmask type controlling effects of filesystem::copy.
Definition bits/fs_fwd.h:84
perms
Bitmask type representing file access permissions.
perm_options
Bitmask type controlling changes to permissions.
directory_options
Bitmask type controlling directory iteration.
__file_clock::time_point file_time_type
The type used for file timestamps.
file_type
Enumerated type representing the type of a file.
Definition bits/fs_fwd.h:78
ISO C++ entities toplevel namespace is std.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1662
ISO C++ 2017 namespace for File System library.
Definition chrono.h:58
The underlying type of an enum.
Definition type_traits:2728
Information about a file's type and permissions.
Definition bits/fs_dir.h:61
The value type used by directory iterators.
Iterator type for traversing the entries in a single directory.
Iterator type for recursively traversing a directory hierarchy.
Information about free space on a disk.
Definition bits/fs_fwd.h:67
A filesystem path.
Exception type thrown by the Filesystem library.