PR libstdc++/83279 Use non-null offset argument for sendfile
PR libstdc++/83279 * src/filesystem/std-ops.cc (do_copy_file): Use non-null offset with sendfile. From-SVN: r256289
This commit is contained in:
parent
f622221ab4
commit
2526c53acf
|
@ -1,5 +1,9 @@
|
||||||
2018-01-05 Jonathan Wakely <jwakely@redhat.com>
|
2018-01-05 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
PR libstdc++/83279
|
||||||
|
* src/filesystem/std-ops.cc (do_copy_file): Use non-null offset with
|
||||||
|
sendfile.
|
||||||
|
|
||||||
PR libstdc++/83626
|
PR libstdc++/83626
|
||||||
* src/filesystem/ops.cc (remove(const path&, error_code&)): Do not
|
* src/filesystem/ops.cc (remove(const path&, error_code&)): Do not
|
||||||
report an error for ENOENT.
|
report an error for ENOENT.
|
||||||
|
|
|
@ -382,10 +382,10 @@ fs::do_copy_file(const char* from, const char* to,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t n = 0;
|
|
||||||
size_t count = from_st->st_size;
|
size_t count = from_st->st_size;
|
||||||
#ifdef _GLIBCXX_USE_SENDFILE
|
#ifdef _GLIBCXX_USE_SENDFILE
|
||||||
n = ::sendfile(out.fd, in.fd, nullptr, count);
|
off_t offset = 0;
|
||||||
|
ssize_t n = ::sendfile(out.fd, in.fd, &offset, count);
|
||||||
if (n < 0 && errno != ENOSYS && errno != EINVAL)
|
if (n < 0 && errno != ENOSYS && errno != EINVAL)
|
||||||
{
|
{
|
||||||
ec.assign(errno, std::generic_category());
|
ec.assign(errno, std::generic_category());
|
||||||
|
@ -405,35 +405,32 @@ fs::do_copy_file(const char* from, const char* to,
|
||||||
count -= n;
|
count -= n;
|
||||||
#endif // _GLIBCXX_USE_SENDFILE
|
#endif // _GLIBCXX_USE_SENDFILE
|
||||||
|
|
||||||
__gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in);
|
using std::ios;
|
||||||
__gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out);
|
__gnu_cxx::stdio_filebuf<char> sbin(in.fd, ios::in|ios::binary);
|
||||||
|
__gnu_cxx::stdio_filebuf<char> sbout(out.fd, ios::out|ios::binary);
|
||||||
|
|
||||||
if (sbin.is_open())
|
if (sbin.is_open())
|
||||||
in.fd = -1;
|
in.fd = -1;
|
||||||
if (sbout.is_open())
|
if (sbout.is_open())
|
||||||
out.fd = -1;
|
out.fd = -1;
|
||||||
|
|
||||||
const std::streampos errpos(std::streamoff(-1));
|
#ifdef _GLIBCXX_USE_SENDFILE
|
||||||
|
if (n != 0)
|
||||||
if (n < 0)
|
|
||||||
{
|
{
|
||||||
auto p1 = sbin.pubseekoff(0, std::ios_base::beg, std::ios_base::in);
|
if (n < 0)
|
||||||
auto p2 = sbout.pubseekoff(0, std::ios_base::beg, std::ios_base::out);
|
n = 0;
|
||||||
|
|
||||||
|
const auto p1 = sbin.pubseekoff(n, ios::beg, ios::in);
|
||||||
|
const auto p2 = sbout.pubseekoff(n, ios::beg, ios::out);
|
||||||
|
|
||||||
|
const std::streampos errpos(std::streamoff(-1));
|
||||||
if (p1 == errpos || p2 == errpos)
|
if (p1 == errpos || p2 == errpos)
|
||||||
{
|
{
|
||||||
ec = std::make_error_code(std::errc::io_error);
|
ec = std::make_error_code(std::errc::io_error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (n > 0)
|
#endif
|
||||||
{
|
|
||||||
auto p = sbout.pubseekoff(n, std::ios_base::beg, std::ios_base::out);
|
|
||||||
if (p == errpos)
|
|
||||||
{
|
|
||||||
ec = std::make_error_code(std::errc::io_error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count && !(std::ostream(&sbout) << &sbin))
|
if (count && !(std::ostream(&sbout) << &sbin))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue