...
In this example, a file name is supplied to fopen()
to create and open for writing. HowerverHowever, there is no gauruntee guaruntee that the file referenced by file_name
does not exist prior to calling fopen()
. This may cause an unintended file to be overwritten.
...
Compliant Solution 1.
The open()
function (defined in the POSIX standardOpen Group 04b) provides a a way to test for file existence . If the O_CREAT
and O_EXCL
flags are used together, the open()
function will fail if the file file specified by file_name
already exists.
...