Reputation: 3425
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
Upvotes: 5
Views: 5356
Reputation: 179717
From man 3 open
:
If both
O_DSYNC
andO_RSYNC
are 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.
Upvotes: 9