473,467 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 8641


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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.