GDAL
|
00001 /****************************************************************************** 00002 * $Id: cpl_vsi.h 28476 2015-02-13 14:40:11Z 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" 00055 /* -------------------------------------------------------------------- */ 00056 /* We need access to ``struct stat''. */ 00057 /* -------------------------------------------------------------------- */ 00058 00059 /* Unix */ 00060 #if !defined(_WIN32) && !defined(_WIN32_WCE) 00061 # include <unistd.h> 00062 #endif 00063 00064 /* Windows */ 00065 #if !defined(macos_pre10) && !defined(_WIN32_WCE) 00066 # include <sys/stat.h> 00067 #endif 00068 00069 /* Windows CE */ 00070 #if defined(_WIN32_WCE) 00071 # include <wce_stat.h> 00072 #endif 00073 00074 CPL_C_START 00075 00076 /* ==================================================================== */ 00077 /* stdio file access functions. These may not support large */ 00078 /* files, and don't necessarily go through the virtualization */ 00079 /* API. */ 00080 /* ==================================================================== */ 00081 00082 FILE CPL_DLL * VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT; 00083 int CPL_DLL VSIFClose( FILE * ); 00084 int CPL_DLL VSIFSeek( FILE *, long, int ); 00085 long CPL_DLL VSIFTell( FILE * ); 00086 void CPL_DLL VSIRewind( FILE * ); 00087 void CPL_DLL VSIFFlush( FILE * ); 00088 00089 size_t CPL_DLL VSIFRead( void *, size_t, size_t, FILE * ); 00090 size_t CPL_DLL VSIFWrite( const void *, size_t, size_t, FILE * ); 00091 char CPL_DLL *VSIFGets( char *, int, FILE * ); 00092 int CPL_DLL VSIFPuts( const char *, FILE * ); 00093 int CPL_DLL VSIFPrintf( FILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3); 00094 00095 int CPL_DLL VSIFGetc( FILE * ); 00096 int CPL_DLL VSIFPutc( int, FILE * ); 00097 int CPL_DLL VSIUngetc( int, FILE * ); 00098 int CPL_DLL VSIFEof( FILE * ); 00099 00100 /* ==================================================================== */ 00101 /* VSIStat() related. */ 00102 /* ==================================================================== */ 00103 00104 typedef struct stat VSIStatBuf; 00105 int CPL_DLL VSIStat( const char *, VSIStatBuf * ); 00106 00107 #ifdef _WIN32 00108 # define VSI_ISLNK(x) ( 0 ) /* N/A on Windows */ 00109 # define VSI_ISREG(x) ((x) & S_IFREG) 00110 # define VSI_ISDIR(x) ((x) & S_IFDIR) 00111 # define VSI_ISCHR(x) ((x) & S_IFCHR) 00112 # define VSI_ISBLK(x) ( 0 ) /* N/A on Windows */ 00113 #else 00114 # define VSI_ISLNK(x) S_ISLNK(x) 00115 # define VSI_ISREG(x) S_ISREG(x) 00116 # define VSI_ISDIR(x) S_ISDIR(x) 00117 # define VSI_ISCHR(x) S_ISCHR(x) 00118 # define VSI_ISBLK(x) S_ISBLK(x) 00119 #endif 00120 00121 /* ==================================================================== */ 00122 /* 64bit stdio file access functions. If we have a big size */ 00123 /* defined, then provide protypes for the large file API, */ 00124 /* otherwise redefine to use the regular api. */ 00125 /* ==================================================================== */ 00126 typedef GUIntBig vsi_l_offset; 00127 00128 /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */ 00129 #ifdef DEBUG 00130 #define VSIL_STRICT_ENFORCE 00131 #endif 00132 00133 #ifdef VSIL_STRICT_ENFORCE 00134 typedef struct _VSILFILE VSILFILE; 00135 #else 00136 typedef FILE VSILFILE; 00137 #endif 00138 00139 VSILFILE CPL_DLL * VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT; 00140 int CPL_DLL VSIFCloseL( VSILFILE * ); 00141 int CPL_DLL VSIFSeekL( VSILFILE *, vsi_l_offset, int ); 00142 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * ); 00143 void CPL_DLL VSIRewindL( VSILFILE * ); 00144 size_t CPL_DLL VSIFReadL( void *, size_t, size_t, VSILFILE * ); 00145 int CPL_DLL VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * ); 00146 size_t CPL_DLL VSIFWriteL( const void *, size_t, size_t, VSILFILE * ); 00147 int CPL_DLL VSIFEofL( VSILFILE * ); 00148 int CPL_DLL VSIFTruncateL( VSILFILE *, vsi_l_offset ); 00149 int CPL_DLL VSIFFlushL( VSILFILE * ); 00150 int CPL_DLL VSIFPrintfL( VSILFILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3); 00151 int CPL_DLL VSIFPutcL( int, VSILFILE * ); 00152 00153 int CPL_DLL VSIIngestFile( VSILFILE* fp, 00154 const char* pszFilename, 00155 GByte** ppabyRet, 00156 vsi_l_offset* pnSize, 00157 GIntBig nMaxSize ); 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 * ); 00166 00167 #define VSI_STAT_EXISTS_FLAG 0x1 00168 #define VSI_STAT_NATURE_FLAG 0x2 00169 #define VSI_STAT_SIZE_FLAG 0x4 00170 00171 int CPL_DLL VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags ); 00172 00173 int CPL_DLL VSIIsCaseSensitiveFS( const char * pszFilename ); 00174 00175 void CPL_DLL *VSIFGetNativeFileDescriptorL( VSILFILE* ); 00176 00177 /* ==================================================================== */ 00178 /* Memory allocation */ 00179 /* ==================================================================== */ 00180 00181 void CPL_DLL *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT; 00182 void CPL_DLL *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT; 00183 void CPL_DLL VSIFree( void * ); 00184 void CPL_DLL *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT; 00185 char CPL_DLL *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT; 00186 00194 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT; 00195 00203 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT; 00204 00205 GIntBig CPL_DLL CPLGetPhysicalRAM(void); 00206 GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void); 00207 00208 /* ==================================================================== */ 00209 /* Other... */ 00210 /* ==================================================================== */ 00211 00212 #define CPLReadDir VSIReadDir 00213 char CPL_DLL **VSIReadDir( const char * ); 00214 char CPL_DLL **VSIReadDirRecursive( const char *pszPath ); 00215 int CPL_DLL VSIMkdir( const char * pathname, long mode ); 00216 int CPL_DLL VSIRmdir( const char * pathname ); 00217 int CPL_DLL VSIUnlink( const char * pathname ); 00218 int CPL_DLL VSIRename( const char * oldpath, const char * newpath ); 00219 char CPL_DLL *VSIStrerror( int ); 00220 00221 /* ==================================================================== */ 00222 /* Install special file access handlers. */ 00223 /* ==================================================================== */ 00224 void CPL_DLL VSIInstallMemFileHandler(void); 00225 void CPL_DLL VSIInstallLargeFileHandler(void); 00226 void CPL_DLL VSIInstallSubFileHandler(void); 00227 void VSIInstallCurlFileHandler(void); 00228 void VSIInstallCurlStreamingFileHandler(void); 00229 void VSIInstallGZipFileHandler(void); /* No reason to export that */ 00230 void VSIInstallZipFileHandler(void); /* No reason to export that */ 00231 void VSIInstallStdinHandler(void); /* No reason to export that */ 00232 void VSIInstallStdoutHandler(void); /* No reason to export that */ 00233 void CPL_DLL VSIInstallSparseFileHandler(void); 00234 void VSIInstallTarFileHandler(void); /* No reason to export that */ 00235 void CPL_DLL VSICleanupFileManager(void); 00236 00237 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename, 00238 GByte *pabyData, 00239 vsi_l_offset nDataLength, 00240 int bTakeOwnership ); 00241 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename, 00242 vsi_l_offset *pnDataLength, 00243 int bUnlinkAndSeize ); 00244 00245 typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream); 00246 void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream ); 00247 00248 /* ==================================================================== */ 00249 /* Time quering. */ 00250 /* ==================================================================== */ 00251 00252 unsigned long CPL_DLL VSITime( unsigned long * ); 00253 const char CPL_DLL *VSICTime( unsigned long ); 00254 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime, 00255 struct tm *poBrokenTime ); 00256 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime, 00257 struct tm *poBrokenTime ); 00258 00259 /* -------------------------------------------------------------------- */ 00260 /* the following can be turned on for detailed logging of */ 00261 /* almost all IO calls. */ 00262 /* -------------------------------------------------------------------- */ 00263 #ifdef VSI_DEBUG 00264 00265 #ifndef DEBUG 00266 # define DEBUG 00267 #endif 00268 00269 #include "cpl_error.h" 00270 00271 #define VSIDebug4(f,a1,a2,a3,a4) CPLDebug( "VSI", f, a1, a2, a3, a4 ); 00272 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 ); 00273 #define VSIDebug2( f, a1, a2 ) CPLDebug( "VSI", f, a1, a2 ); 00274 #define VSIDebug1( f, a1 ) CPLDebug( "VSI", f, a1 ); 00275 #else 00276 #define VSIDebug4( f, a1, a2, a3, a4 ) {} 00277 #define VSIDebug3( f, a1, a2, a3 ) {} 00278 #define VSIDebug2( f, a1, a2 ) {} 00279 #define VSIDebug1( f, a1 ) {} 00280 #endif 00281 00282 CPL_C_END 00283 00284 #endif /* ndef CPL_VSI_H_INCLUDED */