summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2024-04-22 08:04:58 +1000
committer Vas Crabb <vas@vastheman.com>2024-04-22 08:04:58 +1000
commit184292b730f4236bd4840e780fdad97ee060ec84 (patch)
tree67902161a465fe92aec78ca502de07092b8cde0f /3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp
parent24154bc1f00790f344120b3a85175d6f616c5ad0 (diff)
3rdparty/asio: Updated to 1.30.2
Diffstat (limited to '3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp')
-rw-r--r--3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp b/3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp
new file mode 100644
index 00000000000..6e111b4909d
--- /dev/null
+++ b/3rdparty/asio/src/examples/cpp11/files/blocking_file_copy.cpp
@@ -0,0 +1,65 @@
+//
+// blocking_file_copy.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <iostream>
+#include "asio.hpp"
+
+#if defined(ASIO_HAS_FILE)
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 3)
+ {
+ std::cerr << "Usage: blocking_file_copy <from> <to>\n";
+ return 1;
+ }
+
+ asio::io_context io_context;
+
+ asio::stream_file from_file(io_context, argv[1],
+ asio::stream_file::read_only);
+
+ asio::stream_file to_file(io_context, argv[2],
+ asio::stream_file::write_only
+ | asio::stream_file::create
+ | asio::stream_file::truncate);
+
+ char data[4096];
+ std::error_code error;
+ for (;;)
+ {
+ std::size_t n = from_file.read_some(asio::buffer(data), error);
+ if (error)
+ break;
+ asio::write(to_file, asio::buffer(data, n), error);
+ if (error)
+ break;
+ }
+
+ if (error && error != asio::error::eof)
+ {
+ std::cerr << "Error copying file: " << error.message() << "\n";
+ return 1;
+ }
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ return 1;
+ }
+
+ return 0;
+}
+
+#else // defined(ASIO_HAS_FILE)
+int main() {}
+#endif // defined(ASIO_HAS_FILE)