LCOV - code coverage report
Current view: directory - frmts/gtiff - tifvsi.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 41 36 87.8 %
Date: 2012-04-28 Functions: 8 7 87.5 %

       1                 : /******************************************************************************
       2                 :  * $Id: tifvsi.cpp 22639 2011-07-03 15:51:39Z rouault $
       3                 :  *
       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
       7                 :  *           distribution.
       8                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       9                 :  *
      10                 :  ******************************************************************************
      11                 :  * Copyright (c) 2005, Frank Warmerdam, warmerdam@pobox.com
      12                 :  *
      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:
      19                 :  *
      20                 :  * The above copyright notice and this permission notice shall be included
      21                 :  * in all copies or substantial portions of the Software.
      22                 :  *
      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                 :  ****************************************************************************/
      31                 : 
      32                 : /*
      33                 :  * TIFF Library UNIX-specific Routines.
      34                 :  */
      35                 : #include "cpl_vsi.h"
      36                 : #include "tifvsi.h"
      37                 : 
      38                 : // We avoid including xtiffio.h since it drags in the libgeotiff version
      39                 : // of the VSI functions.
      40                 : 
      41                 : #ifdef RENAME_INTERNAL_LIBGEOTIFF_SYMBOLS
      42                 : #include "gdal_libgeotiff_symbol_rename.h"
      43                 : #endif
      44                 : 
      45                 : CPL_C_START
      46                 : extern TIFF CPL_DLL * XTIFFClientOpen(const char* name, const char* mode, 
      47                 :                                       thandle_t thehandle,
      48                 :                                       TIFFReadWriteProc, TIFFReadWriteProc,
      49                 :                                       TIFFSeekProc, TIFFCloseProc,
      50                 :                                       TIFFSizeProc,
      51                 :                                       TIFFMapFileProc, TIFFUnmapFileProc);
      52                 : CPL_C_END
      53                 : 
      54                 : static tsize_t
      55          181668 : _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
      56                 : {
      57          181668 :     return VSIFReadL( buf, 1, size, (VSILFILE *) fd );
      58                 : }
      59                 : 
      60                 : static tsize_t
      61          236876 : _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
      62                 : {
      63          236876 :     return VSIFWriteL( buf, 1, size, (VSILFILE *) fd );
      64                 : }
      65                 : 
      66                 : static toff_t
      67          341556 : _tiffSeekProc(thandle_t fd, toff_t off, int whence)
      68                 : {
      69          341556 :     if( VSIFSeekL( (VSILFILE *) fd, off, whence ) == 0 )
      70          341556 :         return (toff_t) VSIFTellL( (VSILFILE *) fd );
      71                 :     else
      72               0 :         return (toff_t) -1;
      73                 : }
      74                 : 
      75                 : static int
      76           10230 : _tiffCloseProc(thandle_t fd)
      77                 : {
      78           10230 :     return VSIFCloseL( (VSILFILE *) fd );
      79                 : }
      80                 : 
      81                 : static toff_t
      82           13754 : _tiffSizeProc(thandle_t fd)
      83                 : {
      84                 :     vsi_l_offset  old_off;
      85                 :     toff_t        file_size;
      86                 : 
      87           13754 :     old_off = VSIFTellL( (VSILFILE *) fd );
      88           13754 :     VSIFSeekL( (VSILFILE *) fd, 0, SEEK_END );
      89                 :     
      90           13754 :     file_size = (toff_t) VSIFTellL( (VSILFILE *) fd );
      91           13754 :     VSIFSeekL( (VSILFILE *) fd, old_off, SEEK_SET );
      92                 : 
      93           13754 :     return file_size;
      94                 : }
      95                 : 
      96                 : static int
      97            6808 : _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
      98                 : {
      99                 :   (void) fd; (void) pbase; (void) psize;
     100            6808 :   return (0);
     101                 : }
     102                 : 
     103                 : static void
     104               0 : _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
     105                 : {
     106                 :   (void) fd; (void) base; (void) size;
     107               0 : }
     108                 : 
     109                 : /*
     110                 :  * Open a TIFF file for read/writing.
     111                 :  */
     112           10236 : TIFF* VSI_TIFFOpen(const char* name, const char* mode)
     113                 : {
     114                 :     static const char module[] = "TIFFOpen";
     115                 :     int           i, a_out;
     116                 :     char          access[32];
     117                 :     VSILFILE      *fp;
     118                 :     TIFF          *tif;
     119                 : 
     120           10236 :     a_out = 0;
     121           10236 :     access[0] = '\0';
     122           23934 :     for( i = 0; mode[i] != '\0'; i++ )
     123                 :     {
     124           23264 :         if( mode[i] == 'r'
     125            6004 :             || mode[i] == 'w'
     126            3462 :             || mode[i] == '+'
     127             100 :             || mode[i] == 'a' )
     128                 :         {
     129           13598 :             access[a_out++] = mode[i];
     130           13598 :             access[a_out] = '\0';
     131                 :         }
     132                 :     }
     133                 : 
     134           10236 :     strcat( access, "b" );
     135                 :                     
     136           10236 :     fp = VSIFOpenL( name, access );
     137           10236 :     if (fp == NULL) {
     138               6 :         if( errno >= 0 )
     139               6 :             TIFFError(module,"%s: %s", name, VSIStrerror( errno ) );
     140                 :         else
     141               0 :             TIFFError(module, "%s: Cannot open", name);
     142               6 :         return ((TIFF *)0);
     143                 :     }
     144                 : 
     145                 :     tif = XTIFFClientOpen(name, mode,
     146                 :                           (thandle_t) fp,
     147                 :                           _tiffReadProc, _tiffWriteProc,
     148                 :                           _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
     149           10230 :                           _tiffMapProc, _tiffUnmapProc);
     150                 : 
     151           10230 :     if( tif == NULL )
     152               0 :         VSIFCloseL( fp );
     153                 :         
     154           10230 :     return tif;
     155                 : }

Generated by: LCOV version 1.7