C++ : Opening a file in non exclusive mode

后端 未结 5 710
深忆病人
深忆病人 2021-01-19 02:23

I have to develop an application which parses a log file and sends specific data to a server. It has to run on both Linux and Windows.

The problem appears when I wa

5条回答
  •  情书的邮戳
    2021-01-19 02:55

    If you are only reading from the file I know it can be done with windows api CreateFile. Just specify FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE as the input to dwShareMode.

    Unfortunally this is not crossplatform. But there might be something similar for Linux.

    See msdn for more info on CreateFile.

    EDIT: Just a quick note about Greg Hewgill comment. I've just tested with the FILE_SHARE* stuff (too be 100% sure). And it is possible to both delete and rename files in windows if you open read only and specify the FILE_SHARE* parameters.

提交回复
热议问题