C file synchronization

I would like to open a file in C where the read and write are synchronized. The right way

fopen("file.txt", O_DSYNCH | O_RSYNCH) 

or

  fopen("file.txt", O_SYNCH) 

This is for use on Linux.

+4
source share
1 answer

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.

+8
source

Source: https://habr.com/ru/post/1442222/


All Articles