Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/boost/beast/core/detail/win32_unicode_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class win32_unicode_path

public:
win32_unicode_path(const char* utf8_path, error_code& ec) {
ec = {};
int ret = mb2wide(utf8_path, static_buf_.data(),
static_buf_.size());
if (ret == 0)
Expand Down
4 changes: 3 additions & 1 deletion include/boost/beast/core/impl/file_posix.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,13 @@ read(void* buffer, std::size_t n, error_code& ec) const
if(result == 0)
{
// short read
return nread;
break;
}
n -= result;
nread += result;
buffer = static_cast<char*>(buffer) + result;
}
ec = {};
return nread;
}

Expand Down Expand Up @@ -328,6 +329,7 @@ write(void const* buffer, std::size_t n, error_code& ec)
nwritten += result;
buffer = static_cast<char const*>(buffer) + result;
}
ec = {};
return nwritten;
}

Expand Down
2 changes: 2 additions & 0 deletions include/boost/beast/core/impl/file_stdio.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ read(void* buffer, std::size_t n, error_code& ec) const
ec.assign(errno, generic_category());
return 0;
}
ec = {};
return nread;
}

Expand All @@ -318,6 +319,7 @@ write(void const* buffer, std::size_t n, error_code& ec)
ec.assign(errno, generic_category());
return 0;
}
ec = {};
return nwritten;
}

Expand Down
74 changes: 74 additions & 0 deletions test/beast/core/file_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,80 @@ test_file()
}

BEAST_EXPECT(! fs::exists(path));
{
string_view const s = "Hello, world!";

{
File f;
error_code ec = make_error_code(errc::no_such_file_or_directory);
f.open(path, file_mode::write, ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::write, ec);
BEAST_EXPECT(! ec);
ec = make_error_code(errc::no_such_file_or_directory);
f.write(s.data(), s.size(), ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::read, ec);
BEAST_EXPECT(! ec);
ec = make_error_code(errc::no_such_file_or_directory);
f.size(ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::read, ec);
BEAST_EXPECT(! ec);
ec = make_error_code(errc::no_such_file_or_directory);
f.pos(ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::read, ec);
BEAST_EXPECT(! ec);
ec = make_error_code(errc::no_such_file_or_directory);
f.seek(0, ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::read, ec);
BEAST_EXPECT(! ec);
std::string buf;
buf.resize(s.size());
ec = make_error_code(errc::no_such_file_or_directory);
f.read(&buf[0], buf.size(), ec);
BEAST_EXPECT(! ec);
}

{
File f;
error_code ec;
f.open(path, file_mode::read, ec);
BEAST_EXPECT(! ec);
ec = make_error_code(errc::no_such_file_or_directory);
f.close(ec);
BEAST_EXPECT(! ec);
}

remove(path);
}
}

} // beast
Expand Down
1 change: 1 addition & 0 deletions tools/get-boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ git submodule update --init --depth 20 --jobs 4 \
libs/ratio \
libs/rational \
libs/regex \
libs/static_assert \
libs/thread \
libs/tuple \
libs/type_index \
Expand Down