On Fri, Nov 13, 2009 at 10:15:02PM +0000, Andrew Ross wrote:
> 
> 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.

Just to update on this: I discovered that all uses of temporary files in plplot
actually use a file stream FILE * rather than a basic file handle, and so I've
updated the function to return a FILE *. A returned NULL signals failure. This 
requires the use of fdopen which is strictly only defined in POSIX, but it 
appears that Visual C++ at least supports it as _fdopen. We have to use the low 
level open command to ensure that the file is actually created securely (the 
O_EXCL option). 

The tk bindings now use this function to create temporary files for printing.
It will be trivial to replace calls to tmpfile with calls to pl_create_tempfile
if desired. 

The only remaining occurence of tmpnam is in drivers/tk.c where it is used to 
create a temporary name for a named pipe. This can't be replaced with 
pl_create_tempfile since we don't actually want to create a file. The following
call to mkfifo will fail however if the name already exists and so this should
be safe.

This use can be avoided altogether if you use the dp option for the tk driver 
which uses sockets rather than named pipes for communication.

Andrew



------------------------------------------------------------------------------
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

Reply via email to