Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
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
bgColor#ccccff
#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
bgColor#ccccff
#include <unistd.h>

FILE * file;

/* ... */

file = fopen("myfile", "w+");
if (fopen == NULL) {
  /* Handle error condition */
}
unlink("myfile");

/* ... */

...