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

前端 未结 8 1264
长发绾君心
长发绾君心 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:03

    In the past, I have build a "temporary file manager" that kept track of temporary files.

    One would request a temporary file name from the manager and this name was registered.

    Once you don't need the temporary file name any more, you inform the manager and the filename is unregistered.

    Upon receipt of a termination signal, all the registered temporary files were destroyed.

    Temporary filenames were UUID based to avoid collisions.

提交回复
热议问题