Secure temporary file: Difference between revisions

→‎{{header|Julia}}: A new entry for Julia
(→‎{{header|Go}}: Explicitly close the temporary file; also actually use the file a little bit (grr.. damn recaptcha crap))
(→‎{{header|Julia}}: A new entry for Julia)
Line 218:
} catch (IOException e) {
}</lang>
 
=={{header|Julia}}==
{{works with|Linux}} On Unix systems, Julia calls <code>mkstemp</code> to securely open a temporary file. This is likely multi-thread safe, check your system documentation for verification. This code should also work on Windows, but I've not verified that.
<lang Julia>
msg = "Rosetta Code, Secure temporary file, implemented with Julia."
 
(fname, tio) = mktemp()
println(fname, " created as a temporary file.")
println(tio, msg)
close(tio)
println("\"", msg, "\" written to ", fname)
</lang>
Files written to <code>\tmp</code> persist for the login session, and are thus truly temporary. If the environment variable <code>TMPDIR</code> is set, the temporary file is created in this directory. In this case, the file may not be properly temporary.
<lang Julia>
ENV["TMPDIR"] = pwd()
(fname, tio) = mktemp()
println(fname, " created as a \"temporary\" file.")
println(tio, msg)
close(tio)
println("\"", msg, "\" written to ", fname)
</lang>
 
{{out}}
<pre>
/tmp/tmphe0qlu created as a temporary file.
"Rosetta Code, Secure temporary file, implemented with Julia." written to /tmp/tmphe0qlu
/home/mike/rosetta/julia/tmpVNGK8D created as a "temporary" file.
"Rosetta Code, Secure temporary file, implemented with Julia." written to /home/joeb/rosetta/julia/tmpVNGK8D
$ cat /tmp/tmphe0qlu
Rosetta Code, Secure temporary file, implemented with Julia.
$ ls -l /tmp/tmphe0qlu
-rw------- 1 joeb joeb 61 Apr 13 13:18 /tmp/tmphe0qlu
$ cat tmpVNGK8D
Rosetta Code, Secure temporary file, implemented with Julia.
$ ls -l tmpVNGK8D
-rw------- 1 joeb jeob 61 Apr 13 13:18 tmpVNGK8D
</pre>
 
=={{header|Lua}}==
<lang lua>fp = io.tmpfile()