summaryrefslogtreecommitdiffstats
path: root/lib/Utils/copyfd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Utils/copyfd.cpp')
-rw-r--r--lib/Utils/copyfd.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Utils/copyfd.cpp b/lib/Utils/copyfd.cpp
index cda52b03..9abe7522 100644
--- a/lib/Utils/copyfd.cpp
+++ b/lib/Utils/copyfd.cpp
@@ -105,3 +105,25 @@ off_t copyfd_eof(int fd1, int fd2)
{
return full_fd_action(fd1, fd2, 0);
}
+
+off_t copy_file(const char *src_name, const char *dst_name)
+{
+ off_t r;
+ int src = open(src_name, O_RDONLY);
+ if (src < 0)
+ {
+ perror_msg("Can't open '%s'", src_name);
+ return -1;
+ }
+ int dst = open(dst_name, O_WRONLY | O_TRUNC | O_CREAT, 0666);
+ if (dst < 0)
+ {
+ close(src);
+ perror_msg("Can't open '%s'", dst_name);
+ return -1;
+ }
+ r = copyfd_eof(src, dst);
+ close(src);
+ close(dst);
+ return r;
+}