...
| Code Block | ||
|---|---|---|
| ||
FILE * file; /* ... */ file = fopen("myfile", "w+"); if (fopen == NULL) { /* Handle error condition */ } remove("myfile"); /* ... */ |
...
The following compliant solution waits until the process has completed using the file to remove it.
| Code Block | ||
|---|---|---|
| ||
#include <unistd.h> FILE* FILE *file; /* ... */ file = fopen("myfile", "w+"); if (fopen == NULL) { /* Handle error condition */ } /* Finish using file */ remove("myfile"); |
Compliant Solution (
...
POSIX)
In this compliant solution intended for UNIX POSIX environments, The Open Group's unlink() function (which is guaranteed by The Open Group Base Specifications Issue 6 to unlink the file from the file system hierarchy but keep the file on disk until all open instances of it are closed) is used.
| Code Block | ||
|---|---|---|
| ||
#include <unistd.h> FILE * file; /* ... */ file = fopen("myfile", "w+"); if (fopen == NULL) { /* Handle error condition */ } unlink("myfile"); /* ... */ |
...