Commit 0657379e by Uros Bizjak Committed by Uros Bizjak

ops.cc: Always include ostream and ext/stdio_filebuf.h.

	* src/filesystem/ops.cc: Always include ostream and
	ext/stdio_filebuf.h.
	(do_copy_file): Check if _GLIBCXX_USE_FCHMODAT is defined.
	[_GLIBCXX_USE_SENDFILE]: Fallback to read/write operations in case
	sendfile fails with ENOSYS or EINVAL.

From-SVN: r239479
parent 2e6fc1ac
2016-08-15 Uros Bizjak <ubizjak@gmail.com>
* src/filesystem/ops.cc: Always include ostream and
ext/stdio_filebuf.h.
(do_copy_file): Check if _GLIBCXX_USE_FCHMODAT is defined.
[_GLIBCXX_USE_SENDFILE]: Fallback to read/write operations in case
sendfile fails with ENOSYS or EINVAL.
2016-08-15 Thomas Preud'homme <thomas.preudhomme@arm.com> 2016-08-15 Thomas Preud'homme <thomas.preudhomme@arm.com>
PR libstdc++/72840 PR libstdc++/72840
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include <experimental/filesystem> #include <experimental/filesystem>
#include <functional> #include <functional>
#include <ostream>
#include <stack> #include <stack>
#include <ext/stdio_filebuf.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
...@@ -48,9 +50,6 @@ ...@@ -48,9 +50,6 @@
#endif #endif
#ifdef _GLIBCXX_USE_SENDFILE #ifdef _GLIBCXX_USE_SENDFILE
# include <sys/sendfile.h> # include <sys/sendfile.h>
#else
# include <ext/stdio_filebuf.h>
# include <ostream>
#endif #endif
#if _GLIBCXX_HAVE_UTIME_H #if _GLIBCXX_HAVE_UTIME_H
# include <utime.h> # include <utime.h>
...@@ -416,7 +415,7 @@ namespace ...@@ -416,7 +415,7 @@ namespace
#ifdef _GLIBCXX_USE_FCHMOD #ifdef _GLIBCXX_USE_FCHMOD
if (::fchmod(out.fd, from_st->st_mode)) if (::fchmod(out.fd, from_st->st_mode))
#elif _GLIBCXX_USE_FCHMODAT #elif defined _GLIBCXX_USE_FCHMODAT
if (::fchmodat(AT_FDCWD, to.c_str(), from_st->st_mode, 0)) if (::fchmodat(AT_FDCWD, to.c_str(), from_st->st_mode, 0))
#else #else
if (::chmod(to.c_str(), from_st->st_mode)) if (::chmod(to.c_str(), from_st->st_mode))
...@@ -428,37 +427,45 @@ namespace ...@@ -428,37 +427,45 @@ namespace
#ifdef _GLIBCXX_USE_SENDFILE #ifdef _GLIBCXX_USE_SENDFILE
const auto n = ::sendfile(out.fd, in.fd, nullptr, from_st->st_size); const auto n = ::sendfile(out.fd, in.fd, nullptr, from_st->st_size);
if (n != from_st->st_size) if (n < 0 && (errno == ENOSYS || errno == EINVAL))
{ {
ec.assign(errno, std::generic_category()); #endif
return false; __gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in);
__gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out);
if (sbin.is_open())
in.fd = -1;
if (sbout.is_open())
out.fd = -1;
if (from_st->st_size && !(std::ostream(&sbout) << &sbin))
{
ec = std::make_error_code(std::errc::io_error);
return false;
}
if (!sbout.close() || !sbin.close())
{
ec.assign(errno, std::generic_category());
return false;
}
ec.clear();
return true;
#ifdef _GLIBCXX_USE_SENDFILE
} }
if (!out.close() || !in.close()) if (n != from_st->st_size)
{ {
ec.assign(errno, std::generic_category()); ec.assign(errno, std::generic_category());
return false; return false;
} }
#else if (!out.close() || !in.close())
__gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in);
__gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out);
if (sbin.is_open())
in.fd = -1;
if (sbout.is_open())
out.fd = -1;
if (from_st->st_size && !(std::ostream(&sbout) << &sbin))
{
ec = std::make_error_code(std::errc::io_error);
return false;
}
if (!sbout.close() || !sbin.close())
{ {
ec.assign(errno, std::generic_category()); ec.assign(errno, std::generic_category());
return false; return false;
} }
#endif
ec.clear(); ec.clear();
return true; return true;
#endif
} }
} }
#endif #endif
......
Markdown is supported
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