ofstream_synced close

This commit is contained in:
Robin Davies
2024-09-03 02:06:53 -04:00
parent b8c4fafd3a
commit b35d6a982d
2 changed files with 8 additions and 4 deletions
@@ -10,6 +10,7 @@ namespace pipedal
class ofstream_synced : public std::ofstream
{
public:
using super = std::ofstream;
ofstream_synced() {}
explicit ofstream_synced(const std::string &filename, ios_base::openmode mode = ios_base::out)
@@ -20,6 +21,7 @@ namespace pipedal
: std::ofstream(filename, mode)
{
}
void close();
~ofstream_synced();
};
+6 -4
View File
@@ -8,12 +8,14 @@ void pipedal::FileSystemSync()
{
::sync();
}
ofstream_synced::~ofstream_synced()
{
void ofstream_synced::close() {
if (is_open())
{
close();
super::close();
::sync();
}
}
ofstream_synced::~ofstream_synced()
{
ofstream_synced::close();
}