]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp11/files/blocking_file_copy.cpp
2 // blocking_file_copy.cpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/asio.hpp>
14 #if defined(BOOST_ASIO_HAS_FILE)
16 int main(int argc
, char* argv
[])
22 std::cerr
<< "Usage: blocking_file_copy <from> <to>\n";
26 boost::asio::io_context io_context
;
28 boost::asio::stream_file
from_file(io_context
, argv
[1],
29 boost::asio::stream_file::read_only
);
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
);
37 boost::system::error_code error
;
40 std::size_t n
= from_file
.read_some(boost::asio::buffer(data
), error
);
43 boost::asio::write(to_file
, boost::asio::buffer(data
, n
), error
);
48 if (error
&& error
!= boost::asio::error::eof
)
50 std::cerr
<< "Error copying file: " << error
.message() << "\n";
54 catch (std::exception
& e
)
56 std::cerr
<< "Exception: " << e
.what() << "\n";
63 #else // defined(BOOST_ASIO_HAS_FILE)
65 #endif // defined(BOOST_ASIO_HAS_FILE)