LCOV - code coverage report
Current view: directory - frmts/gtiff/libtiff - tif_vsi.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 72 13 18.1 %
Date: 2012-12-26 Functions: 17 5 29.4 %

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

Generated by: LCOV version 1.7