LCOV - code coverage report
Current view: top level - frmts/gtiff/libtiff - tif_vsi.c (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 25 78 32.1 %
Date: 2024-05-03 15:49:35 Functions: 8 19 42.1 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       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) 2000, 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 "tiffiop.h"
      36             : #include "cpl_vsi.h"
      37             : 
      38           0 : CPL_INLINE static void CPL_IGNORE_RET_VAL_INT(CPL_UNUSED int unused) {}
      39             : 
      40             : static tsize_t
      41           0 : _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
      42             : {
      43           0 :     return VSIFReadL( buf, 1, size, (VSILFILE *) fd );
      44             : }
      45             : 
      46             : static tsize_t
      47           0 : _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
      48             : {
      49           0 :     return VSIFWriteL( buf, 1, size, (VSILFILE *) fd );
      50             : }
      51             : 
      52             : static toff_t
      53           0 : _tiffSeekProc(thandle_t fd, toff_t off, int whence)
      54             : {
      55           0 :     if( VSIFSeekL( (VSILFILE *) fd, off, whence ) == 0 )
      56           0 :         return (toff_t) VSIFTellL( (VSILFILE *) fd );
      57             :     else
      58           0 :         return (toff_t) -1;
      59             : }
      60             : 
      61             : static int
      62           0 : _tiffCloseProc(thandle_t fd)
      63             : {
      64           0 :     return VSIFCloseL( (VSILFILE *) fd );
      65             : }
      66             : 
      67             : static toff_t
      68           0 : _tiffSizeProc(thandle_t fd)
      69             : {
      70             :     vsi_l_offset  old_off;
      71             :     toff_t        file_size;
      72             : 
      73           0 :     old_off = VSIFTellL( (VSILFILE *) fd );
      74           0 :     CPL_IGNORE_RET_VAL_INT(VSIFSeekL( (VSILFILE *) fd, 0, SEEK_END ));
      75             : 
      76           0 :     file_size = (toff_t) VSIFTellL( (VSILFILE *) fd );
      77           0 :     CPL_IGNORE_RET_VAL_INT(VSIFSeekL( (VSILFILE *) fd, old_off, SEEK_SET ));
      78             : 
      79           0 :     return file_size;
      80             : }
      81             : 
      82             : static int
      83           0 : _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
      84             : {
      85             :   (void) fd; (void) pbase; (void) psize;
      86           0 :   return (0);
      87             : }
      88             : 
      89             : static void
      90           0 : _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
      91             : {
      92             :   (void) fd; (void) base; (void) size;
      93           0 : }
      94             : 
      95             : /*
      96             :  * Open a TIFF file descriptor for read/writing.
      97             :  */
      98             : TIFF*
      99           0 : TIFFFdOpen(CPL_UNUSED int fd, CPL_UNUSED const char* name, CPL_UNUSED const char* mode)
     100             : {
     101           0 :   return NULL;
     102             : }
     103             : 
     104             : /*
     105             :  * Open a TIFF file for read/writing.
     106             :  */
     107             : TIFF*
     108           0 : TIFFOpen(const char* name, const char* mode)
     109             : {
     110             :   static const char module[] = "TIFFOpen";
     111             :   int           i, a_out;
     112             :         char          szAccess[32];
     113             :         VSILFILE          *fp;
     114             :         TIFF          *tif;
     115           0 :         char         *pszAccess = szAccess;
     116             : 
     117           0 :         a_out = 0;
     118           0 :         pszAccess[0] = '\0';
     119           0 :         for( i = 0; mode[i] != '\0'; i++ )
     120             :         {
     121           0 :             if( mode[i] == 'r'
     122           0 :                 || mode[i] == 'w'
     123           0 :                 || mode[i] == '+'
     124           0 :                 || mode[i] == 'a' )
     125             :             {
     126           0 :                 szAccess[a_out++] = mode[i];
     127           0 :                 szAccess[a_out] = '\0';
     128             :             }
     129             :         }
     130             : 
     131           0 :         strcat( szAccess, "b" );
     132             : 
     133           0 :         fp = VSIFOpenL( name, szAccess );
     134           0 :   if (fp == NULL) {
     135           0 :             if( errno >= 0 )
     136           0 :                 TIFFError(module,"%s: %s", name, VSIStrerror( errno ) );
     137             :             else
     138           0 :     TIFFError(module, "%s: Cannot open", name);
     139           0 :             return ((TIFF *)0);
     140             :   }
     141             : 
     142           0 :   tif = TIFFClientOpen(name, mode,
     143             :       (thandle_t) fp,
     144             :       _tiffReadProc, _tiffWriteProc,
     145             :       _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
     146             :       _tiffMapProc, _tiffUnmapProc);
     147             : 
     148           0 :         if( tif != NULL )
     149           0 :             tif->tif_fd = 0;
     150             :         else
     151           0 :             CPL_IGNORE_RET_VAL_INT(VSIFCloseL( fp ));
     152             :         
     153           0 :   return tif;
     154             : }
     155             : 
     156             : void*
     157      710650 : _TIFFmalloc(tsize_t s)
     158             : {
     159      710650 :     return VSIMalloc((size_t) s);
     160             : }
     161             : 
     162       65599 : void* _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
     163             : {
     164       65599 :     if( nmemb == 0 || siz == 0 )
     165          32 :         return ((void *) NULL);
     166             : 
     167       65567 :     return VSICalloc((size_t) nmemb, (size_t)siz);
     168             : }
     169             : 
     170             : void
     171     1698970 : _TIFFfree(tdata_t p)
     172             : {
     173     1698970 :     VSIFree( p );
     174     1699150 : }
     175             : 
     176             : void*
     177     1406340 : _TIFFrealloc(tdata_t p, tsize_t s)
     178             : {
     179     1406340 :     return VSIRealloc( p, s );
     180             : }
     181             : 
     182             : void
     183      932415 : _TIFFmemset(void* p, int v, tmsize_t c)
     184             : {
     185      932415 :   memset(p, v, (size_t) c);
     186      932415 : }
     187             : 
     188             : void
     189     1816550 : _TIFFmemcpy(void* d, const void* s, tmsize_t c)
     190             : {
     191     1816550 :   memcpy(d, s, (size_t) c);
     192     1816550 : }
     193             : 
     194             : int
     195           8 : _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c)
     196             : {
     197           8 :   return (memcmp(p1, p2, (size_t) c));
     198             : }
     199             : 
     200             : static void
     201           0 : unixWarningHandler(const char* module, const char* fmt, va_list ap)
     202             : {
     203           0 :   if (module != NULL)
     204           0 :     fprintf(stderr, "%s: ", module);
     205           0 :   fprintf(stderr, "Warning, ");
     206           0 :   vfprintf(stderr, fmt, ap);
     207           0 :   fprintf(stderr, ".\n");
     208           0 : }
     209             : TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler;
     210             : 
     211             : static void
     212          73 : unixErrorHandler(const char* module, const char* fmt, va_list ap)
     213             : {
     214          73 :   if (module != NULL)
     215          73 :     fprintf(stderr, "%s: ", module);
     216          73 :   vfprintf(stderr, fmt, ap);
     217          73 :   fprintf(stderr, ".\n");
     218          73 : }
     219             : TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler;

Generated by: LCOV version 1.14