[fpc-pascal] GetTempFileName in Linux

Sven Barth pascaldragon at googlemail.com
Fri Oct 8 13:32:24 CEST 2010


Am 08.10.2010 11:43, schrieb Michael Van Canneyt:
>
>
> On Fri, 8 Oct 2010, Sven Barth wrote:
>
>> Am 08.10.2010 10:03, schrieb Michael Van Canneyt:
>>>> So when changing/improving GetTempFileName we could also try to make
>>>> it compatible to such applications by creating a directory in TEMP for
>>>> the temporary file that contains the appname and the user.
>>>
>>> The current implementation does just that. It uses GetTempDir which
>>> checks
>>> TEMP and TMP (in that order), and if neither is set, uses /tmp.
>>>
>>> Note also that you can hook in the temporary filename mechanism by
>>> setting
>>> OnGetTempFile and doing it all yourself.
>>
>> I'm aware of that (btw: is this OnGetTempFile possible on Windows as
>> well?).
>
> It should be ?
>

Seems that I'll need to check that.

>> :)
>>
>> But maybe we can use by default something like the following if
>> HAS_GETTEMPFILENAME is not set (pseudo code):
>>
>> if OnGetTempFilename <> Nil then
>> OnGetTempFilename(Prefix)
>> else begin
>> dir := FindTempDir + PathDelim + GetAppName + '-' + GetUserName;
>> CreateTempFileInDir(dir, Prefix);
>> end;
>>
>> * FindTempDir searches for a suitable environment var (TEMP, TMP, /tmp)
>> * GetAppName uses the GetAppName that is used for GetConfigDir as well
>> (might be named differently, I'm not looking at the source currently)
>> * GetUserName returns the name of the current logged on user (could be
>> empty if the username can not be found)
>
> There is no user name info; at most the UID can be retrieved.

Let me guess: UID->username is a libc function...

>
> Secondly, the fallback should work on all platforms, so username etc. are
> not relevant.

Ok... what about providing an event for retrieving the temp directory? 
(or is there already?) Thus one can rely on the behavior that the file 
is created when you call GetTempFilename (which is a todo as we now know 
^^) and one can also customize its location if one wants to support 
something like AppArmor, etc.

>
> We're discussing a unix solution, so this will be implemented for unix
> only.

I'm aware of this.

Regards,
Sven



More information about the fpc-pascal mailing list