473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

tmpnam

when i compile programs i download for linux, i get this warning and i can't
finish the compile:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'

is there away around this? or do i have to modify the source to use mkstemp?

regrads,
--
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------
Nov 15 '05 #1
3 8633


lucas wrote:
when i compile programs i download for linux, i get this warning and i can't
finish the compile:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'

is there away around this? or do i have to modify the source to use mkstemp?


"Is there a way around this?" Well, if "this" is the
shortcomings of tmpname(), then no: if you use tmpnam(), you
accept its problems. Some of those problems are:

- Race conditions: tmpnam() generates a file name that is
not in use at the moment of the call, but there's no
guarantee that some other program might not create such
a file two nanoseconds later, before you get a chance
to use the name tmpnam() built for you.

- Security holes: It's at least conceivable that the race
condition mentioned above could be exploited as part of
a penetration of privilege barriers.

- Disk pollution: When you create a file using the name
tmpnam() gave you, you must remember to remove() it when
you're through (assuming you want it to be temporary).
If your program crashes or is stopped by ^C or some such
and you don't remove() the file, it will hang around on
the disk and take up space. This could become troublesome,
especially if the "temporary" files tend to be large.

What to do instead? The Standard C library provides the
tmpfile() function, which solves or at least addresses most of
these problems. As for mkstemp() -- well, it's not part of
Standard C; try a newsgroup like comp.unix.programmer if you
need help with it.

--
Er*********@sun.com

Nov 15 '05 #2
lucas <ao******@yahoo.com> writes:
when i compile programs i download for linux, i get this warning and i can't
finish the compile:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'

is there away around this? or do i have to modify the source to use mkstemp?


Compilers are allowed to issue warnings whenever they like. There are
several workarounds: ignore the warning, don't use tmpnam, or invoke
the compiler in a way that inhibits the warning. The latter may or
may not be possible (consult the compiler documentation for more
information).

<OT>
Since it's a warning, it won't cause the compilation to fail. There
must be something else causing that. (The standard doesn't
distinguish between warnings and error messages, but gcc does.)
Look at the compiler output for error messages that don't include
the word "warning".
</OT>

It's true that tmpnam() can cause problems, particularly on systems
where other programs may be executing. The advantage is that it's
part of the C standard; mkstemp may be safer, but it's non-standard.

<OT>
"man tmpnam" will give you more information.
</OT>

It sounds like this is code that someone else wrote. It's up to you
to decide whether you want to modify it, complain to the author, or
whatever.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #3
lucas wrote:
when i compile programs i download for linux, i get this warning and i can't
finish the compile:
warning: the use of `tmpnam' is dangerous, better use `mkstemp'

is there away around this? or do i have to modify the source to use mkstemp?


That warning is not preventing the compilation. However, without the
code and the actual errors (if there are any) all anyone can say is that
you have at least two problems. One is that you can't compile the
program you want and the other is that you don't know enough to provide
the information required to help.

Based on your question and apparent level of knowledge I would suggest
looking for a prebuilt (binary) package for the software.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Dave Theese | last post by:
Hello all, We're presented with the problem of needing to generate a unique file name. I've had some thoughts, but also wanted to solicit suggestions from the group. Any suggestions for...
18
by: Serve Laurijssen | last post by:
What's the difference between char buf; strcpy(buf, tmpnam(NULL)); and char buf; tmpnam(buf); According to my docs both calls write to an internal static buffer. What's
1
by: Josh Wilson | last post by:
Hey gang, So I have my stdin which is user defined file, and am wanting to write it to a temporary file (seems odd I know, but there is a sincere reason), and then use that file as the stdin for...
1
by: Steve | last post by:
I have been trying to find documentation on the behavior Can anyone tell me why the first example works and the second doesn't and where I can read about it in the language reference? Steve ...
7
by: Harold Fellermann | last post by:
Hi, I need to create a temporary file and I need to retrieve the path of that file. os.tmpnam() would do the job quite well if it wasn't for the RuntimeWarning "tmpnam is a potential security...
16
by: Markus Dehmann | last post by:
According to several C++ tutorials, calling srand like this to initialize the random number generator seems to be standard: srand((unsigned)time(0)); But it leads to the same random number...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.