I would like to open a file in C where the reads and writes are both synchronized. Is the proper way
fopen("file.txt", O_DSYNCH | O_RSYNCH)
or
fopen("file.txt", O_SYNCH)
This is for use on Linux
From man 3 open:
If both
O_DSYNCandO_RSYNCare set inoflag, all I/O operations on the file descriptor shall complete as defined by synchronized I/O data integrity completion.
Therefore, the correct call is
open("file.txt", O_DSYNC | O_RSYNC);
Note that fopen does not take O_ flags (it uses mode strings like "r+"), and you therefore cannot use any of the O_*SYNC options with it directly.
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