diff options
author | Carl Worth <cworth@cworth.org> | 2005-05-17 12:40:55 +0000 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2005-05-17 12:40:55 +0000 |
commit | f0923288c58f42bf45dc6658a504b14faec6df53 (patch) | |
tree | 9dcca09d5bc1fc92361ae315004d7251270b3bff | |
parent | b4710711b8e39738587249f04a41ae99c5eae981 (diff) |
Two fixes from Kristion Høgsberg:
Fix to close the file if we opened it.
Grab the status from out of the stream _before_ we destroy the stream.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | src/cairo-output-stream.c | 9 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 5 |
3 files changed, 24 insertions, 2 deletions
@@ -1,3 +1,15 @@ +2005-05-17 Carl Worth <cworth@cworth.org> + + Two fixes from Kristion Høgsberg: + + * src/cairo-output-stream.c: (_cairo_output_stream_create), + (_cairo_output_stream_destroy), + (_cairo_output_stream_create_for_file): Fix to close the file if + we opened it. + + * src/cairo-pdf-surface.c: (_cairo_pdf_document_finish): Grab the + status from out of the stream _before_ we destroy the stream. + 2005-05-17 Keith Packard <keithp@keithp.com> * src/cairo-xlib-surface.c: (_get_image_surface): diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index 31473d1d8..14b4486a6 100644 --- a/src/cairo-output-stream.c +++ b/src/cairo-output-stream.c @@ -41,8 +41,8 @@ struct _cairo_output_stream { cairo_write_func_t write_data; - cairo_destroy_func_t destroy_closure; void *closure; + cairo_bool_t owns_closure_is_file; unsigned long position; cairo_status_t status; }; @@ -59,6 +59,7 @@ _cairo_output_stream_create (cairo_write_func_t write_data, stream->write_data = write_data; stream->closure = closure; + stream->owns_closure_is_file = FALSE; stream->position = 0; stream->status = CAIRO_STATUS_SUCCESS; @@ -68,6 +69,11 @@ _cairo_output_stream_create (cairo_write_func_t write_data, void _cairo_output_stream_destroy (cairo_output_stream_t *stream) { + if (stream->owns_closure_is_file) { + FILE *file = stream->closure; + fflush (file); + fclose (file); + } free (stream); } @@ -273,6 +279,7 @@ _cairo_output_stream_create_for_file (const char *filename) stream = _cairo_output_stream_create (stdio_write, fp); if (stream == NULL) fclose (fp); + stream->owns_closure_is_file = TRUE; return stream; } diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index 1a75772a4..228c2c89a 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -2180,6 +2180,7 @@ _cairo_pdf_document_destroy (cairo_pdf_document_t *document) static cairo_status_t _cairo_pdf_document_finish (cairo_pdf_document_t *document) { + cairo_status_t status; cairo_output_stream_t *output = document->output_stream; long offset; unsigned int info_id, catalog_id; @@ -2210,10 +2211,12 @@ _cairo_pdf_document_finish (cairo_pdf_document_t *document) "%%%%EOF\r\n", offset); + status = _cairo_output_stream_get_status (output); _cairo_output_stream_destroy (output); + document->finished = TRUE; - return _cairo_output_stream_get_status (output); + return status; } static cairo_status_t |