C++ Logo

std-proposals

Advanced search

[o]fstream should offer an atomic creation mode

From: Michael Knaup <michael.knaup_at_[hidden]>
Date: Thu, 15 Apr 2021 11:32:00 +0200
Hello everybody,
From a security point of view there should be an ios_base::create which allows to create a file in an atomic way only if it does not exist. So something like
 
std::ofstream outputFile { “file.conf”, ios_base::create };
 
The current solution would be either using the filesystem facility exists support which makes it non-atomic or an ios_base::out | ios_base::in + is_open hack which interferes with file system permissions.
 
So to me it looks like the library is missing a required feature here.
 
Kind regards,
Michael Knaup

Received on 2021-04-15 04:32:05