How can I get a unique new filename for a temporary file?
I'm programming in C, and I want to create a temporary file in /tmp.
Is there any function that gives me a new filename?
Thanks.
How can I get a unique new filename for a temporary file?
I'm programming in C, and I want to create a temporary file in /tmp.
Is there any function that gives me a new filename?
Thanks.
> How can I get a unique new filename for a temporary file?
> I'm programming in C, and I want to create a temporary file in /tmp.
> Is there any function that gives me a new filename?
> Thanks.
[ thanks Icarus, that's your answer :) ]
--
Alex Ramirez-Bellido
Computer Science FIB-UPC (Spain)
http://www.bath.ac.uk/~ma6arb/home.htm
"Daddy, what does <formatting drive c mean?>" ...
Try "tmpnam".
--
-=- Frederick Haab -=- Software Developer -=- Turner Production -=-
> > How can I get a unique new filename for a temporary file?
> try mktemp(3C).
:CONFORMING TO
: BSD 4.3. POSIX dictates tmpnam().
Try tmpnam() instead if you want portability.
Cordially,
Sumner
--
Respond by post or email, but please don't CC: postings to me; my mailbox
is already quite full.
>> How can I get a unique new filename for a temporary file?
>> I'm programming in C, and I want to create a temporary file in /tmp.
>> Is there any function that gives me a new filename?
>> Thanks.
>Have a look at the man page for getpid:
> getpid returns the process ID of the current process.
> (This is often used by routines that generate unique tem-
> porary file names.)
Time flies like arrows, but fruit flies like bananas.
Perry Piplani http://perrypip.netservers.com
> How can I get a unique new filename for a temporary file?
> I'm programming in C, and I want to create a temporary file in /tmp.
> Is there any function that gives me a new filename?
> Thanks.
Tom
--
Tom Manos
InfiNet - Norfolk, VA
**********************************************
Meddle not in the affairs of Wizards, for thou
art crunchy, and taste good with ketchup.
> How can I get a unique new filename for a temporary file?
> I'm programming in C, and I want to create a temporary file in /tmp.
> Is there any function that gives me a new filename?
> Thanks.
--
Ian Cowell
----------------------
: How can I get a unique new filename for a temporary file?
:
: I'm programming in C, and I want to create a temporary file in /tmp.
: Is there any function that gives me a new filename?
Use getpid() to find out the process number, and integrate this into
a file name. Works as long as the process is running.
If you want the file to last longer than the process, you'll need to
keep a record of the last name to be used, and create a new filename
from this. Or use the time. In both cases you'll need some file locking
if more than one process is doing this at the same time.
Geoff
--
---------------------------------------------------------------------------
Ever sit and watch ants? They're always busy with Geoff Short
can't identify with that kind of work ethic. http://kipper.york.ac.uk/~geoff
> : How can I get a unique new filename for a temporary file?
> :
> : I'm programming in C, and I want to create a temporary file in /tmp.
> : Is there any function that gives me a new filename?
> Use getpid() to find out the process number, and integrate this into
> a file name. Works as long as the process is running.
> If you want the file to last longer than the process, you'll need to
> keep a record of the last name to be used, and create a new filename
> from this. Or use the time. In both cases you'll need some file locking
> if more than one process is doing this at the same time.
> Geoff
> --
-- All opinions are mine, not NORTEL's.
/**************************************************************************
Amit Chatterjee
***************************************************************************
> Instead, use the available functions mktemp(). It is compliant with
> SVID2 and XPG2 standards (maybe a part of ISO C standard also but I am
> not sure).
:CONFORMING TO
: BSD 4.3. POSIX dictates tmpnam().
so tmpnam() is a better choice for portability.
Cordially,
Sumner
--
Respond by post or email, but please don't CC: postings to me; my mailbox
is already quite full.
: >
:
: > Instead, use the available functions mktemp(). It is compliant with
: > SVID2 and XPG2 standards (maybe a part of ISO C standard also but I am
: > not sure).
:
: It's not a part of the ISO C standard. The mktemp man page says:
:
: :CONFORMING TO
: : BSD 4.3. POSIX dictates tmpnam().
:
: so tmpnam() is a better choice for portability.
:
According to the POSIX Programmers Guide (A great book by the way),
tmpnam () - Generates a string that is a valid non-existing file name.
#include <stdio.h>
char *tmpnam (char *s);
Generates a string that is a valid filename and is not the name of an
existing file. The tmpnam() function generates a different name each time
it is called up to TMP_MAX times.
There is also a note that the BSD function mktemp() must be replaced by
tmpnam for POSIX compatability.
Do a man tmpnam, or buy the book for more info.
Andrae Muys.
--
=========================================================================
|
Andrae Muys | Linux... What do you want to DO today?
4th(and a half)Yr CSE |
University of Queensland. | Diplomacy is the art of saying "Nice Doggie!"
Australia | till you can find a rock. - Wynn Catlin
1. ensuring unique FTP upload filenames
I've got an interesting problem for the FTP server gurus out there...
We want an FTP site that allows tons of users to log into an anonymous
account and submit files. The files must not overwrite each other, but
we don't want the users to have to worry about specifying a unique
filename.
Ideally, the FTP server would intercept the incoming file and change
its name to a unique identifier.
Is that possible somehow?
I appreciate any insights...
Sent via Deja.com http://www.deja.com/
Before you buy.
2. Routing Problem under Linux
3. unique filenames in Makefile
4. Announcing xfig 3.2.2 (already!)
5. automatically rename file to unique filename
6. Clock doesn't keep the correct time on p-133
7. Creation of unique filename for temp file.
8. Patch 108528-06 f**ks up fastpatch??
9. How to generate a unique filename
10. generate unique filename in ksh on AIX
11. Unique Filename
13. What is the official way to create unique filenames in Unix?