[Fortran, please advise] Choosing mkstemp over tempnam when opening SCRATCH files.

Toon Moene toon@moene.indiv.nluug.nl
Sun Nov 12 12:45:00 GMT 2000


Toon Moene wrote:

> Joseph S. Myers wrote:

> > It's tmpnam() not tempnam() that's in ISO C.  However, the useful ISO C
> > function here is tmpfile() - which opens a temporary file that will get
> > deleted automatically when closed (but doesn't provide a file name, just a
> > FILE *).
> 
> Thanks for this info - the preferred solution seems to be tmpfile().
> See if I can coerce the rest of libf2c/libI77 in using it ...

Hmmm, on second thoughts - I see that of all the variant functions to
create temporary file(name)s, only `tempnam' uses $TMPDIR as the
directory to put them in in preference.

Because that turned out to be crucial to our users, I think I'll stick
to `tempnam', in spite of the warning on FreeBSD 4.1.

The average Fortran program, even if it uses SCRATCH files, won't run
into this race condition easily, as normally it won't create and close
temporary files in rapid succession.  Furthermore, because suid programs
do not tend to be written in Fortran, system security issues are not
relevant here.

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


More information about the Gcc-patches mailing list