GDAL
cpl_vsi.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_vsi.h 39224 2017-06-21 08:50:19Z rouault $
00003  *
00004  * Project:  CPL - Common Portability Library
00005  * Author:   Frank Warmerdam, warmerdam@pobox.com
00006  * Purpose:  Include file defining Virtual File System (VSI) functions, a
00007  *           layer over POSIX file and other system services.
00008  *
00009  ******************************************************************************
00010  * Copyright (c) 1998, Frank Warmerdam
00011  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining a
00014  * copy of this software and associated documentation files (the "Software"),
00015  * to deal in the Software without restriction, including without limitation
00016  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00017  * and/or sell copies of the Software, and to permit persons to whom the
00018  * Software is furnished to do so, subject to the following conditions:
00019  *
00020  * The above copyright notice and this permission notice shall be included
00021  * in all copies or substantial portions of the Software.
00022  *
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00024  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00026  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00028  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00029  * DEALINGS IN THE SOFTWARE.
00030  ****************************************************************************/
00031 
00032 #ifndef CPL_VSI_H_INCLUDED
00033 #define CPL_VSI_H_INCLUDED
00034 
00035 #include "cpl_port.h"
00054 /* -------------------------------------------------------------------- */
00055 /*      We need access to ``struct stat''.                              */
00056 /* -------------------------------------------------------------------- */
00057 
00058 /* Unix */
00059 #if !defined(_WIN32)
00060 #  include <unistd.h>
00061 #endif
00062 
00063 /* Windows */
00064 #include <sys/stat.h>
00065 
00066 CPL_C_START
00067 
00069 #ifdef ENABLE_EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
00070 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_WARN_UNUSED_RESULT
00071 #else
00072 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
00073 #endif
00074 
00076 /* ==================================================================== */
00077 /*      stdio file access functions.  These do not support large       */
00078 /*      files, and do not go through the virtualization API.           */
00079 /* ==================================================================== */
00080 
00083 FILE CPL_DLL *  VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00084 int CPL_DLL     VSIFClose( FILE * );
00085 int CPL_DLL     VSIFSeek( FILE *, long, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00086 long CPL_DLL    VSIFTell( FILE * ) CPL_WARN_UNUSED_RESULT;
00087 void CPL_DLL    VSIRewind( FILE * );
00088 void CPL_DLL    VSIFFlush( FILE * );
00089 
00090 size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00091 size_t CPL_DLL  VSIFWrite( const void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00092 char CPL_DLL   *VSIFGets( char *, int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00093 int CPL_DLL     VSIFPuts( const char *, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00094 int CPL_DLL     VSIFPrintf( FILE *, CPL_FORMAT_STRING(const char *), ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
00095 
00096 int CPL_DLL     VSIFGetc( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00097 int CPL_DLL     VSIFPutc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00098 int CPL_DLL     VSIUngetc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00099 int CPL_DLL     VSIFEof( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00100 
00103 /* ==================================================================== */
00104 /*      VSIStat() related.                                              */
00105 /* ==================================================================== */
00106 
00108 typedef struct stat VSIStatBuf;
00109 int CPL_DLL VSIStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
00112 #ifdef _WIN32
00113 #  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
00114 #  define VSI_ISREG(x)  ((x) & S_IFREG)
00115 #  define VSI_ISDIR(x)  ((x) & S_IFDIR)
00116 #  define VSI_ISCHR(x)  ((x) & S_IFCHR)
00117 #  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
00118 #else
00119 
00120 #  define VSI_ISLNK(x)  S_ISLNK(x)
00121 
00122 #  define VSI_ISREG(x)  S_ISREG(x)
00123 
00124 #  define VSI_ISDIR(x)  S_ISDIR(x)
00125 
00126 #  define VSI_ISCHR(x)  S_ISCHR(x)
00127 #  define VSI_ISBLK(x)  S_ISBLK(x)
00128 
00129 #endif
00130 
00131 /* ==================================================================== */
00132 /*      64bit stdio file access functions.  If we have a big size       */
00133 /*      defined, then provide prototypes for the large file API,        */
00134 /*      otherwise redefine to use the regular api.                      */
00135 /* ==================================================================== */
00136 
00138 typedef GUIntBig vsi_l_offset;
00140 #define VSI_L_OFFSET_MAX GUINTBIG_MAX
00141 
00143 /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
00144 #ifdef DEBUG
00145 #define VSIL_STRICT_ENFORCE
00146 #endif
00147 
00149 #ifdef VSIL_STRICT_ENFORCE
00150 
00151 typedef struct _VSILFILE VSILFILE;
00152 #else
00153 
00154 typedef FILE VSILFILE;
00155 #endif
00156 
00157 VSILFILE CPL_DLL *  VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00158 VSILFILE CPL_DLL *  VSIFOpenExL( const char *, const char *, int ) CPL_WARN_UNUSED_RESULT;
00159 int CPL_DLL     VSIFCloseL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00160 int CPL_DLL     VSIFSeekL( VSILFILE *, vsi_l_offset, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00161 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * ) CPL_WARN_UNUSED_RESULT;
00162 void CPL_DLL    VSIRewindL( VSILFILE * );
00163 size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00164 int CPL_DLL     VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00165 size_t CPL_DLL  VSIFWriteL( const void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00166 int CPL_DLL     VSIFEofL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00167 int CPL_DLL     VSIFTruncateL( VSILFILE *, vsi_l_offset ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00168 int CPL_DLL     VSIFFlushL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00169 int CPL_DLL     VSIFPrintfL( VSILFILE *, CPL_FORMAT_STRING(const char *), ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
00170 int CPL_DLL     VSIFPutcL( int, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00171 
00173 typedef enum
00174 {
00175     VSI_RANGE_STATUS_UNKNOWN, 
00176     VSI_RANGE_STATUS_DATA,    
00177     VSI_RANGE_STATUS_HOLE     
00178 } VSIRangeStatus;
00179 
00180 VSIRangeStatus CPL_DLL VSIFGetRangeStatusL( VSILFILE * fp, vsi_l_offset nStart, vsi_l_offset nLength );
00181 
00182 int CPL_DLL     VSIIngestFile( VSILFILE* fp,
00183                                const char* pszFilename,
00184                                GByte** ppabyRet,
00185                                vsi_l_offset* pnSize,
00186                                GIntBig nMaxSize ) CPL_WARN_UNUSED_RESULT;
00187 
00188 #if defined(VSI_STAT64_T)
00189 
00190 typedef struct VSI_STAT64_T VSIStatBufL;
00191 #else
00192 
00193 #define VSIStatBufL    VSIStatBuf
00194 #endif
00195 
00196 int CPL_DLL     VSIStatL( const char *, VSIStatBufL * ) CPL_WARN_UNUSED_RESULT;
00197 
00199 #define VSI_STAT_EXISTS_FLAG         0x1
00200 
00201 #define VSI_STAT_NATURE_FLAG         0x2
00202 
00203 #define VSI_STAT_SIZE_FLAG           0x4
00204 
00205 #define VSI_STAT_SET_ERROR_FLAG      0x8
00206 
00207 int CPL_DLL     VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags ) CPL_WARN_UNUSED_RESULT;
00208 
00209 int CPL_DLL     VSIIsCaseSensitiveFS( const char * pszFilename );
00210 
00211 int CPL_DLL     VSISupportsSparseFiles( const char* pszPath );
00212 
00213 void CPL_DLL   *VSIFGetNativeFileDescriptorL( VSILFILE* );
00214 
00215 /* ==================================================================== */
00216 /*      Memory allocation                                               */
00217 /* ==================================================================== */
00218 
00219 void CPL_DLL   *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
00220 void CPL_DLL   *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
00221 void CPL_DLL    VSIFree( void * );
00222 void CPL_DLL   *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
00223 char CPL_DLL   *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
00224 
00225 void CPL_DLL   *VSIMallocAligned( size_t nAlignment, size_t nSize ) CPL_WARN_UNUSED_RESULT;
00226 void CPL_DLL   *VSIMallocAlignedAuto( size_t nSize ) CPL_WARN_UNUSED_RESULT;
00227 void CPL_DLL    VSIFreeAligned( void* ptr );
00228 
00229 void CPL_DLL   *VSIMallocAlignedAutoVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00231 #define VSI_MALLOC_ALIGNED_AUTO_VERBOSE( size ) VSIMallocAlignedAutoVerbose(size,__FILE__,__LINE__)
00232 
00240 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
00241 
00249 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
00250 
00252 void CPL_DLL   *VSIMallocVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00254 #define VSI_MALLOC_VERBOSE( size ) VSIMallocVerbose(size,__FILE__,__LINE__)
00255 
00257 void CPL_DLL   *VSIMalloc2Verbose( size_t nSize1, size_t nSize2, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00259 #define VSI_MALLOC2_VERBOSE( nSize1, nSize2 ) VSIMalloc2Verbose(nSize1,nSize2,__FILE__,__LINE__)
00260 
00262 void CPL_DLL   *VSIMalloc3Verbose( size_t nSize1, size_t nSize2, size_t nSize3, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00264 #define VSI_MALLOC3_VERBOSE( nSize1, nSize2, nSize3 ) VSIMalloc3Verbose(nSize1,nSize2,nSize3,__FILE__,__LINE__)
00265 
00267 void CPL_DLL   *VSICallocVerbose(  size_t nCount, size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00269 #define VSI_CALLOC_VERBOSE( nCount, nSize ) VSICallocVerbose(nCount,nSize,__FILE__,__LINE__)
00270 
00272 void CPL_DLL   *VSIReallocVerbose(  void* pOldPtr, size_t nNewSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00274 #define VSI_REALLOC_VERBOSE( pOldPtr, nNewSize ) VSIReallocVerbose(pOldPtr,nNewSize,__FILE__,__LINE__)
00275 
00277 char CPL_DLL   *VSIStrdupVerbose(  const char* pszStr, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00279 #define VSI_STRDUP_VERBOSE( pszStr ) VSIStrdupVerbose(pszStr,__FILE__,__LINE__)
00280 
00281 GIntBig CPL_DLL CPLGetPhysicalRAM(void);
00282 GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void);
00283 
00284 /* ==================================================================== */
00285 /*      Other...                                                        */
00286 /* ==================================================================== */
00287 
00289 #define CPLReadDir VSIReadDir
00290 char CPL_DLL **VSIReadDir( const char * );
00291 char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
00292 char CPL_DLL **VSIReadDirEx( const char *pszPath, int nMaxFiles );
00293 int CPL_DLL VSIMkdir( const char * pathname, long mode );
00294 int CPL_DLL VSIRmdir( const char * pathname );
00295 int CPL_DLL VSIUnlink( const char * pathname );
00296 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
00297 char CPL_DLL *VSIStrerror( int );
00298 GIntBig CPL_DLL VSIGetDiskFreeSpace(const char *pszDirname);
00299 
00300 /* ==================================================================== */
00301 /*      Install special file access handlers.                           */
00302 /* ==================================================================== */
00303 void CPL_DLL VSIInstallMemFileHandler(void);
00305 void CPL_DLL VSIInstallLargeFileHandler(void);
00307 void CPL_DLL VSIInstallSubFileHandler(void);
00308 void VSIInstallCurlFileHandler(void);
00309 void CPL_DLL VSICurlClearCache(void);
00310 void VSIInstallCurlStreamingFileHandler(void);
00311 void VSIInstallS3FileHandler(void);
00312 void VSIInstallS3StreamingFileHandler(void);
00313 void VSIInstallGSFileHandler(void);
00314 void VSIInstallGSStreamingFileHandler(void);
00315 void VSIInstallGZipFileHandler(void); /* No reason to export that */
00316 void VSIInstallZipFileHandler(void); /* No reason to export that */
00317 void VSIInstallStdinHandler(void); /* No reason to export that */
00318 void VSIInstallStdoutHandler(void); /* No reason to export that */
00319 void CPL_DLL VSIInstallSparseFileHandler(void);
00320 void VSIInstallTarFileHandler(void); /* No reason to export that */
00321 void CPL_DLL VSIInstallCryptFileHandler(void);
00322 void CPL_DLL VSISetCryptKey(const GByte* pabyKey, int nKeySize);
00324 void CPL_DLL VSICleanupFileManager(void);
00327 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
00328                                     GByte *pabyData,
00329                                     vsi_l_offset nDataLength,
00330                                     int bTakeOwnership ) CPL_WARN_UNUSED_RESULT;
00331 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
00332                                     vsi_l_offset *pnDataLength,
00333                                     int bUnlinkAndSeize );
00334 
00336 typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream);
00337 void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream );
00338 
00339 /* ==================================================================== */
00340 /*      Time querying.                                                  */
00341 /* ==================================================================== */
00342 
00344 unsigned long CPL_DLL VSITime( unsigned long * );
00345 const char CPL_DLL *VSICTime( unsigned long );
00346 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
00347                               struct tm *poBrokenTime );
00348 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
00349                                  struct tm *poBrokenTime );
00353 /* -------------------------------------------------------------------- */
00354 /*      the following can be turned on for detailed logging of          */
00355 /*      almost all IO calls.                                            */
00356 /* -------------------------------------------------------------------- */
00357 #ifdef VSI_DEBUG
00358 
00359 #ifndef DEBUG
00360 #  define DEBUG
00361 #endif
00362 
00363 #include "cpl_error.h"
00364 
00365 #define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
00366 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
00367 #define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
00368 #define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
00369 #else
00370 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
00371 #define VSIDebug3( f, a1, a2, a3 ) {}
00372 #define VSIDebug2( f, a1, a2 )     {}
00373 #define VSIDebug1( f, a1 )         {}
00374 #endif
00375 
00377 CPL_C_END
00378 
00379 #endif /* ndef CPL_VSI_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.