1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // XFAIL: no-localization
13 // UNSUPPORTED: availability-filesystem-missing
17 // bool copy_file(const path& from, const path& to);
18 // bool copy_file(const path& from, const path& to, error_code& ec) noexcept;
19 // bool copy_file(const path& from, const path& to, copy_options options);
20 // bool copy_file(const path& from, const path& to, copy_options options,
21 // error_code& ec) noexcept;
25 #include <system_error>
27 #include "test_macros.h"
28 #include "filesystem_test_helper.h"
30 namespace fs
= std::filesystem
;
32 // Linux has various virtual filesystems such as /proc and /sys
33 // where files may have no length (st_size == 0), but still contain data.
34 // This is because the to-be-read data is usually generated ad-hoc by the reading syscall
35 // These files can not be copied with kernel-side copies like copy_file_range or sendfile,
36 // and must instead be copied via a traditional userspace read + write loop.
37 int main(int, char** argv
) {
38 const fs::path procfile
{"/proc/self/comm"};
39 assert(file_size(procfile
) == 0);
42 std::error_code ec
= GetTestEC();
44 const fs::path dest
= env
.make_env_path("dest");
46 assert(copy_file(procfile
, dest
, ec
));
49 // /proc/self/comm contains the filename of the executable, plus a null terminator
50 assert(file_size(dest
) == fs::path(argv
[0]).filename().string().size() + 1);