Home > Software engineering >  Is it safe to use fclose() on a temporary file created by tmpfile()?
Is it safe to use fclose() on a temporary file created by tmpfile()?

Time:02-07

According to this documentation, the temporary file created by tmpfile() is closed and deleted when the program exits normally. So far, I have not found any details regarding the use of fclose() on such file.

CodePudding user response:

Is it safe to use fclose() on a temporary file created by tmpfile()?

Yes, OK to close.

The tmpfile function creates a temporary binary file that is different from any other existing file and that will automatically be removed when it is closed or at program termination. If the program terminates abnormally, whether an open temporary file is removed is implementation-defined.
C17dr § 7.21.4.3 2

  •  Tags:  
  • Related