OGR
cpl_vsi.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: cpl_vsi.h 33758 2016-03-21 09:06:22Z rouault $
3  *
4  * Project: CPL - Common Portability Library
5  * Author: Frank Warmerdam, warmerdam@pobox.com
6  * Purpose: Include file defining Virtual File System (VSI) functions, a
7  * layer over POSIX file and other system services.
8  *
9  ******************************************************************************
10  * Copyright (c) 1998, Frank Warmerdam
11  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
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 #ifndef CPL_VSI_H_INCLUDED
33 #define CPL_VSI_H_INCLUDED
34 
35 #include "cpl_port.h"
54 /* -------------------------------------------------------------------- */
55 /* We need access to ``struct stat''. */
56 /* -------------------------------------------------------------------- */
57 
58 /* Unix */
59 #if !defined(_WIN32)
60 # include <unistd.h>
61 #endif
62 
63 /* Windows */
64 #include <sys/stat.h>
65 
66 CPL_C_START
67 
68 #ifdef ENABLE_EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
69 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_WARN_UNUSED_RESULT
70 #else
71 #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
72 #endif
73 
74 /* ==================================================================== */
75 /* stdio file access functions. These may not support large */
76 /* files, and don't necessarily go through the virtualization */
77 /* API. */
78 /* ==================================================================== */
79 
80 FILE CPL_DLL * VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
81 int CPL_DLL VSIFClose( FILE * );
82 int CPL_DLL VSIFSeek( FILE *, long, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
83 long CPL_DLL VSIFTell( FILE * ) CPL_WARN_UNUSED_RESULT;
84 void CPL_DLL VSIRewind( FILE * );
85 void CPL_DLL VSIFFlush( FILE * );
86 
87 size_t CPL_DLL VSIFRead( void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
88 size_t CPL_DLL VSIFWrite( const void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
89 char CPL_DLL *VSIFGets( char *, int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
90 int CPL_DLL VSIFPuts( const char *, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
91 int CPL_DLL VSIFPrintf( FILE *, const char *, ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
92 
93 int CPL_DLL VSIFGetc( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
94 int CPL_DLL VSIFPutc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
95 int CPL_DLL VSIUngetc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
96 int CPL_DLL VSIFEof( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
97 
98 /* ==================================================================== */
99 /* VSIStat() related. */
100 /* ==================================================================== */
101 
102 typedef struct stat VSIStatBuf;
103 int CPL_DLL VSIStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
104 
105 #ifdef _WIN32
106 # define VSI_ISLNK(x) ( 0 ) /* N/A on Windows */
107 # define VSI_ISREG(x) ((x) & S_IFREG)
108 # define VSI_ISDIR(x) ((x) & S_IFDIR)
109 # define VSI_ISCHR(x) ((x) & S_IFCHR)
110 # define VSI_ISBLK(x) ( 0 ) /* N/A on Windows */
111 #else
112 # define VSI_ISLNK(x) S_ISLNK(x)
113 # define VSI_ISREG(x) S_ISREG(x)
114 # define VSI_ISDIR(x) S_ISDIR(x)
115 # define VSI_ISCHR(x) S_ISCHR(x)
116 # define VSI_ISBLK(x) S_ISBLK(x)
117 #endif
118 
119 /* ==================================================================== */
120 /* 64bit stdio file access functions. If we have a big size */
121 /* defined, then provide prototypes for the large file API, */
122 /* otherwise redefine to use the regular api. */
123 /* ==================================================================== */
124 typedef GUIntBig vsi_l_offset;
125 #define VSI_L_OFFSET_MAX GUINTBIG_MAX
126 
127 /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
128 #ifdef DEBUG
129 #define VSIL_STRICT_ENFORCE
130 #endif
131 
132 #ifdef VSIL_STRICT_ENFORCE
133 typedef struct _VSILFILE VSILFILE;
134 #else
135 typedef FILE VSILFILE;
136 #endif
137 
138 VSILFILE CPL_DLL * VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
139 VSILFILE CPL_DLL * VSIFOpenExL( const char *, const char *, int ) CPL_WARN_UNUSED_RESULT;
140 int CPL_DLL VSIFCloseL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
141 int CPL_DLL VSIFSeekL( VSILFILE *, vsi_l_offset, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
142 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * ) CPL_WARN_UNUSED_RESULT;
143 void CPL_DLL VSIRewindL( VSILFILE * );
144 size_t CPL_DLL VSIFReadL( void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
145 int CPL_DLL VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
146 size_t CPL_DLL VSIFWriteL( const void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
147 int CPL_DLL VSIFEofL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
148 int CPL_DLL VSIFTruncateL( VSILFILE *, vsi_l_offset ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
149 int CPL_DLL VSIFFlushL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
150 int CPL_DLL VSIFPrintfL( VSILFILE *, const char *, ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
151 int CPL_DLL VSIFPutcL( int, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
152 
153 int CPL_DLL VSIIngestFile( VSILFILE* fp,
154  const char* pszFilename,
155  GByte** ppabyRet,
156  vsi_l_offset* pnSize,
157  GIntBig nMaxSize ) CPL_WARN_UNUSED_RESULT;
158 
159 #if defined(VSI_STAT64_T)
160 typedef struct VSI_STAT64_T VSIStatBufL;
161 #else
162 #define VSIStatBufL VSIStatBuf
163 #endif
164 
165 int CPL_DLL VSIStatL( const char *, VSIStatBufL * ) CPL_WARN_UNUSED_RESULT;
166 
167 #define VSI_STAT_EXISTS_FLAG 0x1
168 #define VSI_STAT_NATURE_FLAG 0x2
169 #define VSI_STAT_SIZE_FLAG 0x4
170 #define VSI_STAT_SET_ERROR_FLAG 0x8
171 
172 int CPL_DLL VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags ) CPL_WARN_UNUSED_RESULT;
173 
174 int CPL_DLL VSIIsCaseSensitiveFS( const char * pszFilename );
175 
176 void CPL_DLL *VSIFGetNativeFileDescriptorL( VSILFILE* );
177 
178 /* ==================================================================== */
179 /* Memory allocation */
180 /* ==================================================================== */
181 
182 void CPL_DLL *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
183 void CPL_DLL *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
184 void CPL_DLL VSIFree( void * );
185 void CPL_DLL *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
186 char CPL_DLL *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
187 
195 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
196 
204 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
205 
206 
207 void CPL_DLL *VSIMallocVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
208 #define VSI_MALLOC_VERBOSE( size ) VSIMallocVerbose(size,__FILE__,__LINE__)
209 
210 void CPL_DLL *VSIMalloc2Verbose( size_t nSize1, size_t nSize2, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
211 #define VSI_MALLOC2_VERBOSE( nSize1, nSize2 ) VSIMalloc2Verbose(nSize1,nSize2,__FILE__,__LINE__)
212 
213 void CPL_DLL *VSIMalloc3Verbose( size_t nSize1, size_t nSize2, size_t nSize3, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
214 #define VSI_MALLOC3_VERBOSE( nSize1, nSize2, nSize3 ) VSIMalloc3Verbose(nSize1,nSize2,nSize3,__FILE__,__LINE__)
215 
216 void CPL_DLL *VSICallocVerbose( size_t nCount, size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
217 #define VSI_CALLOC_VERBOSE( nCount, nSize ) VSICallocVerbose(nCount,nSize,__FILE__,__LINE__)
218 
219 void CPL_DLL *VSIReallocVerbose( void* pOldPtr, size_t nNewSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
220 #define VSI_REALLOC_VERBOSE( pOldPtr, nNewSize ) VSIReallocVerbose(pOldPtr,nNewSize,__FILE__,__LINE__)
221 
222 char CPL_DLL *VSIStrdupVerbose( const char* pszStr, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
223 #define VSI_STRDUP_VERBOSE( pszStr ) VSIStrdupVerbose(pszStr,__FILE__,__LINE__)
224 
225 
226 GIntBig CPL_DLL CPLGetPhysicalRAM(void);
227 GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void);
228 
229 /* ==================================================================== */
230 /* Other... */
231 /* ==================================================================== */
232 
233 #define CPLReadDir VSIReadDir
234 char CPL_DLL **VSIReadDir( const char * );
235 char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
236 char CPL_DLL **VSIReadDirEx( const char *pszPath, int nMaxFiles );
237 int CPL_DLL VSIMkdir( const char * pathname, long mode );
238 int CPL_DLL VSIRmdir( const char * pathname );
239 int CPL_DLL VSIUnlink( const char * pathname );
240 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
241 char CPL_DLL *VSIStrerror( int );
242 GIntBig CPL_DLL VSIGetDiskFreeSpace(const char *pszDirname);
243 
244 /* ==================================================================== */
245 /* Install special file access handlers. */
246 /* ==================================================================== */
247 void CPL_DLL VSIInstallMemFileHandler(void);
248 void CPL_DLL VSIInstallLargeFileHandler(void);
249 void CPL_DLL VSIInstallSubFileHandler(void);
250 void VSIInstallCurlFileHandler(void);
252 void VSIInstallS3FileHandler(void);
254 void VSIInstallGZipFileHandler(void); /* No reason to export that */
255 void VSIInstallZipFileHandler(void); /* No reason to export that */
256 void VSIInstallStdinHandler(void); /* No reason to export that */
257 void VSIInstallStdoutHandler(void); /* No reason to export that */
258 void CPL_DLL VSIInstallSparseFileHandler(void);
259 void VSIInstallTarFileHandler(void); /* No reason to export that */
260 void CPL_DLL VSIInstallCryptFileHandler(void);
261 void CPL_DLL VSISetCryptKey(const GByte* pabyKey, int nKeySize);
262 void CPL_DLL VSICleanupFileManager(void);
263 
264 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
265  GByte *pabyData,
266  vsi_l_offset nDataLength,
267  int bTakeOwnership ) CPL_WARN_UNUSED_RESULT;
268 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
269  vsi_l_offset *pnDataLength,
270  int bUnlinkAndSeize );
271 
272 typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream);
273 void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream );
274 
275 /* ==================================================================== */
276 /* Time querying. */
277 /* ==================================================================== */
278 
279 unsigned long CPL_DLL VSITime( unsigned long * );
280 const char CPL_DLL *VSICTime( unsigned long );
281 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
282  struct tm *poBrokenTime );
283 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
284  struct tm *poBrokenTime );
285 
286 /* -------------------------------------------------------------------- */
287 /* the following can be turned on for detailed logging of */
288 /* almost all IO calls. */
289 /* -------------------------------------------------------------------- */
290 #ifdef VSI_DEBUG
291 
292 #ifndef DEBUG
293 # define DEBUG
294 #endif
295 
296 #include "cpl_error.h"
297 
298 #define VSIDebug4(f,a1,a2,a3,a4) CPLDebug( "VSI", f, a1, a2, a3, a4 );
299 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
300 #define VSIDebug2( f, a1, a2 ) CPLDebug( "VSI", f, a1, a2 );
301 #define VSIDebug1( f, a1 ) CPLDebug( "VSI", f, a1 );
302 #else
303 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
304 #define VSIDebug3( f, a1, a2, a3 ) {}
305 #define VSIDebug2( f, a1, a2 ) {}
306 #define VSIDebug1( f, a1 ) {}
307 #endif
308 
309 CPL_C_END
310 
311 #endif /* ndef CPL_VSI_H_INCLUDED */
VSILFILE * VSIFOpenL(const char *, const char *)
Open file.
Definition: cpl_vsil.cpp:546
int VSIMkdir(const char *pathname, long mode)
Create a directory.
Definition: cpl_vsil.cpp:303
GIntBig CPLGetPhysicalRAM(void)
Definition: cpl_vsisimple.cpp:1118
char ** VSIReadDir(const char *)
Read names in a directory.
Definition: cpl_vsil.cpp:65
int VSIRename(const char *oldpath, const char *newpath)
Rename a file.
Definition: cpl_vsil.cpp:362
void VSIRewindL(VSILFILE *)
Rewind the file pointer to the beginning of the file.
Definition: cpl_vsil.cpp:714
int VSIIngestFile(VSILFILE *fp, const char *pszFilename, GByte **ppabyRet, vsi_l_offset *pnSize, GIntBig nMaxSize)
Ingest a file into memory.
Definition: cpl_vsil.cpp:995
void * VSIFGetNativeFileDescriptorL(VSILFILE *)
Returns the "native" file descriptor for the virtual handle.
Definition: cpl_vsil.cpp:1175
size_t VSIFReadL(void *, size_t, size_t, VSILFILE *)
Read bytes from file.
Definition: cpl_vsil.cpp:772
void VSIInstallS3FileHandler(void)
Install /vsis3/ Amazon S3 file system handler (requires libcurl)
Definition: cpl_vsil_curl.cpp:4328
char ** VSIReadDirEx(const char *pszPath, int nMaxFiles)
Read names in a directory.
Definition: cpl_vsil.cpp:99
void VSIStdoutSetRedirection(VSIWriteFunction pFct, FILE *stream)
Definition: cpl_vsil_stdout.cpp:57
GIntBig CPLGetUsablePhysicalRAM(void)
Definition: cpl_vsisimple.cpp:1185
int VSIStatL(const char *, VSIStatBufL *)
Get filesystem object info.
Definition: cpl_vsil.cpp:424
void VSIInstallStdoutHandler(void)
Install /vsistdout/ file system handler.
Definition: cpl_vsil_stdout.cpp:422
void VSIInstallSubFileHandler(void)
Definition: cpl_vsil_subfile.cpp:464
void VSIInstallCurlStreamingFileHandler(void)
Install /vsicurl_streaming/ HTTP/FTP file system handler (requires libcurl)
Definition: cpl_vsil_curl_streaming.cpp:1582
void VSIInstallStdinHandler(void)
Install /vsistdin/ file system handler.
Definition: cpl_vsil_stdin.cpp:397
int VSIFTruncateL(VSILFILE *, vsi_l_offset)
Truncate/expand the file to the specified size.
Definition: cpl_vsil.cpp:897
int VSIFFlushL(VSILFILE *)
Flush pending writes to disk.
Definition: cpl_vsil.cpp:740
VSILFILE * VSIFileFromMemBuffer(const char *pszFilename, GByte *pabyData, vsi_l_offset nDataLength, int bTakeOwnership)
Create memory "file" from a buffer.
Definition: cpl_vsi_mem.cpp:865
void VSIInstallTarFileHandler(void)
Install /vsitar/ file system handler.
Definition: cpl_vsil_tar.cpp:495
void VSIInstallZipFileHandler(void)
Install ZIP file system handler.
Definition: cpl_vsil_gzip.cpp:2415
int VSIIsCaseSensitiveFS(const char *pszFilename)
Returns if the filenames of the filesystem are case sensitive.
Definition: cpl_vsil.cpp:508
VSILFILE * VSIFOpenExL(const char *, const char *, int)
Open file.
Definition: cpl_vsil.cpp:595
int VSIFPrintfL(VSILFILE *, const char *,...)
Formatted write to file.
Definition: cpl_vsil.cpp:923
GIntBig VSIGetDiskFreeSpace(const char *pszDirname)
Return free disk space available on the filesystem.
Definition: cpl_vsil.cpp:1196
void VSIInstallSparseFileHandler(void)
Definition: cpl_vsil_sparsefile.cpp:566
int VSIFReadMultiRangeL(int nRanges, void **ppData, const vsi_l_offset *panOffsets, const size_t *panSizes, VSILFILE *)
Read several ranges of bytes from file.
Definition: cpl_vsil.cpp:808
int VSIStatExL(const char *pszFilename, VSIStatBufL *psStatBuf, int nFlags)
Get filesystem object info.
Definition: cpl_vsil.cpp:461
void VSIInstallGZipFileHandler(void)
Install GZip file system handler.
Definition: cpl_vsil_gzip.cpp:1612
int VSIFEofL(VSILFILE *)
Test for end of file.
Definition: cpl_vsil.cpp:870
vsi_l_offset VSIFTellL(VSILFILE *)
Tell current file offset.
Definition: cpl_vsil.cpp:692
int VSIFPutcL(int, VSILFILE *)
Write a single byte to the file.
Definition: cpl_vsil.cpp:959
int VSIFSeekL(VSILFILE *, vsi_l_offset, int)
Seek to requested offset.
Definition: cpl_vsil.cpp:664
void VSIInstallCryptFileHandler(void)
Install /vsicrypt/ encrypted file system handler (requires libcrypto++)
Definition: cpl_vsil_crypt.cpp:1842
int VSIRmdir(const char *pathname)
Delete a directory.
Definition: cpl_vsil.cpp:391
void VSIInstallCurlFileHandler(void)
Install /vsicurl/ HTTP/FTP file system handler (requires libcurl)
Definition: cpl_vsil_curl.cpp:3254
void * VSIMalloc3(size_t nSize1, size_t nSize2, size_t nSize3)
Definition: cpl_vsisimple.cpp:890
int VSIUnlink(const char *pathname)
Delete a file.
Definition: cpl_vsil.cpp:331
int VSIFCloseL(VSILFILE *)
Close file.
Definition: cpl_vsil.cpp:629
void VSIInstallMemFileHandler(void)
Install "memory" file system handler.
Definition: cpl_vsi_mem.cpp:835
void * VSIMalloc2(size_t nSize1, size_t nSize2)
Definition: cpl_vsisimple.cpp:878
GByte * VSIGetMemFileBuffer(const char *pszFilename, vsi_l_offset *pnDataLength, int bUnlinkAndSeize)
Fetch buffer underlying memory file.
Definition: cpl_vsi_mem.cpp:921
void VSISetCryptKey(const GByte *pabyKey, int nKeySize)
Definition: cpl_vsil_crypt.cpp:185
size_t VSIFWriteL(const void *, size_t, size_t, VSILFILE *)
Write bytes to file.
Definition: cpl_vsil.cpp:841
char ** VSIReadDirRecursive(const char *pszPath)
Read names in a directory recursively.
Definition: cpl_vsil.cpp:142
void VSIInstallS3StreamingFileHandler(void)
Install /vsis3_streaming/ Amazon S3 file system handler (requires libcurl)
Definition: cpl_vsil_curl_streaming.cpp:1755

Generated for GDAL by doxygen 1.8.13.