1
/******************************************************************************
2
* $Id: tifvsi.cpp 10645 2007-01-18 02:22:39Z warmerdam $
4
* Project: GeoTIFF Driver
5
* Purpose: Implement system hook functions for libtiff on top of CPL/VSI,
6
* including > 2GB support. Based on tif_unix.c from libtiff
8
* Author: Frank Warmerdam, warmerdam@pobox.com
10
******************************************************************************
11
* Copyright (c) 2005, Frank Warmerdam, warmerdam@pobox.com
13
* Permission is hereby granted, free of charge, to any person obtaining a
14
* copy of this software and associated documentation files (the "Software"),
15
* to deal in the Software without restriction, including without limitation
16
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
* and/or sell copies of the Software, and to permit persons to whom the
18
* Software is furnished to do so, subject to the following conditions:
20
* The above copyright notice and this permission notice shall be included
21
* in all copies or substantial portions of the Software.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
* DEALINGS IN THE SOFTWARE.
30
****************************************************************************/
33
* TIFF Library UNIX-specific Routines.
38
// We avoid including xtiffio.h since it drags in the libgeotiff version
39
// of the VSI functions.
42
extern TIFF CPL_DLL * XTIFFClientOpen(const char* name, const char* mode,
44
TIFFReadWriteProc, TIFFReadWriteProc,
45
TIFFSeekProc, TIFFCloseProc,
47
TIFFMapFileProc, TIFFUnmapFileProc);
51
_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
53
return VSIFReadL( buf, 1, size, (FILE *) fd );
57
_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
59
return VSIFWriteL( buf, 1, size, (FILE *) fd );
63
_tiffSeekProc(thandle_t fd, toff_t off, int whence)
65
if( VSIFSeekL( (FILE *) fd, off, whence ) == 0 )
66
return (toff_t) VSIFTellL( (FILE *) fd );
72
_tiffCloseProc(thandle_t fd)
74
return VSIFCloseL( (FILE *) fd );
78
_tiffSizeProc(thandle_t fd)
83
old_off = VSIFTellL( (FILE *) fd );
84
VSIFSeekL( (FILE *) fd, 0, SEEK_END );
86
file_size = (toff_t) VSIFTellL( (FILE *) fd );
87
VSIFSeekL( (FILE *) fd, old_off, SEEK_SET );
93
_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
95
(void) fd; (void) pbase; (void) psize;
100
_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
102
(void) fd; (void) base; (void) size;
106
* Open a TIFF file for read/writing.
108
TIFF* VSI_TIFFOpen(const char* name, const char* mode)
110
static const char module[] = "TIFFOpen";
118
for( i = 0; mode[i] != '\0'; i++ )
125
access[a_out++] = mode[i];
126
access[a_out] = '\0';
130
strcat( access, "b" );
132
fp = VSIFOpenL( name, access );
135
TIFFError(module,"%s: %s", name, VSIStrerror( errno ) );
137
TIFFError(module, "%s: Cannot open", name);
141
tif = XTIFFClientOpen(name, mode,
143
_tiffReadProc, _tiffWriteProc,
144
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
145
_tiffMapProc, _tiffUnmapProc);