[Lazarus] Safe temp file name

Aradeonas aradeonas at operamail.com
Wed Nov 25 16:27:05 CET 2015

Thanks Graeme,Its like what I do so it seems Im doing OK. I looked at
the code and it seems it just remove { and }.
> if (LValue[1] = '{') and    (LValue[cGUIDLength] = '}') then    LValue
> := Copy(lValue, 2, cGUIDLength - 2);  AAssignTo.AsString := LValue;

It seems it doesnt remove "-" .

> This may be an appropriate use for EnterCriticalSection and
> ExitCriticalSection, although why don't you just use a different
> "prefix" in the call to GetTempFile for each thread.

Yes I can but GUID is easier to use.
> I wasn't aware that GetTempFileName isn't threadsafe.
(Are you sure your code is correct?) Yea. If you look at the
implementation it just check until there isnt a file so if 2 thread get
a filename before they create it it cause a problem. In my case I made
100 thread and they will create temp file and use them,simple but some
time it will happen.

> var
   GUID : TGUID; begin if CreateGUID(GUID) = 0 then begin  MyFileName :=
   GuiDToString(Guid); end;


Regards, Ara

http://www.fastmail.com - mmm... Fastmail...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20151125/9508adcf/attachment-0003.html>

More information about the Lazarus mailing list