 
                            ...
| Code Block | ||
|---|---|---|
| 
 | ||
| 
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 */
 | 
...