1 /* $Id: tif_close.c,v 1.10.2.1 2010-06-08 18:50:41 bfriesen Exp $ */
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * 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)
48 if (tif->tif_mode != O_RDONLY)
50 * Flush buffered data and directory (if dirty).
53 (*tif->tif_cleanup)(tif);
54 TIFFFreeDirectory(tif);
57 _TIFFfree(tif->tif_dirlist);
59 /* Clean up client info links */
60 while( tif->tif_clientinfo )
62 TIFFClientInfoLink *link = tif->tif_clientinfo;
64 tif->tif_clientinfo = link->next;
65 _TIFFfree( link->name );
69 if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
70 _TIFFfree(tif->tif_rawdata);
72 TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
74 /* Clean up custom fields */
75 if (tif->tif_nfields > 0)
79 for (i = 0; i < tif->tif_nfields; i++)
81 TIFFFieldInfo *fld = tif->tif_fieldinfo[i];
82 if (fld->field_bit == FIELD_CUSTOM &&
83 strncmp("Tag ", fld->field_name, 4) == 0)
85 _TIFFfree(fld->field_name);
90 _TIFFfree(tif->tif_fieldinfo);
96 /************************************************************************/
98 /************************************************************************/
101 * Close a previously opened TIFF file.
103 * TIFFClose closes a file that was previously opened with TIFFOpen().
104 * Any buffered data are flushed to the file, including the contents of
105 * the current directory (if modified); and all resources are reclaimed.
107 * @param tif A TIFF pointer.
113 TIFFCloseProc closeproc = tif->tif_closeproc;
114 thandle_t fd = tif->tif_clientdata;
117 (void) (*closeproc)(fd);