]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/fs_ops.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / fs_ops.h
CommitLineData
641cb5a6
JW
1// Filesystem operational functions -*- C++ -*-
2
83ffe9cd 3// Copyright (C) 2014-2023 Free Software Foundation, Inc.
641cb5a6
JW
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
1e9c0268 25/** @file include/bits/fs_ops.h
641cb5a6
JW
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_OPS_H
31#define _GLIBCXX_FS_OPS_H 1
32
33#if __cplusplus >= 201703L
34
35#include <cstdint>
36
37namespace std _GLIBCXX_VISIBILITY(default)
38{
39_GLIBCXX_BEGIN_NAMESPACE_VERSION
40
41namespace filesystem
42{
d727fdc4
JW
43 /** @addtogroup filesystem
44 * @{
641cb5a6
JW
45 */
46
f7a14830 47 [[nodiscard]]
641cb5a6 48 path absolute(const path& __p);
f7a14830
JW
49
50 [[nodiscard]]
641cb5a6
JW
51 path absolute(const path& __p, error_code& __ec);
52
f7a14830 53 [[nodiscard]]
641cb5a6 54 path canonical(const path& __p);
f7a14830
JW
55
56 [[nodiscard]]
641cb5a6
JW
57 path canonical(const path& __p, error_code& __ec);
58
59 inline void
60 copy(const path& __from, const path& __to)
61 { copy(__from, __to, copy_options::none); }
62
63 inline void
29453a9f 64 copy(const path& __from, const path& __to, error_code& __ec)
641cb5a6
JW
65 { copy(__from, __to, copy_options::none, __ec); }
66
67 void copy(const path& __from, const path& __to, copy_options __options);
68 void copy(const path& __from, const path& __to, copy_options __options,
29453a9f 69 error_code& __ec);
641cb5a6
JW
70
71 inline bool
72 copy_file(const path& __from, const path& __to)
73 { return copy_file(__from, __to, copy_options::none); }
74
75 inline bool
29453a9f 76 copy_file(const path& __from, const path& __to, error_code& __ec)
641cb5a6
JW
77 { return copy_file(__from, __to, copy_options::none, __ec); }
78
79 bool copy_file(const path& __from, const path& __to, copy_options __option);
80 bool copy_file(const path& __from, const path& __to, copy_options __option,
29453a9f 81 error_code& __ec);
641cb5a6
JW
82
83 void copy_symlink(const path& __existing_symlink, const path& __new_symlink);
84 void copy_symlink(const path& __existing_symlink, const path& __new_symlink,
85 error_code& __ec) noexcept;
86
87 bool create_directories(const path& __p);
29453a9f 88 bool create_directories(const path& __p, error_code& __ec);
641cb5a6
JW
89
90 bool create_directory(const path& __p);
91 bool create_directory(const path& __p, error_code& __ec) noexcept;
92
93 bool create_directory(const path& __p, const path& attributes);
94 bool create_directory(const path& __p, const path& attributes,
95 error_code& __ec) noexcept;
96
97 void create_directory_symlink(const path& __to, const path& __new_symlink);
98 void create_directory_symlink(const path& __to, const path& __new_symlink,
99 error_code& __ec) noexcept;
100
101 void create_hard_link(const path& __to, const path& __new_hard_link);
102 void create_hard_link(const path& __to, const path& __new_hard_link,
103 error_code& __ec) noexcept;
104
105 void create_symlink(const path& __to, const path& __new_symlink);
106 void create_symlink(const path& __to, const path& __new_symlink,
107 error_code& __ec) noexcept;
108
f7a14830 109 [[nodiscard]]
641cb5a6 110 path current_path();
f7a14830
JW
111
112 [[nodiscard]]
641cb5a6 113 path current_path(error_code& __ec);
f7a14830 114
641cb5a6
JW
115 void current_path(const path& __p);
116 void current_path(const path& __p, error_code& __ec) noexcept;
117
f7a14830 118 [[nodiscard]]
641cb5a6
JW
119 bool
120 equivalent(const path& __p1, const path& __p2);
121
f7a14830 122 [[nodiscard]]
641cb5a6
JW
123 bool
124 equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
125
f7a14830 126 [[nodiscard]]
641cb5a6
JW
127 inline bool
128 exists(file_status __s) noexcept
129 { return status_known(__s) && __s.type() != file_type::not_found; }
130
f7a14830 131 [[nodiscard]]
641cb5a6
JW
132 inline bool
133 exists(const path& __p)
134 { return exists(status(__p)); }
135
f7a14830 136 [[nodiscard]]
641cb5a6
JW
137 inline bool
138 exists(const path& __p, error_code& __ec) noexcept
139 {
140 auto __s = status(__p, __ec);
141 if (status_known(__s))
f7373fce
JW
142 {
143 __ec.clear();
144 return __s.type() != file_type::not_found;
145 }
146 return false;
641cb5a6
JW
147 }
148
f7a14830 149 [[nodiscard]]
641cb5a6 150 uintmax_t file_size(const path& __p);
f7a14830
JW
151
152 [[nodiscard]]
641cb5a6
JW
153 uintmax_t file_size(const path& __p, error_code& __ec) noexcept;
154
f7a14830 155 [[nodiscard]]
641cb5a6 156 uintmax_t hard_link_count(const path& __p);
f7a14830
JW
157
158 [[nodiscard]]
641cb5a6
JW
159 uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept;
160
f7a14830 161 [[nodiscard]]
641cb5a6
JW
162 inline bool
163 is_block_file(file_status __s) noexcept
164 { return __s.type() == file_type::block; }
165
f7a14830 166 [[nodiscard]]
641cb5a6
JW
167 inline bool
168 is_block_file(const path& __p)
169 { return is_block_file(status(__p)); }
170
f7a14830 171 [[nodiscard]]
641cb5a6
JW
172 inline bool
173 is_block_file(const path& __p, error_code& __ec) noexcept
174 { return is_block_file(status(__p, __ec)); }
175
f7a14830 176 [[nodiscard]]
641cb5a6
JW
177 inline bool
178 is_character_file(file_status __s) noexcept
179 { return __s.type() == file_type::character; }
180
f7a14830 181 [[nodiscard]]
641cb5a6
JW
182 inline bool
183 is_character_file(const path& __p)
184 { return is_character_file(status(__p)); }
185
f7a14830 186 [[nodiscard]]
641cb5a6
JW
187 inline bool
188 is_character_file(const path& __p, error_code& __ec) noexcept
189 { return is_character_file(status(__p, __ec)); }
190
f7a14830 191 [[nodiscard]]
641cb5a6
JW
192 inline bool
193 is_directory(file_status __s) noexcept
194 { return __s.type() == file_type::directory; }
195
f7a14830 196 [[nodiscard]]
641cb5a6
JW
197 inline bool
198 is_directory(const path& __p)
199 { return is_directory(status(__p)); }
200
f7a14830 201 [[nodiscard]]
641cb5a6
JW
202 inline bool
203 is_directory(const path& __p, error_code& __ec) noexcept
204 { return is_directory(status(__p, __ec)); }
205
f7a14830 206 [[nodiscard]]
641cb5a6 207 bool is_empty(const path& __p);
f7a14830
JW
208
209 [[nodiscard]]
29453a9f 210 bool is_empty(const path& __p, error_code& __ec);
641cb5a6 211
f7a14830 212 [[nodiscard]]
641cb5a6
JW
213 inline bool
214 is_fifo(file_status __s) noexcept
215 { return __s.type() == file_type::fifo; }
216
f7a14830 217 [[nodiscard]]
641cb5a6
JW
218 inline bool
219 is_fifo(const path& __p)
220 { return is_fifo(status(__p)); }
221
f7a14830 222 [[nodiscard]]
641cb5a6
JW
223 inline bool
224 is_fifo(const path& __p, error_code& __ec) noexcept
225 { return is_fifo(status(__p, __ec)); }
226
f7a14830 227 [[nodiscard]]
641cb5a6
JW
228 inline bool
229 is_other(file_status __s) noexcept
230 {
231 return exists(__s) && !is_regular_file(__s) && !is_directory(__s)
232 && !is_symlink(__s);
233 }
234
f7a14830 235 [[nodiscard]]
641cb5a6
JW
236 inline bool
237 is_other(const path& __p)
238 { return is_other(status(__p)); }
239
f7a14830 240 [[nodiscard]]
641cb5a6
JW
241 inline bool
242 is_other(const path& __p, error_code& __ec) noexcept
243 { return is_other(status(__p, __ec)); }
244
f7a14830 245 [[nodiscard]]
641cb5a6
JW
246 inline bool
247 is_regular_file(file_status __s) noexcept
248 { return __s.type() == file_type::regular; }
249
f7a14830 250 [[nodiscard]]
641cb5a6
JW
251 inline bool
252 is_regular_file(const path& __p)
253 { return is_regular_file(status(__p)); }
254
f7a14830 255 [[nodiscard]]
641cb5a6
JW
256 inline bool
257 is_regular_file(const path& __p, error_code& __ec) noexcept
258 { return is_regular_file(status(__p, __ec)); }
259
f7a14830 260 [[nodiscard]]
641cb5a6
JW
261 inline bool
262 is_socket(file_status __s) noexcept
263 { return __s.type() == file_type::socket; }
264
f7a14830 265 [[nodiscard]]
641cb5a6
JW
266 inline bool
267 is_socket(const path& __p)
268 { return is_socket(status(__p)); }
269
f7a14830 270 [[nodiscard]]
641cb5a6
JW
271 inline bool
272 is_socket(const path& __p, error_code& __ec) noexcept
273 { return is_socket(status(__p, __ec)); }
274
f7a14830 275 [[nodiscard]]
641cb5a6
JW
276 inline bool
277 is_symlink(file_status __s) noexcept
278 { return __s.type() == file_type::symlink; }
279
f7a14830 280 [[nodiscard]]
641cb5a6
JW
281 inline bool
282 is_symlink(const path& __p)
283 { return is_symlink(symlink_status(__p)); }
284
f7a14830 285 [[nodiscard]]
641cb5a6
JW
286 inline bool
287 is_symlink(const path& __p, error_code& __ec) noexcept
288 { return is_symlink(symlink_status(__p, __ec)); }
289
f7a14830 290 [[nodiscard]]
641cb5a6 291 file_time_type last_write_time(const path& __p);
f7a14830
JW
292
293 [[nodiscard]]
641cb5a6 294 file_time_type last_write_time(const path& __p, error_code& __ec) noexcept;
f7a14830 295
641cb5a6
JW
296 void last_write_time(const path& __p, file_time_type __new_time);
297 void last_write_time(const path& __p, file_time_type __new_time,
298 error_code& __ec) noexcept;
299
300 void
301 permissions(const path& __p, perms __prms,
302 perm_options __opts = perm_options::replace);
303
304 inline void
305 permissions(const path& __p, perms __prms, error_code& __ec) noexcept
306 { permissions(__p, __prms, perm_options::replace, __ec); }
307
308 void
309 permissions(const path& __p, perms __prms, perm_options __opts,
0382bcfc 310 error_code& __ec) noexcept;
641cb5a6 311
f7a14830 312 [[nodiscard]]
641cb5a6
JW
313 inline path proximate(const path& __p, error_code& __ec)
314 { return proximate(__p, current_path(), __ec); }
315
f7a14830 316 [[nodiscard]]
641cb5a6 317 path proximate(const path& __p, const path& __base = current_path());
f7a14830
JW
318
319 [[nodiscard]]
641cb5a6
JW
320 path proximate(const path& __p, const path& __base, error_code& __ec);
321
f7a14830 322 [[nodiscard]]
641cb5a6 323 path read_symlink(const path& __p);
f7a14830
JW
324
325 [[nodiscard]]
641cb5a6
JW
326 path read_symlink(const path& __p, error_code& __ec);
327
f7a14830 328 [[nodiscard]]
641cb5a6
JW
329 inline path relative(const path& __p, error_code& __ec)
330 { return relative(__p, current_path(), __ec); }
331
f7a14830 332 [[nodiscard]]
641cb5a6 333 path relative(const path& __p, const path& __base = current_path());
f7a14830
JW
334
335 [[nodiscard]]
641cb5a6
JW
336 path relative(const path& __p, const path& __base, error_code& __ec);
337
338 bool remove(const path& __p);
339 bool remove(const path& __p, error_code& __ec) noexcept;
340
341 uintmax_t remove_all(const path& __p);
29453a9f 342 uintmax_t remove_all(const path& __p, error_code& __ec);
641cb5a6
JW
343
344 void rename(const path& __from, const path& __to);
345 void rename(const path& __from, const path& __to, error_code& __ec) noexcept;
346
347 void resize_file(const path& __p, uintmax_t __size);
348 void resize_file(const path& __p, uintmax_t __size, error_code& __ec) noexcept;
349
f7a14830 350 [[nodiscard]]
641cb5a6 351 space_info space(const path& __p);
f7a14830
JW
352
353 [[nodiscard]]
641cb5a6
JW
354 space_info space(const path& __p, error_code& __ec) noexcept;
355
f7a14830 356 [[nodiscard]]
641cb5a6 357 file_status status(const path& __p);
f7a14830
JW
358
359 [[nodiscard]]
641cb5a6
JW
360 file_status status(const path& __p, error_code& __ec) noexcept;
361
f7a14830 362 [[nodiscard]]
641cb5a6
JW
363 inline bool status_known(file_status __s) noexcept
364 { return __s.type() != file_type::none; }
365
f7a14830 366 [[nodiscard]]
641cb5a6 367 file_status symlink_status(const path& __p);
f7a14830
JW
368
369 [[nodiscard]]
641cb5a6
JW
370 file_status symlink_status(const path& __p, error_code& __ec) noexcept;
371
f7a14830 372 [[nodiscard]]
641cb5a6 373 path temp_directory_path();
f7a14830
JW
374
375 [[nodiscard]]
641cb5a6
JW
376 path temp_directory_path(error_code& __ec);
377
f7a14830 378 [[nodiscard]]
641cb5a6 379 path weakly_canonical(const path& __p);
f7a14830
JW
380
381 [[nodiscard]]
641cb5a6
JW
382 path weakly_canonical(const path& __p, error_code& __ec);
383
f0b88346 384 /// @} group filesystem
641cb5a6
JW
385} // namespace filesystem
386
387_GLIBCXX_END_NAMESPACE_VERSION
388} // namespace std
389
390#endif // C++17
391
392#endif // _GLIBCXX_FS_OPS_H