Secure temporary file: Difference between revisions
Content added Content deleted
(Scala) |
|||
Line 22: | Line 22: | ||
=={{header|C}}== |
=={{header|C}}== |
||
<lang c>#include < |
<lang c>#include <stdlib.h> |
||
#include <stdio.h> |
|||
int main() |
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> |
}</lang> |
||
Line 41: | Line 37: | ||
#include <stdio.h> |
#include <stdio.h> |
||
int main() |
int main(void) |
||
{ |
|||
const char *filename = "/tmp/prefixXXXXXX"; |
|||
int fd = mkstemp(filename); |
|||
const int fd = mkstemp(filename); |
|||
(void) puts(filename); |
|||
/* do stuff with file descriptor "fd" */ |
|||
(void) close(fd); |
|||
return EXIT_SUCCESS; |
|||
}</lang> |
}</lang> |
||