MCPcopy Create free account
hub / github.com/boostorg/asio / main

Function main

example/cpp11/files/blocking_file_copy.cpp:16–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#if defined(BOOST_ASIO_HAS_FILE)
15
16int main(int argc, char* argv[])
17{
18 try
19 {
20 if (argc != 3)
21 {
22 std::cerr << "Usage: blocking_file_copy <from> <to>\n";
23 return 1;
24 }
25
26 boost::asio::io_context io_context;
27
28 boost::asio::stream_file from_file(io_context, argv[1],
29 boost::asio::stream_file::read_only);
30
31 boost::asio::stream_file to_file(io_context, argv[2],
32 boost::asio::stream_file::write_only
33 | boost::asio::stream_file::create
34 | boost::asio::stream_file::truncate);
35
36 char data[4096];
37 boost::system::error_code error;
38 for (;;)
39 {
40 std::size_t n = from_file.read_some(boost::asio::buffer(data), error);
41 if (error)
42 break;
43 boost::asio::write(to_file, boost::asio::buffer(data, n), error);
44 if (error)
45 break;
46 }
47
48 if (error && error != boost::asio::error::eof)
49 {
50 std::cerr << "Error copying file: " << error.message() << "\n";
51 return 1;
52 }
53 }
54 catch (std::exception& e)
55 {
56 std::cerr << "Exception: " << e.what() << "\n";
57 return 1;
58 }
59
60 return 0;
61}
62
63#else // defined(BOOST_ASIO_HAS_FILE)
64int main() {}

Callers

nothing calls this directly

Calls 3

bufferFunction · 0.85
writeFunction · 0.85
read_someMethod · 0.45

Tested by

no test coverage detected