<div><div>Upon thinking more, having the temporary file on the same partition as the original file ensures that if the computer crashes, the directory entry for the original file will more likely point to valid data.</div><div><div><br data-mce-bogus="1"></div><div>So the logic should probably be as follows:</div><div><br data-mce-bogus="1"></div><div>template="pngoutXXXXXX.png.tmp";</div><div>if directory_of_the_original_file is writable and has enough space then use directory_of_the_original_file + template as a temporary file</div><div>else if $TMPDIR exists, is on the same partition as the original file, is writable, and has enough space then use $TMPDIR + "/"+ template as a temporary file</div><div>else if "/tmp" exists, is on the same partition as the original, is writable, and has enough space then use "/tmp/" + template as a temporary file</div><div>else if "/var/tmp" exists, is on the same partition as the original, is writable, and has enough space then use "/var/tmp/" + template as a temporary file</div><div>else overwrite the original file directly</div></div></div>