[mlir] Allow fallback from file line col range to loc (#124321)
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.copy_file / copy_file_procfs.pass.cpp
blob29bc8e41250d225fb24b41a89cd8c4edc4988cf1
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // REQUIRES: linux
11 // UNSUPPORTED: no-filesystem
12 // XFAIL: no-localization
13 // UNSUPPORTED: availability-filesystem-missing
15 // <filesystem>
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;
23 #include <cassert>
24 #include <filesystem>
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);
41 scoped_test_env env;
42 std::error_code ec = GetTestEC();
44 const fs::path dest = env.make_env_path("dest");
46 assert(copy_file(procfile, dest, ec));
47 assert(!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);
52 return 0;