[fpc-devel] Bug in SysUtils.GetTempFileName?

Sergei Gorelkin sergei_gorelkin at mail.ru
Fri Sep 1 09:42:49 CEST 2006


Hello,

I've hit another segfault, this time it was code calling
WinApi function GetTempFileName(). Resolving the call explicitly to
Windows.GetTempFileName() works. It appears that problem is
in cross-platform analog of GetTempFileName() that is contained in SysUtils
unit.
Looking at the RTL source, I could not figure out how it's expected to work.
In 'rtl/objpas/osutilsh.inc' there is a declaration:

function GetTempFileName(Dir,Prefix: PChar; uUnique: DWORD; TempFileName: PChar):DWORD;
(note that it's not compatible with WinApi because 'stdcall' is
missing!)

The corresponding implementation in 'rtl/objpas/osutil.inc' is compiled
conditionally:

{$if not(defined(win32)) and not(defined(win64))}
function GetTempFileName(...
...
{$endif}

Naturally, under Windows the function is not needed because it's contained in
WinApi. But then function declaration in interface must also be wrapped into
conditional section, otherwise how such code gets compiled?

-- 
Best regards,
 Sergei





More information about the fpc-devel mailing list