[cairo] tmpfile fails in cairo-ps-surface on win32 systems (proposed patch)

Adrian Johnson ajohnson at redneon.com
Fri Dec 28 06:37:49 PST 2007


Adib Taraben wrote:
> Hello Cairo team,
> 
> I found that when I use inkscape on my WinXP to create PS files via
> cairo that on accounts without administrative rights it results in
> 0(zero)byte length PS-files.
> The reason is the tmpfile() call in
> _cairo_ps_surface_create_for_stream_internal. tmpfile() on MinGW creates
> a temporary file on the root ("\\") which fails because of the missing
> rights.
> There is also a discussion on the wine-list
> http://www.nabble.com/temporary-files-in-wine-to8919379.html
> 
> Cairo uses tmpfile only in the PS backend. so only one function is
> affected.
> I present you a workaround using the native win32 calls. The calls are
> ANSI calls in order to allow fopen() to work correctly. The patch is
> against current snapshot 1.5.4.

I've rewritten the patch to move the Windows code out to a separate
file, use the Unicode Windows functions to create the filename, use
CreateFileW to open the file so the delete on close flag can be set, and
obtain a FILE* pointer from the CreateFile handle [1].

I've also fixed the PostScript backend to return
CAIRO_STATUS_TEMP_FILE_ERROR instead of the unhelpful
CAIRO_STATUS_NO_MEMORY for errors creating or writing to temp files.

Looking at the Inkscape SVN it appears that the error status of the
cairo PostScript surface is not checked. If the PostScript surface does
not have a status of CAIRO_STATUS_SUCCESS after calling
cairo_surface_finish() the PostScript output should be ignored as it
will be incomplete or broken.

[1]
http://gitweb.freedesktop.org/?p=cairo;a=commit;h=4fa46e3caaffb54f4419887418d8d0ea39816092




More information about the cairo mailing list