What does std::ofstream::close() actually do?
c++, flush, fstream
Solution
Other than flushing the userspace buffers, i.e. `flush()`, `close(2)` is called on the underlying file-descriptor. It depends on the operating system what happens then, but most likely nothing happens to the actual storage occupied by the file.
What will happen is that the (if the file descriptor was the last reference in that process to that file) file entry associated with the file gets removed from the open-file table of the process. I.e. freeing process-associated kernel-memory.
Problem
This question: How to protect log from application crash? has lead me to another - what does `std::ofstream::close()` actually do? I know it calls `flush()` and that's one thing. But what else? What closing the file actually is? Edit: Let me rephrase my question - is anything physically done to the actual file during the call to `close()` or is it just `std::ofstream` internal cleanup stuff?