mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-27 03:21:34 +00:00
Truncate file by default
This commit is contained in:
parent
22a68d1613
commit
119f7dc3d6
@ -280,7 +280,8 @@ class file {
|
||||
WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only.
|
||||
RDWR = FMT_POSIX(O_RDWR), // Open for reading and writing.
|
||||
CREATE = FMT_POSIX(O_CREAT), // Create if the file doesn't exist.
|
||||
APPEND = FMT_POSIX(O_APPEND) // Open in append mode.
|
||||
APPEND = FMT_POSIX(O_APPEND), // Open in append mode.
|
||||
TRUNC = FMT_POSIX(O_TRUNC) // Truncate the content of the file.
|
||||
};
|
||||
|
||||
// Constructs a file object which doesn't represent any file.
|
||||
@ -357,7 +358,7 @@ struct buffer_size {
|
||||
};
|
||||
|
||||
struct ostream_params {
|
||||
int oflag = file::WRONLY | file::CREATE;
|
||||
int oflag = file::WRONLY | file::CREATE | file::TRUNC;
|
||||
size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
|
||||
|
||||
ostream_params() {}
|
||||
|
@ -319,6 +319,19 @@ TEST(OStreamTest, BufferSize) {
|
||||
EXPECT_READ(in, "foo");
|
||||
}
|
||||
|
||||
TEST(OStreamTest, Truncate) {
|
||||
{
|
||||
fmt::ostream out = fmt::output_file("test-file");
|
||||
out.print("0123456789");
|
||||
}
|
||||
{
|
||||
fmt::ostream out = fmt::output_file("test-file");
|
||||
out.print("foo");
|
||||
}
|
||||
file in("test-file", file::RDONLY);
|
||||
EXPECT_EQ("foo", read(in, 4));
|
||||
}
|
||||
|
||||
TEST(FileTest, DefaultCtor) {
|
||||
file f;
|
||||
EXPECT_EQ(-1, f.descriptor());
|
||||
|
Loading…
Reference in New Issue
Block a user