[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

tmpnam usage warning



I'm doing some work on a Basic Interpreter and will be packaging it for Debian.

The interpreter allows the user to execute shell commands, this is
implemented using the "system" call.

To capture the output from the command " > <filename>" is concatenated onto
the end of the user supplied command. The <filename> is generated by a call
to "tmpnam".

This causes a warning "the use of `tmpnam' is dangerous, better use `mkstemp'".

I'd like to fix this, but how? tmpnam generates a name for a file which is
guaranteed *not* to exist, which is ideal in this situation since the output
from the command run by system is redirected to it and the file can then be
opened once the command has finished.

"mkstemp" however gives me a handle to a guaranteed uniquely named file
which is already open and which gets deleted when it's closed.

What is the best solution to this problem?

regards,

Colin

-- 
Colin Tuckley      |  colin@tuckley.org  |  PGP/GnuPG Key Id
+44(0)1903 236872  |  +44(0)7799 143369  |     0x1B3045CE

A door is what a cat is perpetually on the wrong side of. - adapted from
Ogden Nash



Reply to: