Versions Compared

Key

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

...

Code Block
bgColor#ccccff
char sfn[] = "/tmp/temp-XXXXXX";
FILE *sfp;
int fd = -1;

if (fd = mkstemp(sfn)) == -1) {
  /* Handle Error */
}

if (sfp = fdopen(fd, "w+")) == NULL) {
    unlink(sfn);
    close(fd);
  }
  /* Handle Error */
}

unlink(sfn); /* unlink immediately to allow name to be recycled*/
/* use temporary file */
fclose(sfp); /* also closes fd */

...