Commit 7d5954bb authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

System copy

parent 7abb14ef
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <array>
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
...@@ -393,6 +394,29 @@ std::string search_env_path(const std::string &filename) ...@@ -393,6 +394,29 @@ std::string search_env_path(const std::string &filename)
return std::string(); return std::string();
} }
std::string system_copy(const std::string &source,
const std::string &destination)
{
std::string copy_command;
#ifdef _WIN32
copy_command = "copy";
#else
copy_command = "cp";
#endif
std::string command =
copy_command + std::string(" ") + source + std::string(" ") + destination;
FILE *handle = pipe_open(command);
std::array<char, 128> buf;
std::string output;
while (fgets(buf.data(), int(buf.size()), handle) != NULL)
{
output += buf.data();
}
radix::pipe_close(handle);
return output;
}
// remove_file // remove_file
} // namespace radix } // namespace radix
...@@ -16,6 +16,14 @@ ...@@ -16,6 +16,14 @@
namespace radix namespace radix
{ {
/**
* @brief system_copy Uses system copy command to copy source to destination
* @param source
* @param destination
* @return std::string output of command
*/
RADIX_PUBLIC std::string system_copy(const std::string &source,
const std::string &destination);
/** /**
* @brief Provides platform independent popen call * @brief Provides platform independent popen call
* function creates a pipe and asynchronously executes a spawned * function creates a pipe and asynchronously executes a spawned
......
...@@ -224,3 +224,13 @@ TEST(System, SearchEnvPath) ...@@ -224,3 +224,13 @@ TEST(System, SearchEnvPath)
std::string path = search_env_path(app); std::string path = search_env_path(app);
EXPECT_EQ(blessed, radix::string_tolower(path)); EXPECT_EQ(blessed, radix::string_tolower(path));
} }
TEST(System, copy)
{
std::string this_file(__FILE__);
// copy the unit test source file to the current working directory
radix::system_copy(this_file, radix::current_dir());
EXPECT_TRUE(radix::file_exists(radix::basename(this_file)));
radix::remove_file(radix::basename(this_file));
EXPECT_FALSE(radix::file_exists(basename(this_file)));
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment