Skip to content

Commit

Permalink
Make flush public
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 30, 2021
1 parent f1794a8 commit bba0a9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,6 @@ class FMT_API ostream final : private detail::buffer<char> {
private:
file file_;

void flush() {
if (size() == 0) return;
file_.write(data(), size());
clear();
}

void grow(size_t) override;

ostream(cstring_view path, const detail::ostream_params& params)
Expand All @@ -426,6 +420,12 @@ class FMT_API ostream final : private detail::buffer<char> {
delete[] data();
}

void flush() {
if (size() == 0) return;
file_.write(data(), size());
clear();
}

template <typename... T>
friend ostream output_file(cstring_view path, T... params);

Expand Down
8 changes: 8 additions & 0 deletions test/os-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ TEST(ostream_test, truncate) {
EXPECT_EQ("foo", read(in, 4));
}

TEST(ostream_test, flush) {
auto out = fmt::output_file("test-file");
out.print("x");
out.flush();
auto in = fmt::file("test-file", file::RDONLY);
EXPECT_READ(in, "x");
}

TEST(file_test, default_ctor) {
file f;
EXPECT_EQ(-1, f.descriptor());
Expand Down

0 comments on commit bba0a9d

Please sign in to comment.