xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/bits/fs_ops.h (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1 // Filesystem operational functions -*- C++ -*-
2 
3 // Copyright (C) 2014-2020 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_ops.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_OPS_H
31 #define _GLIBCXX_FS_OPS_H 1
32 
33 #if __cplusplus >= 201703L
34 
35 #include <cstdint>
36 
_GLIBCXX_VISIBILITY(default)37 namespace std _GLIBCXX_VISIBILITY(default)
38 {
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 
41 namespace filesystem
42 {
43   /** @addtogroup filesystem
44    *  @{
45    */
46 
47   path absolute(const path& __p);
48   path absolute(const path& __p, error_code& __ec);
49 
50   path canonical(const path& __p);
51   path canonical(const path& __p, error_code& __ec);
52 
53   inline void
54   copy(const path& __from, const path& __to)
55   { copy(__from, __to, copy_options::none); }
56 
57   inline void
58   copy(const path& __from, const path& __to, error_code& __ec)
59   { copy(__from, __to, copy_options::none, __ec); }
60 
61   void copy(const path& __from, const path& __to, copy_options __options);
62   void copy(const path& __from, const path& __to, copy_options __options,
63 	    error_code& __ec);
64 
65   inline bool
66   copy_file(const path& __from, const path& __to)
67   { return copy_file(__from, __to, copy_options::none); }
68 
69   inline bool
70   copy_file(const path& __from, const path& __to, error_code& __ec)
71   { return copy_file(__from, __to, copy_options::none, __ec); }
72 
73   bool copy_file(const path& __from, const path& __to, copy_options __option);
74   bool copy_file(const path& __from, const path& __to, copy_options __option,
75 		 error_code& __ec);
76 
77   void copy_symlink(const path& __existing_symlink, const path& __new_symlink);
78   void copy_symlink(const path& __existing_symlink, const path& __new_symlink,
79 		    error_code& __ec) noexcept;
80 
81   bool create_directories(const path& __p);
82   bool create_directories(const path& __p, error_code& __ec);
83 
84   bool create_directory(const path& __p);
85   bool create_directory(const path& __p, error_code& __ec) noexcept;
86 
87   bool create_directory(const path& __p, const path& attributes);
88   bool create_directory(const path& __p, const path& attributes,
89 			error_code& __ec) noexcept;
90 
91   void create_directory_symlink(const path& __to, const path& __new_symlink);
92   void create_directory_symlink(const path& __to, const path& __new_symlink,
93 				error_code& __ec) noexcept;
94 
95   void create_hard_link(const path& __to, const path& __new_hard_link);
96   void create_hard_link(const path& __to, const path& __new_hard_link,
97 			error_code& __ec) noexcept;
98 
99   void create_symlink(const path& __to, const path& __new_symlink);
100   void create_symlink(const path& __to, const path& __new_symlink,
101 		      error_code& __ec) noexcept;
102 
103   path current_path();
104   path current_path(error_code& __ec);
105   void current_path(const path& __p);
106   void current_path(const path& __p, error_code& __ec) noexcept;
107 
108   bool
109   equivalent(const path& __p1, const path& __p2);
110 
111   bool
112   equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
113 
114   inline bool
115   exists(file_status __s) noexcept
116   { return status_known(__s) && __s.type() != file_type::not_found; }
117 
118   inline bool
119   exists(const path& __p)
120   { return exists(status(__p)); }
121 
122   inline bool
123   exists(const path& __p, error_code& __ec) noexcept
124   {
125     auto __s = status(__p, __ec);
126     if (status_known(__s))
127       {
128 	__ec.clear();
129 	return __s.type() != file_type::not_found;
130       }
131     return false;
132   }
133 
134   uintmax_t file_size(const path& __p);
135   uintmax_t file_size(const path& __p, error_code& __ec) noexcept;
136 
137   uintmax_t hard_link_count(const path& __p);
138   uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept;
139 
140   inline bool
141   is_block_file(file_status __s) noexcept
142   { return __s.type() == file_type::block; }
143 
144   inline bool
145   is_block_file(const path& __p)
146   { return is_block_file(status(__p)); }
147 
148   inline bool
149   is_block_file(const path& __p, error_code& __ec) noexcept
150   { return is_block_file(status(__p, __ec)); }
151 
152   inline bool
153   is_character_file(file_status __s) noexcept
154   { return __s.type() == file_type::character; }
155 
156   inline bool
157   is_character_file(const path& __p)
158   { return is_character_file(status(__p)); }
159 
160   inline bool
161   is_character_file(const path& __p, error_code& __ec) noexcept
162   { return is_character_file(status(__p, __ec)); }
163 
164   inline bool
165   is_directory(file_status __s) noexcept
166   { return __s.type() == file_type::directory; }
167 
168   inline bool
169   is_directory(const path& __p)
170   { return is_directory(status(__p)); }
171 
172   inline bool
173   is_directory(const path& __p, error_code& __ec) noexcept
174   { return is_directory(status(__p, __ec)); }
175 
176   bool is_empty(const path& __p);
177   bool is_empty(const path& __p, error_code& __ec);
178 
179   inline bool
180   is_fifo(file_status __s) noexcept
181   { return __s.type() == file_type::fifo; }
182 
183   inline bool
184   is_fifo(const path& __p)
185   { return is_fifo(status(__p)); }
186 
187   inline bool
188   is_fifo(const path& __p, error_code& __ec) noexcept
189   { return is_fifo(status(__p, __ec)); }
190 
191   inline bool
192   is_other(file_status __s) noexcept
193   {
194     return exists(__s) && !is_regular_file(__s) && !is_directory(__s)
195       && !is_symlink(__s);
196   }
197 
198   inline bool
199   is_other(const path& __p)
200   { return is_other(status(__p)); }
201 
202   inline bool
203   is_other(const path& __p, error_code& __ec) noexcept
204   { return is_other(status(__p, __ec)); }
205 
206   inline bool
207   is_regular_file(file_status __s) noexcept
208   { return __s.type() == file_type::regular; }
209 
210   inline bool
211   is_regular_file(const path& __p)
212   { return is_regular_file(status(__p)); }
213 
214   inline bool
215   is_regular_file(const path& __p, error_code& __ec) noexcept
216   { return is_regular_file(status(__p, __ec)); }
217 
218   inline bool
219   is_socket(file_status __s) noexcept
220   { return __s.type() == file_type::socket; }
221 
222   inline bool
223   is_socket(const path& __p)
224   { return is_socket(status(__p)); }
225 
226   inline bool
227   is_socket(const path& __p, error_code& __ec) noexcept
228   { return is_socket(status(__p, __ec)); }
229 
230   inline bool
231   is_symlink(file_status __s) noexcept
232   { return __s.type() == file_type::symlink; }
233 
234   inline bool
235   is_symlink(const path& __p)
236   { return is_symlink(symlink_status(__p)); }
237 
238   inline bool
239   is_symlink(const path& __p, error_code& __ec) noexcept
240   { return is_symlink(symlink_status(__p, __ec)); }
241 
242   file_time_type  last_write_time(const path& __p);
243   file_time_type  last_write_time(const path& __p, error_code& __ec) noexcept;
244   void last_write_time(const path& __p, file_time_type __new_time);
245   void last_write_time(const path& __p, file_time_type __new_time,
246 		       error_code& __ec) noexcept;
247 
248   void
249   permissions(const path& __p, perms __prms,
250 	      perm_options __opts = perm_options::replace);
251 
252   inline void
253   permissions(const path& __p, perms __prms, error_code& __ec) noexcept
254   { permissions(__p, __prms, perm_options::replace, __ec); }
255 
256   void
257   permissions(const path& __p, perms __prms, perm_options __opts,
258 	      error_code& __ec) noexcept;
259 
260   inline path proximate(const path& __p, error_code& __ec)
261   { return proximate(__p, current_path(), __ec); }
262 
263   path proximate(const path& __p, const path& __base = current_path());
264   path proximate(const path& __p, const path& __base, error_code& __ec);
265 
266   path read_symlink(const path& __p);
267   path read_symlink(const path& __p, error_code& __ec);
268 
269   inline path relative(const path& __p, error_code& __ec)
270   { return relative(__p, current_path(), __ec); }
271 
272   path relative(const path& __p, const path& __base = current_path());
273   path relative(const path& __p, const path& __base, error_code& __ec);
274 
275   bool remove(const path& __p);
276   bool remove(const path& __p, error_code& __ec) noexcept;
277 
278   uintmax_t remove_all(const path& __p);
279   uintmax_t remove_all(const path& __p, error_code& __ec);
280 
281   void rename(const path& __from, const path& __to);
282   void rename(const path& __from, const path& __to, error_code& __ec) noexcept;
283 
284   void resize_file(const path& __p, uintmax_t __size);
285   void resize_file(const path& __p, uintmax_t __size, error_code& __ec) noexcept;
286 
287   space_info space(const path& __p);
288   space_info space(const path& __p, error_code& __ec) noexcept;
289 
290   file_status status(const path& __p);
291   file_status status(const path& __p, error_code& __ec) noexcept;
292 
293   inline bool status_known(file_status __s) noexcept
294   { return __s.type() != file_type::none; }
295 
296   file_status symlink_status(const path& __p);
297   file_status symlink_status(const path& __p, error_code& __ec) noexcept;
298 
299   path temp_directory_path();
300   path temp_directory_path(error_code& __ec);
301 
302   path weakly_canonical(const path& __p);
303   path weakly_canonical(const path& __p, error_code& __ec);
304 
305   /// @} group filesystem
306 } // namespace filesystem
307 
308 _GLIBCXX_END_NAMESPACE_VERSION
309 } // namespace std
310 
311 #endif // C++17
312 
313 #endif // _GLIBCXX_FS_OPS_H
314