flat assembler
Message board for the users of flat assembler.

Index > Main > Handling Temporary Files

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 05 Nov 2007, 04:25
I would ask this question in Linux or Windows, but I guess it applies to all OSes?

What methods do people use to generate and keep track of temporary files used by their applications.

While glibc (on *nix systems) has tmpfile(), it doesn't have a corresponding close and delete call where you just supply a handle...

Windows expects the user to do all the heavy lifting, and only provides APIs for getting the current TMP directory... (unless you use .NET).

My current policy is to use: <pid>b0_1.tmp, <pid>b0_2.tmp, etc for the tmp filenames, the problem being is, is there a universal method for determining the tmp folder?

Is it safe to assume '/tmp' and '%TMP%' or '%TEMP%' are always available?

PS. adding the PID to the temp filename ensures that the temp files are assigned to a single process, and therefore other compiler processes won't accidently overwrite them...

PPS. On Windows, using CreateFile can I just use the '%TMP%\tmp.tmp' as the filename, or do I have to find what %TMP% is, and build the filename manually?
Post 05 Nov 2007, 04:25
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 05 Nov 2007, 04:35
Quote:

PPS. On Windows, using CreateFile can I just use the '%TMP%\tmp.tmp' as the filename, or do I have to find what %TMP% is, and build the filename manually?
Quote:
The GetTempPath function retrieves the path of the directory designated for temporary files. This function supersedes the GetTempDrive function.

DWORD GetTempPath(

DWORD nBufferLength, // size, in characters, of the buffer
LPTSTR lpBuffer // address of buffer for temp. path
);


Parameters

nBufferLength

Specifies the size, in characters, of the string buffer identified by lpBuffer.

lpBuffer

Points to a string buffer that receives the null-terminated string specifying the temporary file path.


Take a look at GetTempFileName for reference about building a file name.
Post 05 Nov 2007, 04:35
View user's profile Send private message Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 05 Nov 2007, 04:56
Thanks, I'm glad that Microsoft doesn't like to make things easy... Wink
Post 05 Nov 2007, 04:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.