From man 3 open :
If both O_DSYNC and O_RSYNC set to oflag , all the I / O operations in the file descriptor are completed as determined by the completion of the data integrity of the synchronized I / O.
Hence the correct call
open("file.txt", O_DSYNC | O_RSYNC);
Note that fopen does not accept O_ flags (it uses mode lines such as "r+" ), and therefore you cannot use any of the O_*SYNC parameters with it.
source share