1// Filesystem declarations -*- C++ -*-
2
3// Copyright (C) 2014-2022 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 experimental/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{experimental/filesystem}
28 */
29
30#ifndef _GLIBCXX_EXPERIMENTAL_FS_FWD_H
31#define _GLIBCXX_EXPERIMENTAL_FS_FWD_H 1
32
33#if __cplusplus < 201103L
34# include <bits/c++0x_warning.h>
35#else
36
37#include <system_error>
38#include <cstdint>
39#include <bits/chrono.h>
40
41namespace std _GLIBCXX_VISIBILITY(default)
42{
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
44
45namespace experimental
46{
47namespace filesystem
48{
49inline namespace v1
50{
51#if _GLIBCXX_USE_CXX11_ABI
52inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
53#endif
54
55  /**
56   * @defgroup filesystem-ts Filesystem TS
57   * @ingroup experimental
58   *
59   * Utilities for performing operations on file systems and their components,
60   * such as paths, regular files, and directories.
61   *
62   * ISO/IEC TS 18822:2015	C++ File System Technical Specification
63   *
64   * @since C++11
65   *
66   * @remark Link using `-lstdc++fs` to use these types and functions.
67   *
68   * @{
69   */
70
71  class file_status;
72_GLIBCXX_BEGIN_NAMESPACE_CXX11
73  class path;
74  class filesystem_error;
75  class directory_entry;
76  class directory_iterator;
77  class recursive_directory_iterator;
78_GLIBCXX_END_NAMESPACE_CXX11
79
80  /// Information about free space on a disk
81  struct space_info
82  {
83    uintmax_t capacity;
84    uintmax_t free;
85    uintmax_t available;
86  };
87
88  /// Enumerated type representing the type of a file
89  enum class file_type : signed char {
90      none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
91      block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
92  };
93
94  /// Bitmask type controlling effects of `filesystem::copy`
95  enum class copy_options : unsigned short {
96      none = 0,
97      skip_existing = 1, overwrite_existing = 2, update_existing = 4,
98      recursive = 8,
99      copy_symlinks = 16, skip_symlinks = 32,
100      directories_only = 64, create_symlinks = 128, create_hard_links = 256
101  };
102
103  /// @{
104  /// @relates copy_options
105  constexpr copy_options
106  operator&(copy_options __x, copy_options __y) noexcept
107  {
108    using __utype = typename std::underlying_type<copy_options>::type;
109    return static_cast<copy_options>(
110	static_cast<__utype>(__x) & static_cast<__utype>(__y));
111  }
112
113  constexpr copy_options
114  operator|(copy_options __x, copy_options __y) noexcept
115  {
116    using __utype = typename std::underlying_type<copy_options>::type;
117    return static_cast<copy_options>(
118	static_cast<__utype>(__x) | static_cast<__utype>(__y));
119  }
120
121  constexpr copy_options
122  operator^(copy_options __x, copy_options __y) noexcept
123  {
124    using __utype = typename std::underlying_type<copy_options>::type;
125    return static_cast<copy_options>(
126	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
127  }
128
129  constexpr copy_options
130  operator~(copy_options __x) noexcept
131  {
132    using __utype = typename std::underlying_type<copy_options>::type;
133    return static_cast<copy_options>(~static_cast<__utype>(__x));
134  }
135
136  inline copy_options&
137  operator&=(copy_options& __x, copy_options __y) noexcept
138  { return __x = __x & __y; }
139
140  inline copy_options&
141  operator|=(copy_options& __x, copy_options __y) noexcept
142  { return __x = __x | __y; }
143
144  inline copy_options&
145  operator^=(copy_options& __x, copy_options __y) noexcept
146  { return __x = __x ^ __y; }
147  /// @}
148
149  /// Bitmask type representing file access permissions
150  enum class perms : unsigned {
151      none		=  0,
152      owner_read	=  0400,
153      owner_write	=  0200,
154      owner_exec	=  0100,
155      owner_all		=  0700,
156      group_read	=   040,
157      group_write	=   020,
158      group_exec	=   010,
159      group_all		=   070,
160      others_read	=    04,
161      others_write	=    02,
162      others_exec	=    01,
163      others_all	=    07,
164      all		=  0777,
165      set_uid		= 04000,
166      set_gid		= 02000,
167      sticky_bit	= 01000,
168      mask		= 07777,
169      unknown		=  0xFFFF,
170      add_perms		= 0x10000,
171      remove_perms	= 0x20000,
172      symlink_nofollow	= 0x40000
173  };
174
175  /// @{
176  /// @relates std::experimental::filesystem::perms
177  constexpr perms
178  operator&(perms __x, perms __y) noexcept
179  {
180    using __utype = typename std::underlying_type<perms>::type;
181    return static_cast<perms>(
182	static_cast<__utype>(__x) & static_cast<__utype>(__y));
183  }
184
185  constexpr perms
186  operator|(perms __x, perms __y) noexcept
187  {
188    using __utype = typename std::underlying_type<perms>::type;
189    return static_cast<perms>(
190	static_cast<__utype>(__x) | static_cast<__utype>(__y));
191  }
192
193  constexpr perms
194  operator^(perms __x, perms __y) noexcept
195  {
196    using __utype = typename std::underlying_type<perms>::type;
197    return static_cast<perms>(
198	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
199  }
200
201  constexpr perms
202  operator~(perms __x) noexcept
203  {
204    using __utype = typename std::underlying_type<perms>::type;
205    return static_cast<perms>(~static_cast<__utype>(__x));
206  }
207
208  inline perms&
209  operator&=(perms& __x, perms __y) noexcept
210  { return __x = __x & __y; }
211
212  inline perms&
213  operator|=(perms& __x, perms __y) noexcept
214  { return __x = __x | __y; }
215
216  inline perms&
217  operator^=(perms& __x, perms __y) noexcept
218  { return __x = __x ^ __y; }
219  /// @}
220
221  /// Bitmask type controlling directory iteration
222  enum class directory_options : unsigned char {
223      none = 0, follow_directory_symlink = 1, skip_permission_denied = 2
224  };
225
226  /// @{
227  /// @relates directory_options
228  constexpr directory_options
229  operator&(directory_options __x, directory_options __y) noexcept
230  {
231    using __utype = typename std::underlying_type<directory_options>::type;
232    return static_cast<directory_options>(
233	static_cast<__utype>(__x) & static_cast<__utype>(__y));
234  }
235
236  constexpr directory_options
237  operator|(directory_options __x, directory_options __y) noexcept
238  {
239    using __utype = typename std::underlying_type<directory_options>::type;
240    return static_cast<directory_options>(
241	static_cast<__utype>(__x) | static_cast<__utype>(__y));
242  }
243
244  constexpr directory_options
245  operator^(directory_options __x, directory_options __y) noexcept
246  {
247    using __utype = typename std::underlying_type<directory_options>::type;
248    return static_cast<directory_options>(
249	static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
250  }
251
252  constexpr directory_options
253  operator~(directory_options __x) noexcept
254  {
255    using __utype = typename std::underlying_type<directory_options>::type;
256    return static_cast<directory_options>(~static_cast<__utype>(__x));
257  }
258
259  inline directory_options&
260  operator&=(directory_options& __x, directory_options __y) noexcept
261  { return __x = __x & __y; }
262
263  inline directory_options&
264  operator|=(directory_options& __x, directory_options __y) noexcept
265  { return __x = __x | __y; }
266
267  inline directory_options&
268  operator^=(directory_options& __x, directory_options __y) noexcept
269  { return __x = __x ^ __y; }
270  /// @}
271
272  /// The type used for file timestamps
273  using file_time_type = std::chrono::system_clock::time_point;
274
275  // operational functions
276
277  void copy(const path& __from, const path& __to, copy_options __options);
278  void copy(const path& __from, const path& __to, copy_options __options,
279	    error_code&) noexcept;
280
281  bool copy_file(const path& __from, const path& __to, copy_options __option);
282  bool copy_file(const path& __from, const path& __to, copy_options __option,
283		 error_code&);
284
285  path current_path();
286
287  file_status status(const path&);
288  file_status status(const path&, error_code&) noexcept;
289
290  bool status_known(file_status) noexcept;
291
292  file_status symlink_status(const path&);
293  file_status symlink_status(const path&, error_code&) noexcept;
294
295  bool is_regular_file(file_status) noexcept;
296  bool is_symlink(file_status) noexcept;
297
298  /// @} group filesystem-ts
299} // namespace v1
300} // namespace filesystem
301} // namespace experimental
302
303_GLIBCXX_END_NAMESPACE_VERSION
304} // namespace std
305
306#endif // C++11
307
308#endif // _GLIBCXX_EXPERIMENTAL_FS_FWD_H
309