1 /* PDFlib GmbH cvsid:
2 * $Id: tif_flush.c,v 1.7 2004/03/26 18:36:54 rjs Exp $ */
3
4 /*
5 * Copyright (c) 1988-1997 Sam Leffler
6 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and
9 * its documentation for any purpose is hereby granted without fee, provided
10 * that (i) the above copyright notices and this permission notice appear in
11 * all copies of the software and related documentation, and (ii) the names of
12 * Sam Leffler and Silicon Graphics may not be used in any advertising or
13 * publicity relating to the software without the specific, prior written
14 * permission of Sam Leffler and Silicon Graphics.
15 *
16 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
21 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 * OF THIS SOFTWARE.
26 */
27
28 /*
29 * TIFF Library.
30 */
31 #include "tiffiop.h"
32
33 #ifdef PDFLIB_TIFFWRITE_SUPPORT
34 int
TIFFFlush(TIFF * tif)35 TIFFFlush(TIFF* tif)
36 {
37
38 if (tif->tif_mode != O_RDONLY) {
39 if (!TIFFFlushData(tif))
40 return (0);
41 if ((tif->tif_flags & TIFF_DIRTYDIRECT) &&
42 !TIFFWriteDirectory(tif))
43 return (0);
44 }
45 return (1);
46 }
47
48 /*
49 * Flush buffered data to the file.
50 *
51 * Frank Warmerdam'2000: I modified this to return 1 if TIFF_BEENWRITING
52 * is not set, so that TIFFFlush() will proceed to write out the directory.
53 * The documentation says returning 1 is an error indicator, but not having
54 * been writing isn't exactly a an error. Hopefully this doesn't cause
55 * problems for other people.
56 */
57 int
TIFFFlushData(TIFF * tif)58 TIFFFlushData(TIFF* tif)
59 {
60 if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
61 return (0);
62 if (tif->tif_flags & TIFF_POSTENCODE) {
63 tif->tif_flags &= ~TIFF_POSTENCODE;
64 if (!(*tif->tif_postencode)(tif))
65 return (0);
66 }
67 return (TIFFFlushData1(tif));
68 }
69 #endif /* PDFLIB_TIFFWRITE_SUPPORT */
70
71