cpl_vsi.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_vsi.h 33758 2016-03-21 09:06:22Z 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 
00068 #ifdef ENABLE_EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
00069 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_WARN_UNUSED_RESULT
00070 #else
00071 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
00072 #endif
00073 
00074 /* ==================================================================== */
00075 /*      stdio file access functions.  These may not support large       */
00076 /*      files, and don't necessarily go through the virtualization      */
00077 /*      API.                                                            */
00078 /* ==================================================================== */
00079 
00080 FILE CPL_DLL *  VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00081 int CPL_DLL     VSIFClose( FILE * );
00082 int CPL_DLL     VSIFSeek( FILE *, long, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00083 long CPL_DLL    VSIFTell( FILE * ) CPL_WARN_UNUSED_RESULT;
00084 void CPL_DLL    VSIRewind( FILE * );
00085 void CPL_DLL    VSIFFlush( FILE * );
00086 
00087 size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00088 size_t CPL_DLL  VSIFWrite( const void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00089 char CPL_DLL   *VSIFGets( char *, int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00090 int CPL_DLL     VSIFPuts( const char *, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00091 int CPL_DLL     VSIFPrintf( FILE *, const char *, ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
00092 
00093 int CPL_DLL     VSIFGetc( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00094 int CPL_DLL     VSIFPutc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00095 int CPL_DLL     VSIUngetc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00096 int CPL_DLL     VSIFEof( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00097 
00098 /* ==================================================================== */
00099 /*      VSIStat() related.                                              */
00100 /* ==================================================================== */
00101 
00102 typedef struct stat VSIStatBuf;
00103 int CPL_DLL VSIStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
00104 
00105 #ifdef _WIN32
00106 #  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
00107 #  define VSI_ISREG(x)  ((x) & S_IFREG)
00108 #  define VSI_ISDIR(x)  ((x) & S_IFDIR)
00109 #  define VSI_ISCHR(x)  ((x) & S_IFCHR)
00110 #  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
00111 #else
00112 #  define VSI_ISLNK(x)  S_ISLNK(x)
00113 #  define VSI_ISREG(x)  S_ISREG(x)
00114 #  define VSI_ISDIR(x)  S_ISDIR(x)
00115 #  define VSI_ISCHR(x)  S_ISCHR(x)
00116 #  define VSI_ISBLK(x)  S_ISBLK(x)
00117 #endif
00118 
00119 /* ==================================================================== */
00120 /*      64bit stdio file access functions.  If we have a big size       */
00121 /*      defined, then provide prototypes for the large file API,        */
00122 /*      otherwise redefine to use the regular api.                      */
00123 /* ==================================================================== */
00124 typedef GUIntBig vsi_l_offset;
00125 #define VSI_L_OFFSET_MAX GUINTBIG_MAX
00126 
00127 /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
00128 #ifdef DEBUG
00129 #define VSIL_STRICT_ENFORCE
00130 #endif
00131 
00132 #ifdef VSIL_STRICT_ENFORCE
00133 typedef struct _VSILFILE VSILFILE;
00134 #else
00135 typedef FILE VSILFILE;
00136 #endif
00137 
00138 VSILFILE CPL_DLL *  VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
00139 VSILFILE CPL_DLL *  VSIFOpenExL( const char *, const char *, int ) CPL_WARN_UNUSED_RESULT;
00140 int CPL_DLL     VSIFCloseL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00141 int CPL_DLL     VSIFSeekL( VSILFILE *, vsi_l_offset, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00142 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * ) CPL_WARN_UNUSED_RESULT;
00143 void CPL_DLL    VSIRewindL( VSILFILE * );
00144 size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00145 int CPL_DLL     VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00146 size_t CPL_DLL  VSIFWriteL( const void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00147 int CPL_DLL     VSIFEofL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00148 int CPL_DLL     VSIFTruncateL( VSILFILE *, vsi_l_offset ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00149 int CPL_DLL     VSIFFlushL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00150 int CPL_DLL     VSIFPrintfL( VSILFILE *, const char *, ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
00151 int CPL_DLL     VSIFPutcL( int, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
00152 
00153 int CPL_DLL     VSIIngestFile( VSILFILE* fp,
00154                                const char* pszFilename,
00155                                GByte** ppabyRet,
00156                                vsi_l_offset* pnSize,
00157                                GIntBig nMaxSize ) CPL_WARN_UNUSED_RESULT;
00158 
00159 #if defined(VSI_STAT64_T)
00160 typedef struct VSI_STAT64_T VSIStatBufL;
00161 #else
00162 #define VSIStatBufL    VSIStatBuf
00163 #endif
00164 
00165 int CPL_DLL     VSIStatL( const char *, VSIStatBufL * ) CPL_WARN_UNUSED_RESULT;
00166 
00167 #define VSI_STAT_EXISTS_FLAG         0x1
00168 #define VSI_STAT_NATURE_FLAG         0x2
00169 #define VSI_STAT_SIZE_FLAG           0x4
00170 #define VSI_STAT_SET_ERROR_FLAG      0x8
00171 
00172 int CPL_DLL     VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags ) CPL_WARN_UNUSED_RESULT;
00173 
00174 int CPL_DLL     VSIIsCaseSensitiveFS( const char * pszFilename );
00175 
00176 void CPL_DLL   *VSIFGetNativeFileDescriptorL( VSILFILE* );
00177 
00178 /* ==================================================================== */
00179 /*      Memory allocation                                               */
00180 /* ==================================================================== */
00181 
00182 void CPL_DLL   *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
00183 void CPL_DLL   *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
00184 void CPL_DLL    VSIFree( void * );
00185 void CPL_DLL   *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
00186 char CPL_DLL   *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
00187 
00195 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
00196 
00204 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
00205 
00206 
00207 void CPL_DLL   *VSIMallocVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00208 #define VSI_MALLOC_VERBOSE( size ) VSIMallocVerbose(size,__FILE__,__LINE__)
00209 
00210 void CPL_DLL   *VSIMalloc2Verbose( size_t nSize1, size_t nSize2, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00211 #define VSI_MALLOC2_VERBOSE( nSize1, nSize2 ) VSIMalloc2Verbose(nSize1,nSize2,__FILE__,__LINE__)
00212 
00213 void CPL_DLL   *VSIMalloc3Verbose( size_t nSize1, size_t nSize2, size_t nSize3, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00214 #define VSI_MALLOC3_VERBOSE( nSize1, nSize2, nSize3 ) VSIMalloc3Verbose(nSize1,nSize2,nSize3,__FILE__,__LINE__)
00215 
00216 void CPL_DLL   *VSICallocVerbose(  size_t nCount, size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00217 #define VSI_CALLOC_VERBOSE( nCount, nSize ) VSICallocVerbose(nCount,nSize,__FILE__,__LINE__)
00218 
00219 void CPL_DLL   *VSIReallocVerbose(  void* pOldPtr, size_t nNewSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00220 #define VSI_REALLOC_VERBOSE( pOldPtr, nNewSize ) VSIReallocVerbose(pOldPtr,nNewSize,__FILE__,__LINE__)
00221 
00222 char CPL_DLL   *VSIStrdupVerbose(  const char* pszStr, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
00223 #define VSI_STRDUP_VERBOSE( pszStr ) VSIStrdupVerbose(pszStr,__FILE__,__LINE__)
00224 
00225 
00226 GIntBig CPL_DLL CPLGetPhysicalRAM(void);
00227 GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void);
00228 
00229 /* ==================================================================== */
00230 /*      Other...                                                        */
00231 /* ==================================================================== */
00232 
00233 #define CPLReadDir VSIReadDir
00234 char CPL_DLL **VSIReadDir( const char * );
00235 char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
00236 char CPL_DLL **VSIReadDirEx( const char *pszPath, int nMaxFiles );
00237 int CPL_DLL VSIMkdir( const char * pathname, long mode );
00238 int CPL_DLL VSIRmdir( const char * pathname );
00239 int CPL_DLL VSIUnlink( const char * pathname );
00240 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
00241 char CPL_DLL *VSIStrerror( int );
00242 GIntBig CPL_DLL VSIGetDiskFreeSpace(const char *pszDirname);
00243 
00244 /* ==================================================================== */
00245 /*      Install special file access handlers.                           */
00246 /* ==================================================================== */
00247 void CPL_DLL VSIInstallMemFileHandler(void);
00248 void CPL_DLL VSIInstallLargeFileHandler(void);
00249 void CPL_DLL VSIInstallSubFileHandler(void);
00250 void VSIInstallCurlFileHandler(void);
00251 void VSIInstallCurlStreamingFileHandler(void);
00252 void VSIInstallS3FileHandler(void);
00253 void VSIInstallS3StreamingFileHandler(void);
00254 void VSIInstallGZipFileHandler(void); /* No reason to export that */
00255 void VSIInstallZipFileHandler(void); /* No reason to export that */
00256 void VSIInstallStdinHandler(void); /* No reason to export that */
00257 void VSIInstallStdoutHandler(void); /* No reason to export that */
00258 void CPL_DLL VSIInstallSparseFileHandler(void);
00259 void VSIInstallTarFileHandler(void); /* No reason to export that */
00260 void CPL_DLL VSIInstallCryptFileHandler(void);
00261 void CPL_DLL VSISetCryptKey(const GByte* pabyKey, int nKeySize);
00262 void CPL_DLL VSICleanupFileManager(void);
00263 
00264 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
00265                                     GByte *pabyData,
00266                                     vsi_l_offset nDataLength,
00267                                     int bTakeOwnership ) CPL_WARN_UNUSED_RESULT;
00268 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
00269                                     vsi_l_offset *pnDataLength,
00270                                     int bUnlinkAndSeize );
00271 
00272 typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream);
00273 void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream );
00274 
00275 /* ==================================================================== */
00276 /*      Time querying.                                                  */
00277 /* ==================================================================== */
00278 
00279 unsigned long CPL_DLL VSITime( unsigned long * );
00280 const char CPL_DLL *VSICTime( unsigned long );
00281 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
00282                               struct tm *poBrokenTime );
00283 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
00284                                  struct tm *poBrokenTime );
00285 
00286 /* -------------------------------------------------------------------- */
00287 /*      the following can be turned on for detailed logging of          */
00288 /*      almost all IO calls.                                            */
00289 /* -------------------------------------------------------------------- */
00290 #ifdef VSI_DEBUG
00291 
00292 #ifndef DEBUG
00293 #  define DEBUG
00294 #endif
00295 
00296 #include "cpl_error.h"
00297 
00298 #define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
00299 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
00300 #define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
00301 #define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
00302 #else
00303 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
00304 #define VSIDebug3( f, a1, a2, a3 ) {}
00305 #define VSIDebug2( f, a1, a2 )     {}
00306 #define VSIDebug1( f, a1 )         {}
00307 #endif
00308 
00309 CPL_C_END
00310 
00311 #endif /* ndef CPL_VSI_H_INCLUDED */

Generated for GDAL by doxygen 1.6.1.