]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/tif_close.c
3 * Copyright (c) 1988-1997 Sam Leffler
4 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Sam Leffler and Silicon Graphics.
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32 /************************************************************************/
34 /************************************************************************/
37 * Auxiliary function to free the TIFF structure. Given structure will be
38 * completetly freed, so you should save opened file handle and pointer
39 * to the close procedure in external variables before calling
40 * _TIFFCleanup(), if you will need these ones to close the file.
42 * @param tif A TIFF pointer.
46 TIFFCleanup(TIFF
* tif
)
49 * Flush buffered data and directory (if dirty).
51 if (tif
->tif_mode
!= O_RDONLY
)
53 (*tif
->tif_cleanup
)(tif
);
54 TIFFFreeDirectory(tif
);
57 _TIFFfree(tif
->tif_dirlist
);
60 * Clean up client info links.
62 while( tif
->tif_clientinfo
)
64 TIFFClientInfoLink
*link
= tif
->tif_clientinfo
;
66 tif
->tif_clientinfo
= link
->next
;
67 _TIFFfree( link
->name
);
71 if (tif
->tif_rawdata
&& (tif
->tif_flags
&TIFF_MYBUFFER
))
72 _TIFFfree(tif
->tif_rawdata
);
74 TIFFUnmapFileContents(tif
, tif
->tif_base
, (toff_t
)tif
->tif_size
);
77 * Clean up custom fields.
79 if (tif
->tif_fields
&& tif
->tif_nfields
> 0) {
82 for (i
= 0; i
< tif
->tif_nfields
; i
++) {
83 TIFFField
*fld
= tif
->tif_fields
[i
];
84 if (fld
->field_bit
== FIELD_CUSTOM
&&
85 strncmp("Tag ", fld
->field_name
, 4) == 0) {
86 _TIFFfree(fld
->field_name
);
91 _TIFFfree(tif
->tif_fields
);
94 if (tif
->tif_nfieldscompat
> 0) {
97 for (i
= 0; i
< tif
->tif_nfieldscompat
; i
++) {
98 if (tif
->tif_fieldscompat
[i
].allocated_size
)
99 _TIFFfree(tif
->tif_fieldscompat
[i
].fields
);
101 _TIFFfree(tif
->tif_fieldscompat
);
107 /************************************************************************/
109 /************************************************************************/
112 * Close a previously opened TIFF file.
114 * TIFFClose closes a file that was previously opened with TIFFOpen().
115 * Any buffered data are flushed to the file, including the contents of
116 * the current directory (if modified); and all resources are reclaimed.
118 * @param tif A TIFF pointer.
124 TIFFCloseProc closeproc
= tif
->tif_closeproc
;
125 thandle_t fd
= tif
->tif_clientdata
;
128 (void) (*closeproc
)(fd
);
131 /* vim: set ts=8 sts=8 sw=8 noet: */