[fpc-pascal] GetTempFileName in Linux
Michael Van Canneyt
michael at freepascal.org
Wed Oct 6 11:05:28 CEST 2010
On Wed, 6 Oct 2010, Jonas Maebe wrote:
>
> On 06 Oct 2010, at 09:41, Michael Van Canneyt wrote:
>
>> This is always true on Unix, the only way to make sure is to have the
>> kernel
>> create the temporary name and file for you. Unix - to my knowledge - does
>> not have a way to create and lock a file in one atomic operation; There are
>> always 2 operations involved, and so anything can happen between the 2
>> calls.
>
> You can at least open a file with O_CREAT|O_EXCL|O_NOFOLLOW to make sure that
> it does not yet exist at the point that you create it (and that it's not a
> symlink either).
This is correct, but doesn't lock the file, and so it doesn't prevent
someone from 'stealing' the file before the lock is applied.
It's of course a remote possibility.
Personally, I have more problems with windows which actually creates the files
and locks them. It sometimes requires a reboot to release the lock again in
case something happens to the calling process.
That said, I repeat: no problem if someone implements a more secure
algorithm.
Michael.
More information about the fpc-pascal
mailing list