libstdc++
bits/fs_fwd.h
Go to the documentation of this file.
1 // Filesystem declarations -*- C++ -*-
2 
3 // Copyright (C) 2014-2019 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 <chrono>
38 
39 namespace std _GLIBCXX_VISIBILITY(default)
40 {
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 
43 namespace filesystem
44 {
45 #if _GLIBCXX_USE_CXX11_ABI
46 inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
47 #endif
48 
49  /**
50  * @defgroup filesystem Filesystem
51  *
52  * Utilities for performing operations on file systems and their components,
53  * such as paths, regular files, and directories.
54  *
55  * @{
56  */
57 
58  class file_status;
59 _GLIBCXX_BEGIN_NAMESPACE_CXX11
60  class path;
61  class filesystem_error;
62  class directory_entry;
63  class directory_iterator;
64  class recursive_directory_iterator;
65 _GLIBCXX_END_NAMESPACE_CXX11
66 
67  struct space_info
68  {
69  uintmax_t capacity;
70  uintmax_t free;
71  uintmax_t available;
72  };
73 
74  enum class file_type : signed char {
75  none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
76  block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
77  };
78 
79  /// Bitmask type
80  enum class copy_options : unsigned short {
81  none = 0,
82  skip_existing = 1, overwrite_existing = 2, update_existing = 4,
83  recursive = 8,
84  copy_symlinks = 16, skip_symlinks = 32,
85  directories_only = 64, create_symlinks = 128, create_hard_links = 256
86  };
87 
88  constexpr copy_options
89  operator&(copy_options __x, copy_options __y) noexcept
90  {
91  using __utype = typename std::underlying_type<copy_options>::type;
92  return static_cast<copy_options>(
93  static_cast<__utype>(__x) & static_cast<__utype>(__y));
94  }
95 
96  constexpr copy_options
97  operator|(copy_options __x, copy_options __y) noexcept
98  {
99  using __utype = typename std::underlying_type<copy_options>::type;
100  return static_cast<copy_options>(
101  static_cast<__utype>(__x) | static_cast<__utype>(__y));
102  }
103 
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  constexpr copy_options
113  operator~(copy_options __x) noexcept
114  {
115  using __utype = typename std::underlying_type<copy_options>::type;
116  return static_cast<copy_options>(~static_cast<__utype>(__x));
117  }
118 
119  inline copy_options&
120  operator&=(copy_options& __x, copy_options __y) noexcept
121  { return __x = __x & __y; }
122 
123  inline copy_options&
124  operator|=(copy_options& __x, copy_options __y) noexcept
125  { return __x = __x | __y; }
126 
127  inline copy_options&
128  operator^=(copy_options& __x, copy_options __y) noexcept
129  { return __x = __x ^ __y; }
130 
131 
132  /// Bitmask type
133  enum class perms : unsigned {
134  none = 0,
135  owner_read = 0400,
136  owner_write = 0200,
137  owner_exec = 0100,
138  owner_all = 0700,
139  group_read = 040,
140  group_write = 020,
141  group_exec = 010,
142  group_all = 070,
143  others_read = 04,
144  others_write = 02,
145  others_exec = 01,
146  others_all = 07,
147  all = 0777,
148  set_uid = 04000,
149  set_gid = 02000,
150  sticky_bit = 01000,
151  mask = 07777,
152  unknown = 0xFFFF,
153  };
154 
155  constexpr perms
156  operator&(perms __x, perms __y) noexcept
157  {
158  using __utype = typename std::underlying_type<perms>::type;
159  return static_cast<perms>(
160  static_cast<__utype>(__x) & static_cast<__utype>(__y));
161  }
162 
163  constexpr perms
164  operator|(perms __x, perms __y) noexcept
165  {
166  using __utype = typename std::underlying_type<perms>::type;
167  return static_cast<perms>(
168  static_cast<__utype>(__x) | static_cast<__utype>(__y));
169  }
170 
171  constexpr perms
172  operator^(perms __x, perms __y) noexcept
173  {
174  using __utype = typename std::underlying_type<perms>::type;
175  return static_cast<perms>(
176  static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
177  }
178 
179  constexpr perms
180  operator~(perms __x) noexcept
181  {
182  using __utype = typename std::underlying_type<perms>::type;
183  return static_cast<perms>(~static_cast<__utype>(__x));
184  }
185 
186  inline perms&
187  operator&=(perms& __x, perms __y) noexcept
188  { return __x = __x & __y; }
189 
190  inline perms&
191  operator|=(perms& __x, perms __y) noexcept
192  { return __x = __x | __y; }
193 
194  inline perms&
195  operator^=(perms& __x, perms __y) noexcept
196  { return __x = __x ^ __y; }
197 
198  /// Bitmask type
199  enum class perm_options : unsigned {
200  replace = 0x1,
201  add = 0x2,
202  remove = 0x4,
203  nofollow = 0x8
204  };
205 
206  constexpr perm_options
207  operator&(perm_options __x, perm_options __y) noexcept
208  {
209  using __utype = typename std::underlying_type<perm_options>::type;
210  return static_cast<perm_options>(
211  static_cast<__utype>(__x) & static_cast<__utype>(__y));
212  }
213 
214  constexpr perm_options
215  operator|(perm_options __x, perm_options __y) noexcept
216  {
217  using __utype = typename std::underlying_type<perm_options>::type;
218  return static_cast<perm_options>(
219  static_cast<__utype>(__x) | static_cast<__utype>(__y));
220  }
221 
222  constexpr perm_options
223  operator^(perm_options __x, perm_options __y) noexcept
224  {
225  using __utype = typename std::underlying_type<perm_options>::type;
226  return static_cast<perm_options>(
227  static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
228  }
229 
230  constexpr perm_options
231  operator~(perm_options __x) noexcept
232  {
233  using __utype = typename std::underlying_type<perm_options>::type;
234  return static_cast<perm_options>(~static_cast<__utype>(__x));
235  }
236 
237  inline perm_options&
238  operator&=(perm_options& __x, perm_options __y) noexcept
239  { return __x = __x & __y; }
240 
241  inline perm_options&
242  operator|=(perm_options& __x, perm_options __y) noexcept
243  { return __x = __x | __y; }
244 
245  inline perm_options&
246  operator^=(perm_options& __x, perm_options __y) noexcept
247  { return __x = __x ^ __y; }
248 
249  // Bitmask type
250  enum class directory_options : unsigned char {
251  none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
252  };
253 
254  constexpr directory_options
255  operator&(directory_options __x, directory_options __y) noexcept
256  {
257  using __utype = typename std::underlying_type<directory_options>::type;
258  return static_cast<directory_options>(
259  static_cast<__utype>(__x) & static_cast<__utype>(__y));
260  }
261 
262  constexpr directory_options
263  operator|(directory_options __x, directory_options __y) noexcept
264  {
265  using __utype = typename std::underlying_type<directory_options>::type;
266  return static_cast<directory_options>(
267  static_cast<__utype>(__x) | static_cast<__utype>(__y));
268  }
269 
270  constexpr directory_options
271  operator^(directory_options __x, directory_options __y) noexcept
272  {
273  using __utype = typename std::underlying_type<directory_options>::type;
274  return static_cast<directory_options>(
275  static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
276  }
277 
278  constexpr directory_options
279  operator~(directory_options __x) noexcept
280  {
281  using __utype = typename std::underlying_type<directory_options>::type;
282  return static_cast<directory_options>(~static_cast<__utype>(__x));
283  }
284 
285  inline directory_options&
286  operator&=(directory_options& __x, directory_options __y) noexcept
287  { return __x = __x & __y; }
288 
289  inline directory_options&
290  operator|=(directory_options& __x, directory_options __y) noexcept
291  { return __x = __x | __y; }
292 
293  inline directory_options&
294  operator^=(directory_options& __x, directory_options __y) noexcept
295  { return __x = __x ^ __y; }
296 
297  struct __file_clock
298  {
299  using duration = chrono::nanoseconds;
300  using rep = duration::rep;
301  using period = duration::period;
302  using time_point = chrono::time_point<__file_clock>;
303  static constexpr bool is_steady = false;
304 
305  static time_point
306  now() noexcept
307  { return _S_from_sys(chrono::system_clock::now()); }
308 
309  private:
310  using __sys_clock = chrono::system_clock;
311 
312  // This clock's (unspecified) epoch is 2174-01-01 00:00:00 UTC.
313  // A signed 64-bit duration with nanosecond resolution gives roughly
314  // +/- 292 years, which covers the 1901-2446 date range for ext4.
315  static constexpr chrono::seconds _S_epoch_diff{6437664000};
316 
317  protected:
318  // For internal use only
319  template<typename _Dur>
320  static
321  chrono::time_point<__file_clock, _Dur>
322  _S_from_sys(const chrono::time_point<__sys_clock, _Dur>& __t) noexcept
323  {
324  using __file_time = chrono::time_point<__file_clock, _Dur>;
325  return __file_time{__t.time_since_epoch()} - _S_epoch_diff;
326  }
327 
328  // For internal use only
329  template<typename _Dur>
330  static
331  chrono::time_point<__sys_clock, _Dur>
332  _S_to_sys(const chrono::time_point<__file_clock, _Dur>& __t) noexcept
333  {
334  using __sys_time = chrono::time_point<__sys_clock, _Dur>;
335  return __sys_time{__t.time_since_epoch()} + _S_epoch_diff;
336  }
337  };
338 
339  using file_time_type = __file_clock::time_point;
340 
341  // operational functions
342 
343  void copy(const path& __from, const path& __to, copy_options __options);
344  void copy(const path& __from, const path& __to, copy_options __options,
345  error_code&);
346 
347  bool copy_file(const path& __from, const path& __to, copy_options __option);
348  bool copy_file(const path& __from, const path& __to, copy_options __option,
349  error_code&);
350 
351  path current_path();
352 
353  bool exists(file_status) noexcept;
354 
355  bool is_other(file_status) noexcept;
356 
357  uintmax_t file_size(const path&);
358  uintmax_t file_size(const path&, error_code&) noexcept;
359  uintmax_t hard_link_count(const path&);
360  uintmax_t hard_link_count(const path&, error_code&) noexcept;
361  file_time_type last_write_time(const path&);
362  file_time_type last_write_time(const path&, error_code&) noexcept;
363 
364  void permissions(const path&, perms, perm_options, error_code&) noexcept;
365 
366  path proximate(const path& __p, const path& __base, error_code& __ec);
367  path proximate(const path& __p, const path& __base, error_code& __ec);
368 
369  path relative(const path& __p, const path& __base, error_code& __ec);
370 
371  file_status status(const path&);
372  file_status status(const path&, error_code&) noexcept;
373 
374  bool status_known(file_status) noexcept;
375 
376  file_status symlink_status(const path&);
377  file_status symlink_status(const path&, error_code&) noexcept;
378 
379  bool is_regular_file(file_status) noexcept;
380  bool is_symlink(file_status) noexcept;
381 
382  // @} group filesystem
383 } // namespace filesystem
384 
385 _GLIBCXX_END_NAMESPACE_VERSION
386 } // namespace std
387 
388 #endif // C++17
389 
390 #endif // _GLIBCXX_FS_FWD_H
ISO C++ entities toplevel namespace is std.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1451
duration< int64_t > seconds
seconds
Definition: chrono:614
bitset< _Nb > operator &(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1433
duration< int64_t, nano > nanoseconds
nanoseconds
Definition: chrono:605
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1442
_Iterator __base(_Iterator __it)