I'm porting a program that used stdio file facilities to use an std::ofstream instead. The original program uses fsync to force a file's buffers out to the disk. The fsync() is used because I'm writing a logging file, and want to ensure that data is written ASAP (i.e., before a crash). The log file is always open, until the program is terminated.
I cannot figure out how to force the flush to disk with ofstream. I've tried the flush() call, but that just flushes the program's buffers out into the file system's buffers, and does not guarantee that the data is physically written to disk. I can observe an LED that lights up when the write actually takes place,
How do I emulate fsync() with an ofstream?