Jump to content

Secure temporary file: Difference between revisions

(Scala)
Line 22:
 
=={{header|C}}==
<lang c>#include <stdiostdlib.h>
#include <stdio.h>
 
int main(void) {
{
FILE *fh = tmpfile(); /* file is automatically deleted when program exits */
/* do stuff with stream "fh" */
(void) fclose(fh);
return EXIT_SUCCESS;
/* The C standard library also has a tmpnam() function to create a file
for you to open later. But you should not use it because someone else might
be able to open the file from the time it is created by this function to the
time you open it. */
return 0;
}</lang>
 
Line 41 ⟶ 37:
#include <stdio.h>
 
int main(void) {
{
const char *filename[] = "/tmp/prefixXXXXXX";
int fd = mkstemp(filename);
const int putsfd = mkstemp(filename);
(void) puts(filename);
/* do stuff with file descriptor "fd" */
(void) close(fd);
return 0EXIT_SUCCESS;
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.