Guaranteed file deletion upon program termination (C/C++)

前端 未结 8 1259
长发绾君心
长发绾君心 2020-12-14 02:16

Win32\'s CreateFile has FILE_FLAG_DELETE_ON_CLOSE, but I\'m on Linux.

I want to open a temporary file which will always be deleted upon program terminat

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 03:08

    I just joined stackoverflow and found you here :)

    If you're problem is to manage mq files and keep them from piling up, you don't really need to guarantee file deletion upon termination. If you just wanted to useless files from piling up, than keeping a journal may be all you need. Add an entry to the journal file after a mq is opened, another entry when it is closed, and when your library is initialized, check for inconsistency in the journal and take whatever action needed to correct the inconsistency. If you worry about crashing when mq_open/mq_close is being called, you can also add an journal entry just before those functions are called.

提交回复
热议问题