1// Filesystem declarations -*- C++ -*-
2
3// Copyright (C) 2014-2024 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;
61 class directory_iterator;
62 class recursive_directory_iterator;
63_GLIBCXX_END_NAMESPACE_CXX11
64
65 /// Information about free space on a disk
66 struct space_info
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 enum class perms : unsigned {
145 none = 0,
146 owner_read = 0400,
147 owner_write = 0200,
148 owner_exec = 0100,
149 owner_all = 0700,
150 group_read = 040,
151 group_write = 020,
152 group_exec = 010,
153 group_all = 070,
154 others_read = 04,
155 others_write = 02,
156 others_exec = 01,
157 others_all = 07,
158 all = 0777,
159 set_uid = 04000,
160 set_gid = 02000,
161 sticky_bit = 01000,
162 mask = 07777,
163 unknown = 0xFFFF,
164 };
165
166 /// @{
167 /// @relates perms
168 [[nodiscard]]
169 constexpr perms
170 operator&(perms __x, perms __y) noexcept
171 {
172 using __utype = typename std::underlying_type<perms>::type;
173 return static_cast<perms>(
174 static_cast<__utype>(__x) & static_cast<__utype>(__y));
175 }
176
177 [[nodiscard]]
178 constexpr perms
179 operator|(perms __x, perms __y) noexcept
180 {
181 using __utype = typename std::underlying_type<perms>::type;
182 return static_cast<perms>(
183 static_cast<__utype>(__x) | static_cast<__utype>(__y));
184 }
185
186 [[nodiscard]]
187 constexpr perms
188 operator^(perms __x, perms __y) noexcept
189 {
190 using __utype = typename std::underlying_type<perms>::type;
191 return static_cast<perms>(
192 static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
193 }
194
195 [[nodiscard]]
196 constexpr perms
197 operator~(perms __x) noexcept
198 {
199 using __utype = typename std::underlying_type<perms>::type;
200 return static_cast<perms>(~static_cast<__utype>(__x));
201 }
202
203 inline perms&
204 operator&=(perms& __x, perms __y) noexcept
205 { return __x = __x & __y; }
206
207 inline perms&
208 operator|=(perms& __x, perms __y) noexcept
209 { return __x = __x | __y; }
210
211 inline perms&
212 operator^=(perms& __x, perms __y) noexcept
213 { return __x = __x ^ __y; }
214 /// @}
215
216 /// Bitmask type controlling changes to permissions
217 enum class perm_options : unsigned {
218 replace = 0x1,
219 add = 0x2,
220 remove = 0x4,
221 nofollow = 0x8
222 };
223
224 /// @{
225 /// @relates perm_options
226 [[nodiscard]]
227 constexpr perm_options
228 operator&(perm_options __x, perm_options __y) noexcept
229 {
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));
233 }
234
235 [[nodiscard]]
236 constexpr perm_options
237 operator|(perm_options __x, perm_options __y) noexcept
238 {
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));
242 }
243
244 [[nodiscard]]
245 constexpr perm_options
246 operator^(perm_options __x, perm_options __y) noexcept
247 {
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));
251 }
252
253 [[nodiscard]]
254 constexpr perm_options
255 operator~(perm_options __x) noexcept
256 {
257 using __utype = typename std::underlying_type<perm_options>::type;
258 return static_cast<perm_options>(~static_cast<__utype>(__x));
259 }
260
261 inline perm_options&
262 operator&=(perm_options& __x, perm_options __y) noexcept
263 { return __x = __x & __y; }
264
265 inline perm_options&
266 operator|=(perm_options& __x, perm_options __y) noexcept
267 { return __x = __x | __y; }
268
269 inline perm_options&
270 operator^=(perm_options& __x, perm_options __y) noexcept
271 { return __x = __x ^ __y; }
272 /// @}
273
274 /// Bitmask type controlling directory iteration
275 enum class directory_options : unsigned char {
276 none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
277 };
278
279 /// @{
280 /// @relates directory_options
281 [[nodiscard]]
282 constexpr directory_options
283 operator&(directory_options __x, directory_options __y) noexcept
284 {
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));
288 }
289
290 [[nodiscard]]
291 constexpr directory_options
292 operator|(directory_options __x, directory_options __y) noexcept
293 {
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));
297 }
298
299 [[nodiscard]]
300 constexpr directory_options
301 operator^(directory_options __x, directory_options __y) noexcept
302 {
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));
306 }
307
308 [[nodiscard]]
309 constexpr directory_options
310 operator~(directory_options __x) noexcept
311 {
312 using __utype = typename std::underlying_type<directory_options>::type;
313 return static_cast<directory_options>(~static_cast<__utype>(__x));
314 }
315
316 inline directory_options&
317 operator&=(directory_options& __x, directory_options __y) noexcept
318 { return __x = __x & __y; }
319
320 inline directory_options&
321 operator|=(directory_options& __x, directory_options __y) noexcept
322 { return __x = __x | __y; }
323
324 inline directory_options&
325 operator^=(directory_options& __x, directory_options __y) noexcept
326 { return __x = __x ^ __y; }
327 /// @}
328
329 /// The type used for file timestamps
330 using file_time_type = __file_clock::time_point;
331
332 // operational functions
333
334 void copy(const path& __from, const path& __to, copy_options __options);
335 void copy(const path& __from, const path& __to, copy_options __options,
336 error_code&);
337
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,
340 error_code&);
341
342 path current_path();
343
344 bool exists(file_status) noexcept;
345
346 bool is_other(file_status) noexcept;
347
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;
354
355 void permissions(const path&, perms, perm_options, error_code&) noexcept;
356
357 path proximate(const path& __p, const path& __base, error_code& __ec);
358 path proximate(const path& __p, const path& __base, error_code& __ec);
359
360 path relative(const path& __p, const path& __base, error_code& __ec);
361
362 file_status status(const path&);
363 file_status status(const path&, error_code&) noexcept;
364
365 bool status_known(file_status) noexcept;
366
367 file_status symlink_status(const path&);
368 file_status symlink_status(const path&, error_code&) noexcept;
369
370 bool is_regular_file(file_status) noexcept;
371 bool is_symlink(file_status) noexcept;
372
373 bool remove(const path&, error_code&) noexcept;
374 uintmax_t remove_all(const path&);
375 uintmax_t remove_all(const path&, error_code&);
376
377/// @}
378} // namespace filesystem
379_GLIBCXX_END_NAMESPACE_VERSION
380} // namespace std
381#endif // C++17
382#endif // _GLIBCXX_FS_FWD_H
383