Is there an alternative to fsync for windows? (C++ builder)
Fsync required to include unistd.h and it's only for unix systems
Thanks!
The fsync is used to coordinate a file's in-core state with any storage device. The fsync() system call passes (“flushes”) all altered in-core content of (i.e., altered buffer for) the file descriptor fd to a disc machine (or any other perpetual storing device) where such a file remains.
But is that the case: is there a call to fsync from fflush ? No, calling fflush on a POSIX system does not imply that fsync will be called. Saying that the data is to be written, rather than that is is written implies that further buffering by the host environment is permitted.
For z/OS UNIX file system files, the fflush() function copies the data from the runtime buffer to the file system. The fsync() function copies the data from the file system buffer to the storage device.
The fsync() function is intended to force a physical write of data from the buffer cache, and to assure that after a system crash or other failure that all data up to the time of the fsync() call is recorded on the disk.
From the man-page:
fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function.
The mentioned write function tells the operating system what the contents of the file should be. At this point all changes will be held in filesystem caches before actually being committed to disk.
The POSIX function fsync()
tells the operating system to sync all changes from its caches to disk. As others have said you can use FlushFileBuffers
on the Windows platform.
_commit
looks about right, it takes a file descriptor just like fsync
does:
The _commit function forces the operating system to write the file associated with fd to disk. This call ensures that the specified file is flushed immediately, not at the operating system's discretion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With