Alan, Thanks for the links. I've now implemented a function pl_create_tmpfile which should meet our needs. It will create a secure temporary file in a standard way across platforms.
The function always returns a file handle (or -1 on failure). If a char ** is passed then the filename will also be returned in the pointer. If the file name is not returned then the file will automatically be deleted. It the file name is returned then the user is responsible for deleting the file and also for freeing the memory associated with the file name. I hope to avoid using the latter since there is a race condition associated with it, but currently I may need it because of the way the plplot code is written. The temporary file will be created in the directory given by TMPDIR (UNIX) or TEMP (windows) if they are set. Otherwise it will try P_tmpdir (if defined). Finally it will try the default /tmp (UNIX) or c:\windows\temp (windows) directory. Note that non-linux support is not tested at all. Before proceeding further I'd like to check this at least compiles on a range of windows / mac platforms. Cheers Andrew On Fri, Nov 13, 2009 at 10:14:47AM -0800, Alan Irwin wrote: > > > > Hmmm. Why, after all these years, has no-one got this right? > > > > Here are some references with example code that I found with a google search > for > > mkstemp example > > I hope they provide a good answer to your question above. > > http://www.daemon-systems.org/man/mkstemp.3.html, > http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/2270____.HTM > http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html > http://www.tldp.org/HOWTO/Secure-Programs-HOWTO/avoid-race.html > > Alan > __________________________ > Alan W. Irwin > > Astronomical research affiliation with Department of Physics and Astronomy, > University of Victoria (astrowww.phys.uvic.ca). > > Programming affiliations with the FreeEOS equation-of-state implementation > for stellar interiors (freeeos.sf.net); PLplot scientific plotting software > package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of > Linux Links project (loll.sf.net); and the Linux Brochure Project > (lbproject.sf.net). > __________________________ > > Linux-powered Science > __________________________ > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Plplot-devel mailing list > Plplot-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/plplot-devel > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel