| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Unique Filenames |
ZZ>
> How can I create a file with a unique filename under OS/2?
ZZ>
Unique as in "I want a temporary file to use" ?
Use the tmpnam() function supplied in your Standard C Library.
Unique as in "I don't want to conflict with an existing file" ?
Use a simple for(;;) loop that constructs successive filenames until
it creates a name that does not exist. To avoid race conditions in
multiprocess and network environments such as OS/2, use
DosOpen(...OPEN_ACTION_FAIL_IF_EXISTS...) rather than
DosQueryPathInfo() to determine if a file exists.
Unique as in "I don't ever want to use the same name twice" ?
Construct the filename from a combination of the local machine name,
the current date and time (use the POSIX 1003.1 time in seconds
since The Epoch), the current process and thread IDs, and a sequence
number if the date/time isn't granular enough for your purposes
(i.e. if the same thread is likely to create more than one of these
files per second on a fast machine).
i.e. use the tuple,
which is guaranteed unique until the clock wraps around.
> JdeBP <
___
X MegaMail 2.10 #0:
--- Maximus/2 2.02
* Origin: DoNoR/2,Woking UK (44-1483-722344) (2:440/4)SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809 @PATH: 440/4 141/209 270/101 105/103 42 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.