xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/fs_fwd.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Filesystem declarations -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2014-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /** @file include/bits/fs_fwd.h
26*38fd1498Szrj  *  This is an internal header file, included by other library headers.
27*38fd1498Szrj  *  Do not attempt to use it directly. @headername{filesystem}
28*38fd1498Szrj  */
29*38fd1498Szrj 
30*38fd1498Szrj #ifndef _GLIBCXX_FS_FWD_H
31*38fd1498Szrj #define _GLIBCXX_FS_FWD_H 1
32*38fd1498Szrj 
33*38fd1498Szrj #if __cplusplus >= 201703L
34*38fd1498Szrj 
35*38fd1498Szrj #include <system_error>
36*38fd1498Szrj #include <cstdint>
37*38fd1498Szrj #include <chrono>
38*38fd1498Szrj 
_GLIBCXX_VISIBILITY(default)39*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
40*38fd1498Szrj {
41*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
42*38fd1498Szrj 
43*38fd1498Szrj namespace filesystem
44*38fd1498Szrj {
45*38fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
46*38fd1498Szrj inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
47*38fd1498Szrj #endif
48*38fd1498Szrj 
49*38fd1498Szrj   /**
50*38fd1498Szrj    * @defgroup filesystem Filesystem
51*38fd1498Szrj    *
52*38fd1498Szrj    * Utilities for performing operations on file systems and their components,
53*38fd1498Szrj    * such as paths, regular files, and directories.
54*38fd1498Szrj    *
55*38fd1498Szrj    * @{
56*38fd1498Szrj    */
57*38fd1498Szrj 
58*38fd1498Szrj   class file_status;
59*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
60*38fd1498Szrj   class path;
61*38fd1498Szrj   class filesystem_error;
62*38fd1498Szrj   class directory_entry;
63*38fd1498Szrj   class directory_iterator;
64*38fd1498Szrj   class recursive_directory_iterator;
65*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
66*38fd1498Szrj 
67*38fd1498Szrj   struct space_info
68*38fd1498Szrj   {
69*38fd1498Szrj     uintmax_t capacity;
70*38fd1498Szrj     uintmax_t free;
71*38fd1498Szrj     uintmax_t available;
72*38fd1498Szrj   };
73*38fd1498Szrj 
74*38fd1498Szrj   enum class file_type : signed char {
75*38fd1498Szrj       none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
76*38fd1498Szrj       block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
77*38fd1498Szrj   };
78*38fd1498Szrj 
79*38fd1498Szrj   /// Bitmask type
80*38fd1498Szrj   enum class copy_options : unsigned short {
81*38fd1498Szrj       none = 0,
82*38fd1498Szrj       skip_existing = 1, overwrite_existing = 2, update_existing = 4,
83*38fd1498Szrj       recursive = 8,
84*38fd1498Szrj       copy_symlinks = 16, skip_symlinks = 32,
85*38fd1498Szrj       directories_only = 64, create_symlinks = 128, create_hard_links = 256
86*38fd1498Szrj   };
87*38fd1498Szrj 
88*38fd1498Szrj   constexpr copy_options
89*38fd1498Szrj   operator&(copy_options __x, copy_options __y) noexcept
90*38fd1498Szrj   {
91*38fd1498Szrj     using __utype = typename std::underlying_type<copy_options>::type;
92*38fd1498Szrj     return static_cast<copy_options>(
93*38fd1498Szrj 	static_cast<__utype>(__x) & static_cast<__utype>(__y));
94*38fd1498Szrj   }
95*38fd1498Szrj 
96*38fd1498Szrj   constexpr copy_options
97*38fd1498Szrj   operator|(copy_options __x, copy_options __y) noexcept
98*38fd1498Szrj   {
99*38fd1498Szrj     using __utype = typename std::underlying_type<copy_options>::type;
100*38fd1498Szrj     return static_cast<copy_options>(
101*38fd1498Szrj 	static_cast<__utype>(__x) | static_cast<__utype>(__y));
102*38fd1498Szrj   }
103*38fd1498Szrj 
104*38fd1498Szrj   constexpr copy_options
105*38fd1498Szrj   operator^(copy_options __x, copy_options __y) noexcept
106*38fd1498Szrj   {
107*38fd1498Szrj     using __utype = typename std::underlying_type<copy_options>::type;
108*38fd1498Szrj     return static_cast<copy_options>(
109*38fd1498Szrj 	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
110*38fd1498Szrj   }
111*38fd1498Szrj 
112*38fd1498Szrj   constexpr copy_options
113*38fd1498Szrj   operator~(copy_options __x) noexcept
114*38fd1498Szrj   {
115*38fd1498Szrj     using __utype = typename std::underlying_type<copy_options>::type;
116*38fd1498Szrj     return static_cast<copy_options>(~static_cast<__utype>(__x));
117*38fd1498Szrj   }
118*38fd1498Szrj 
119*38fd1498Szrj   inline copy_options&
120*38fd1498Szrj   operator&=(copy_options& __x, copy_options __y) noexcept
121*38fd1498Szrj   { return __x = __x & __y; }
122*38fd1498Szrj 
123*38fd1498Szrj   inline copy_options&
124*38fd1498Szrj   operator|=(copy_options& __x, copy_options __y) noexcept
125*38fd1498Szrj   { return __x = __x | __y; }
126*38fd1498Szrj 
127*38fd1498Szrj   inline copy_options&
128*38fd1498Szrj   operator^=(copy_options& __x, copy_options __y) noexcept
129*38fd1498Szrj   { return __x = __x ^ __y; }
130*38fd1498Szrj 
131*38fd1498Szrj 
132*38fd1498Szrj   /// Bitmask type
133*38fd1498Szrj   enum class perms : unsigned {
134*38fd1498Szrj       none		=  0,
135*38fd1498Szrj       owner_read	=  0400,
136*38fd1498Szrj       owner_write	=  0200,
137*38fd1498Szrj       owner_exec	=  0100,
138*38fd1498Szrj       owner_all		=  0700,
139*38fd1498Szrj       group_read	=   040,
140*38fd1498Szrj       group_write	=   020,
141*38fd1498Szrj       group_exec	=   010,
142*38fd1498Szrj       group_all		=   070,
143*38fd1498Szrj       others_read	=    04,
144*38fd1498Szrj       others_write	=    02,
145*38fd1498Szrj       others_exec	=    01,
146*38fd1498Szrj       others_all	=    07,
147*38fd1498Szrj       all		=  0777,
148*38fd1498Szrj       set_uid		= 04000,
149*38fd1498Szrj       set_gid		= 02000,
150*38fd1498Szrj       sticky_bit	= 01000,
151*38fd1498Szrj       mask		= 07777,
152*38fd1498Szrj       unknown		=  0xFFFF,
153*38fd1498Szrj   };
154*38fd1498Szrj 
155*38fd1498Szrj   constexpr perms
156*38fd1498Szrj   operator&(perms __x, perms __y) noexcept
157*38fd1498Szrj   {
158*38fd1498Szrj     using __utype = typename std::underlying_type<perms>::type;
159*38fd1498Szrj     return static_cast<perms>(
160*38fd1498Szrj 	static_cast<__utype>(__x) & static_cast<__utype>(__y));
161*38fd1498Szrj   }
162*38fd1498Szrj 
163*38fd1498Szrj   constexpr perms
164*38fd1498Szrj   operator|(perms __x, perms __y) noexcept
165*38fd1498Szrj   {
166*38fd1498Szrj     using __utype = typename std::underlying_type<perms>::type;
167*38fd1498Szrj     return static_cast<perms>(
168*38fd1498Szrj 	static_cast<__utype>(__x) | static_cast<__utype>(__y));
169*38fd1498Szrj   }
170*38fd1498Szrj 
171*38fd1498Szrj   constexpr perms
172*38fd1498Szrj   operator^(perms __x, perms __y) noexcept
173*38fd1498Szrj   {
174*38fd1498Szrj     using __utype = typename std::underlying_type<perms>::type;
175*38fd1498Szrj     return static_cast<perms>(
176*38fd1498Szrj 	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
177*38fd1498Szrj   }
178*38fd1498Szrj 
179*38fd1498Szrj   constexpr perms
180*38fd1498Szrj   operator~(perms __x) noexcept
181*38fd1498Szrj   {
182*38fd1498Szrj     using __utype = typename std::underlying_type<perms>::type;
183*38fd1498Szrj     return static_cast<perms>(~static_cast<__utype>(__x));
184*38fd1498Szrj   }
185*38fd1498Szrj 
186*38fd1498Szrj   inline perms&
187*38fd1498Szrj   operator&=(perms& __x, perms __y) noexcept
188*38fd1498Szrj   { return __x = __x & __y; }
189*38fd1498Szrj 
190*38fd1498Szrj   inline perms&
191*38fd1498Szrj   operator|=(perms& __x, perms __y) noexcept
192*38fd1498Szrj   { return __x = __x | __y; }
193*38fd1498Szrj 
194*38fd1498Szrj   inline perms&
195*38fd1498Szrj   operator^=(perms& __x, perms __y) noexcept
196*38fd1498Szrj   { return __x = __x ^ __y; }
197*38fd1498Szrj 
198*38fd1498Szrj   /// Bitmask type
199*38fd1498Szrj   enum class perm_options : unsigned {
200*38fd1498Szrj       replace	= 0x1,
201*38fd1498Szrj       add	= 0x2,
202*38fd1498Szrj       remove	= 0x4,
203*38fd1498Szrj       nofollow	= 0x8
204*38fd1498Szrj   };
205*38fd1498Szrj 
206*38fd1498Szrj   constexpr perm_options
207*38fd1498Szrj   operator&(perm_options __x, perm_options __y) noexcept
208*38fd1498Szrj   {
209*38fd1498Szrj     using __utype = typename std::underlying_type<perm_options>::type;
210*38fd1498Szrj     return static_cast<perm_options>(
211*38fd1498Szrj 	static_cast<__utype>(__x) & static_cast<__utype>(__y));
212*38fd1498Szrj   }
213*38fd1498Szrj 
214*38fd1498Szrj   constexpr perm_options
215*38fd1498Szrj   operator|(perm_options __x, perm_options __y) noexcept
216*38fd1498Szrj   {
217*38fd1498Szrj     using __utype = typename std::underlying_type<perm_options>::type;
218*38fd1498Szrj     return static_cast<perm_options>(
219*38fd1498Szrj 	static_cast<__utype>(__x) | static_cast<__utype>(__y));
220*38fd1498Szrj   }
221*38fd1498Szrj 
222*38fd1498Szrj   constexpr perm_options
223*38fd1498Szrj   operator^(perm_options __x, perm_options __y) noexcept
224*38fd1498Szrj   {
225*38fd1498Szrj     using __utype = typename std::underlying_type<perm_options>::type;
226*38fd1498Szrj     return static_cast<perm_options>(
227*38fd1498Szrj 	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
228*38fd1498Szrj   }
229*38fd1498Szrj 
230*38fd1498Szrj   constexpr perm_options
231*38fd1498Szrj   operator~(perm_options __x) noexcept
232*38fd1498Szrj   {
233*38fd1498Szrj     using __utype = typename std::underlying_type<perm_options>::type;
234*38fd1498Szrj     return static_cast<perm_options>(~static_cast<__utype>(__x));
235*38fd1498Szrj   }
236*38fd1498Szrj 
237*38fd1498Szrj   inline perm_options&
238*38fd1498Szrj   operator&=(perm_options& __x, perm_options __y) noexcept
239*38fd1498Szrj   { return __x = __x & __y; }
240*38fd1498Szrj 
241*38fd1498Szrj   inline perm_options&
242*38fd1498Szrj   operator|=(perm_options& __x, perm_options __y) noexcept
243*38fd1498Szrj   { return __x = __x | __y; }
244*38fd1498Szrj 
245*38fd1498Szrj   inline perm_options&
246*38fd1498Szrj   operator^=(perm_options& __x, perm_options __y) noexcept
247*38fd1498Szrj   { return __x = __x ^ __y; }
248*38fd1498Szrj 
249*38fd1498Szrj   // Bitmask type
250*38fd1498Szrj   enum class directory_options : unsigned char {
251*38fd1498Szrj       none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
252*38fd1498Szrj   };
253*38fd1498Szrj 
254*38fd1498Szrj   constexpr directory_options
255*38fd1498Szrj   operator&(directory_options __x, directory_options __y) noexcept
256*38fd1498Szrj   {
257*38fd1498Szrj     using __utype = typename std::underlying_type<directory_options>::type;
258*38fd1498Szrj     return static_cast<directory_options>(
259*38fd1498Szrj 	static_cast<__utype>(__x) & static_cast<__utype>(__y));
260*38fd1498Szrj   }
261*38fd1498Szrj 
262*38fd1498Szrj   constexpr directory_options
263*38fd1498Szrj   operator|(directory_options __x, directory_options __y) noexcept
264*38fd1498Szrj   {
265*38fd1498Szrj     using __utype = typename std::underlying_type<directory_options>::type;
266*38fd1498Szrj     return static_cast<directory_options>(
267*38fd1498Szrj 	static_cast<__utype>(__x) | static_cast<__utype>(__y));
268*38fd1498Szrj   }
269*38fd1498Szrj 
270*38fd1498Szrj   constexpr directory_options
271*38fd1498Szrj   operator^(directory_options __x, directory_options __y) noexcept
272*38fd1498Szrj   {
273*38fd1498Szrj     using __utype = typename std::underlying_type<directory_options>::type;
274*38fd1498Szrj     return static_cast<directory_options>(
275*38fd1498Szrj 	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
276*38fd1498Szrj   }
277*38fd1498Szrj 
278*38fd1498Szrj   constexpr directory_options
279*38fd1498Szrj   operator~(directory_options __x) noexcept
280*38fd1498Szrj   {
281*38fd1498Szrj     using __utype = typename std::underlying_type<directory_options>::type;
282*38fd1498Szrj     return static_cast<directory_options>(~static_cast<__utype>(__x));
283*38fd1498Szrj   }
284*38fd1498Szrj 
285*38fd1498Szrj   inline directory_options&
286*38fd1498Szrj   operator&=(directory_options& __x, directory_options __y) noexcept
287*38fd1498Szrj   { return __x = __x & __y; }
288*38fd1498Szrj 
289*38fd1498Szrj   inline directory_options&
290*38fd1498Szrj   operator|=(directory_options& __x, directory_options __y) noexcept
291*38fd1498Szrj   { return __x = __x | __y; }
292*38fd1498Szrj 
293*38fd1498Szrj   inline directory_options&
294*38fd1498Szrj   operator^=(directory_options& __x, directory_options __y) noexcept
295*38fd1498Szrj   { return __x = __x ^ __y; }
296*38fd1498Szrj 
297*38fd1498Szrj   using file_time_type = std::chrono::system_clock::time_point;
298*38fd1498Szrj 
299*38fd1498Szrj   // operational functions
300*38fd1498Szrj 
301*38fd1498Szrj   void copy(const path& __from, const path& __to, copy_options __options);
302*38fd1498Szrj   void copy(const path& __from, const path& __to, copy_options __options,
303*38fd1498Szrj 	    error_code&);
304*38fd1498Szrj 
305*38fd1498Szrj   bool copy_file(const path& __from, const path& __to, copy_options __option);
306*38fd1498Szrj   bool copy_file(const path& __from, const path& __to, copy_options __option,
307*38fd1498Szrj 		 error_code&);
308*38fd1498Szrj 
309*38fd1498Szrj   path current_path();
310*38fd1498Szrj 
311*38fd1498Szrj   bool exists(file_status) noexcept;
312*38fd1498Szrj 
313*38fd1498Szrj   bool is_other(file_status) noexcept;
314*38fd1498Szrj 
315*38fd1498Szrj   uintmax_t file_size(const path&);
316*38fd1498Szrj   uintmax_t file_size(const path&, error_code&) noexcept;
317*38fd1498Szrj   uintmax_t hard_link_count(const path&);
318*38fd1498Szrj   uintmax_t hard_link_count(const path&, error_code&) noexcept;
319*38fd1498Szrj   file_time_type last_write_time(const path&);
320*38fd1498Szrj   file_time_type last_write_time(const path&, error_code&) noexcept;
321*38fd1498Szrj 
322*38fd1498Szrj   void permissions(const path&, perms, perm_options, error_code&) noexcept;
323*38fd1498Szrj 
324*38fd1498Szrj   path proximate(const path& __p, const path& __base, error_code& __ec);
325*38fd1498Szrj   path proximate(const path& __p, const path& __base, error_code& __ec);
326*38fd1498Szrj 
327*38fd1498Szrj   path relative(const path& __p, const path& __base, error_code& __ec);
328*38fd1498Szrj 
329*38fd1498Szrj   file_status status(const path&);
330*38fd1498Szrj   file_status status(const path&, error_code&) noexcept;
331*38fd1498Szrj 
332*38fd1498Szrj   bool status_known(file_status) noexcept;
333*38fd1498Szrj 
334*38fd1498Szrj   file_status symlink_status(const path&);
335*38fd1498Szrj   file_status symlink_status(const path&, error_code&) noexcept;
336*38fd1498Szrj 
337*38fd1498Szrj   bool is_regular_file(file_status) noexcept;
338*38fd1498Szrj   bool is_symlink(file_status) noexcept;
339*38fd1498Szrj 
340*38fd1498Szrj   // @} group filesystem
341*38fd1498Szrj } // namespace filesystem
342*38fd1498Szrj 
343*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
344*38fd1498Szrj } // namespace std
345*38fd1498Szrj 
346*38fd1498Szrj #endif // C++17
347*38fd1498Szrj 
348*38fd1498Szrj #endif // _GLIBCXX_FS_FWD_H
349