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