GDAL
cpl_vsi.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: cpl_vsi.h 27044 2014-03-16 23:41:27Z 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"
55 /* -------------------------------------------------------------------- */
56 /* We need access to ``struct stat''. */
57 /* -------------------------------------------------------------------- */
58 
59 /* Unix */
60 #if !defined(_WIN32) && !defined(_WIN32_WCE)
61 # include <unistd.h>
62 #endif
63 
64 /* Windows */
65 #if !defined(macos_pre10) && !defined(_WIN32_WCE)
66 # include <sys/stat.h>
67 #endif
68 
69 /* Windows CE */
70 #if defined(_WIN32_WCE)
71 # include <wce_stat.h>
72 #endif
73 
74 CPL_C_START
75 
76 /* ==================================================================== */
77 /* stdio file access functions. These may not support large */
78 /* files, and don't necessarily go through the virtualization */
79 /* API. */
80 /* ==================================================================== */
81 
82 FILE CPL_DLL * VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
83 int CPL_DLL VSIFClose( FILE * );
84 int CPL_DLL VSIFSeek( FILE *, long, int );
85 long CPL_DLL VSIFTell( FILE * );
86 void CPL_DLL VSIRewind( FILE * );
87 void CPL_DLL VSIFFlush( FILE * );
88 
89 size_t CPL_DLL VSIFRead( void *, size_t, size_t, FILE * );
90 size_t CPL_DLL VSIFWrite( const void *, size_t, size_t, FILE * );
91 char CPL_DLL *VSIFGets( char *, int, FILE * );
92 int CPL_DLL VSIFPuts( const char *, FILE * );
93 int CPL_DLL VSIFPrintf( FILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
94 
95 int CPL_DLL VSIFGetc( FILE * );
96 int CPL_DLL VSIFPutc( int, FILE * );
97 int CPL_DLL VSIUngetc( int, FILE * );
98 int CPL_DLL VSIFEof( FILE * );
99 
100 /* ==================================================================== */
101 /* VSIStat() related. */
102 /* ==================================================================== */
103 
104 typedef struct stat VSIStatBuf;
105 int CPL_DLL VSIStat( const char *, VSIStatBuf * );
106 
107 #ifdef _WIN32
108 # define VSI_ISLNK(x) ( 0 ) /* N/A on Windows */
109 # define VSI_ISREG(x) ((x) & S_IFREG)
110 # define VSI_ISDIR(x) ((x) & S_IFDIR)
111 # define VSI_ISCHR(x) ((x) & S_IFCHR)
112 # define VSI_ISBLK(x) ( 0 ) /* N/A on Windows */
113 #else
114 # define VSI_ISLNK(x) S_ISLNK(x)
115 # define VSI_ISREG(x) S_ISREG(x)
116 # define VSI_ISDIR(x) S_ISDIR(x)
117 # define VSI_ISCHR(x) S_ISCHR(x)
118 # define VSI_ISBLK(x) S_ISBLK(x)
119 #endif
120 
121 /* ==================================================================== */
122 /* 64bit stdio file access functions. If we have a big size */
123 /* defined, then provide protypes for the large file API, */
124 /* otherwise redefine to use the regular api. */
125 /* ==================================================================== */
126 typedef GUIntBig vsi_l_offset;
127 
128 /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
129 #ifdef DEBUG
130 #define VSIL_STRICT_ENFORCE
131 #endif
132 
133 #ifdef VSIL_STRICT_ENFORCE
134 typedef struct _VSILFILE VSILFILE;
135 #else
136 typedef FILE VSILFILE;
137 #endif
138 
139 VSILFILE CPL_DLL * VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
140 int CPL_DLL VSIFCloseL( VSILFILE * );
141 int CPL_DLL VSIFSeekL( VSILFILE *, vsi_l_offset, int );
142 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * );
143 void CPL_DLL VSIRewindL( VSILFILE * );
144 size_t CPL_DLL VSIFReadL( void *, size_t, size_t, VSILFILE * );
145 int CPL_DLL VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * );
146 size_t CPL_DLL VSIFWriteL( const void *, size_t, size_t, VSILFILE * );
147 int CPL_DLL VSIFEofL( VSILFILE * );
148 int CPL_DLL VSIFTruncateL( VSILFILE *, vsi_l_offset );
149 int CPL_DLL VSIFFlushL( VSILFILE * );
150 int CPL_DLL VSIFPrintfL( VSILFILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
151 int CPL_DLL VSIFPutcL( int, VSILFILE * );
152 
153 int CPL_DLL VSIIngestFile( VSILFILE* fp,
154  const char* pszFilename,
155  GByte** ppabyRet,
156  vsi_l_offset* pnSize,
157  GIntBig nMaxSize );
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 * );
166 
167 #define VSI_STAT_EXISTS_FLAG 0x1
168 #define VSI_STAT_NATURE_FLAG 0x2
169 #define VSI_STAT_SIZE_FLAG 0x4
170 
171 int CPL_DLL VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags );
172 
173 int CPL_DLL VSIIsCaseSensitiveFS( const char * pszFilename );
174 
175 void CPL_DLL *VSIFGetNativeFileDescriptorL( VSILFILE* );
176 
177 /* ==================================================================== */
178 /* Memory allocation */
179 /* ==================================================================== */
180 
181 void CPL_DLL *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
182 void CPL_DLL *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
183 void CPL_DLL VSIFree( void * );
184 void CPL_DLL *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
185 char CPL_DLL *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
186 
194 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
195 
203 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
204 
205 
206 /* ==================================================================== */
207 /* Other... */
208 /* ==================================================================== */
209 
210 #define CPLReadDir VSIReadDir
211 char CPL_DLL **VSIReadDir( const char * );
212 char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
213 int CPL_DLL VSIMkdir( const char * pathname, long mode );
214 int CPL_DLL VSIRmdir( const char * pathname );
215 int CPL_DLL VSIUnlink( const char * pathname );
216 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
217 char CPL_DLL *VSIStrerror( int );
218 
219 /* ==================================================================== */
220 /* Install special file access handlers. */
221 /* ==================================================================== */
222 void CPL_DLL VSIInstallMemFileHandler(void);
223 void CPL_DLL VSIInstallLargeFileHandler(void);
224 void CPL_DLL VSIInstallSubFileHandler(void);
225 void VSIInstallCurlFileHandler(void);
227 void VSIInstallGZipFileHandler(void); /* No reason to export that */
228 void VSIInstallZipFileHandler(void); /* No reason to export that */
229 void VSIInstallStdinHandler(void); /* No reason to export that */
230 void VSIInstallStdoutHandler(void); /* No reason to export that */
231 void CPL_DLL VSIInstallSparseFileHandler(void);
232 void VSIInstallTarFileHandler(void); /* No reason to export that */
233 void CPL_DLL VSICleanupFileManager(void);
234 
235 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
236  GByte *pabyData,
237  vsi_l_offset nDataLength,
238  int bTakeOwnership );
239 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
240  vsi_l_offset *pnDataLength,
241  int bUnlinkAndSeize );
242 
243 /* ==================================================================== */
244 /* Time quering. */
245 /* ==================================================================== */
246 
247 unsigned long CPL_DLL VSITime( unsigned long * );
248 const char CPL_DLL *VSICTime( unsigned long );
249 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
250  struct tm *poBrokenTime );
251 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
252  struct tm *poBrokenTime );
253 
254 /* -------------------------------------------------------------------- */
255 /* the following can be turned on for detailed logging of */
256 /* almost all IO calls. */
257 /* -------------------------------------------------------------------- */
258 #ifdef VSI_DEBUG
259 
260 #ifndef DEBUG
261 # define DEBUG
262 #endif
263 
264 #include "cpl_error.h"
265 
266 #define VSIDebug4(f,a1,a2,a3,a4) CPLDebug( "VSI", f, a1, a2, a3, a4 );
267 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
268 #define VSIDebug2( f, a1, a2 ) CPLDebug( "VSI", f, a1, a2 );
269 #define VSIDebug1( f, a1 ) CPLDebug( "VSI", f, a1 );
270 #else
271 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
272 #define VSIDebug3( f, a1, a2, a3 ) {}
273 #define VSIDebug2( f, a1, a2 ) {}
274 #define VSIDebug1( f, a1 ) {}
275 #endif
276 
277 CPL_C_END
278 
279 #endif /* ndef CPL_VSI_H_INCLUDED */
int VSIMkdir(const char *pathname, long mode)
Create a directory.
Definition: cpl_vsil.cpp:262
char ** VSIReadDir(const char *)
Read names in a directory.
Definition: cpl_vsil.cpp:63
int VSIRename(const char *oldpath, const char *newpath)
Rename a file.
Definition: cpl_vsil.cpp:321
int VSIIngestFile(VSILFILE *fp, const char *pszFilename, GByte **ppabyRet, vsi_l_offset *pnSize, GIntBig nMaxSize)
Ingest a file into memory.
Definition: cpl_vsil.cpp:873
void * VSIFGetNativeFileDescriptorL(VSILFILE *)
Returns the "native" file descriptor for the virtual handle.
Definition: cpl_vsil.cpp:1030
Core portability definitions for CPL.
size_t VSIFReadL(void *, size_t, size_t, VSILFILE *)
Read bytes from file.
Definition: cpl_vsil.cpp:669
void * VSIMalloc3(size_t nSize1, size_t nSize2, size_t nSize3) CPL_WARN_UNUSED_RESULT
VSIMalloc3 allocates (nSize1 * nSize2 * nSize3) bytes.
Definition: cpl_vsisimple.cpp:821
int VSIStatL(const char *, VSIStatBufL *)
Get filesystem object info.
Definition: cpl_vsil.cpp:383
void VSIInstallStdoutHandler(void)
Install /vsistdout/ file system handler.
Definition: cpl_vsil_stdout.cpp:378
void VSIInstallSubFileHandler(void)
Install /vsisubfile/ virtual file handler.
Definition: cpl_vsil_subfile.cpp:458
void VSIInstallCurlStreamingFileHandler(void)
Install /vsicurl_streaming/ HTTP/FTP file system handler (requires libcurl)
Definition: cpl_vsil_curl_streaming.cpp:1461
VSILFILE * VSIFOpenL(const char *, const char *) CPL_WARN_UNUSED_RESULT
Open file.
Definition: cpl_vsil.cpp:504
void VSIInstallStdinHandler(void)
Install /vsistdin/ file system handler.
Definition: cpl_vsil_stdin.cpp:389
int VSIFTruncateL(VSILFILE *, vsi_l_offset)
Truncate/expand the file to the specified size.
Definition: cpl_vsil.cpp:794
int VSIFFlushL(VSILFILE *)
Flush pending writes to disk.
Definition: cpl_vsil.cpp:637
VSILFILE * VSIFileFromMemBuffer(const char *pszFilename, GByte *pabyData, vsi_l_offset nDataLength, int bTakeOwnership)
Create memory "file" from a buffer.
Definition: cpl_vsi_mem.cpp:825
void VSIInstallTarFileHandler(void)
Install /vsitar/ file system handler.
Definition: cpl_vsil_tar.cpp:334
void VSIInstallZipFileHandler(void)
Install ZIP file system handler.
Definition: cpl_vsil_gzip.cpp:2348
int VSIIsCaseSensitiveFS(const char *pszFilename)
Returns if the filenames of the filesystem are case sensitive.
Definition: cpl_vsil.cpp:466
void * VSIMalloc2(size_t nSize1, size_t nSize2) CPL_WARN_UNUSED_RESULT
VSIMalloc2 allocates (nSize1 * nSize2) bytes.
Definition: cpl_vsisimple.cpp:789
int VSIFPrintfL(VSILFILE *, const char *,...)
Formatted write to file.
Definition: cpl_vsil.cpp:820
CPL error handling services.
void VSIInstallSparseFileHandler(void)
Install /vsisparse/ virtual file handler.
Definition: cpl_vsil_sparsefile.cpp:568
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:705
int VSIStatExL(const char *pszFilename, VSIStatBufL *psStatBuf, int nFlags)
Get filesystem object info.
Definition: cpl_vsil.cpp:420
void VSIInstallGZipFileHandler(void)
Install GZip file system handler.
Definition: cpl_vsil_gzip.cpp:1559
int VSIFEofL(VSILFILE *)
Test for end of file.
Definition: cpl_vsil.cpp:767
vsi_l_offset VSIFTellL(VSILFILE *)
Tell current file offset.
Definition: cpl_vsil.cpp:599
int VSIFSeekL(VSILFILE *, vsi_l_offset, int)
Seek to requested offset.
Definition: cpl_vsil.cpp:571
int VSIRmdir(const char *pathname)
Delete a directory.
Definition: cpl_vsil.cpp:350
void VSIInstallCurlFileHandler(void)
Install /vsicurl/ HTTP/FTP file system handler (requires libcurl)
Definition: cpl_vsil_curl.cpp:2673
int VSIUnlink(const char *pathname)
Delete a file.
Definition: cpl_vsil.cpp:290
int VSIFCloseL(VSILFILE *)
Close file.
Definition: cpl_vsil.cpp:536
void VSIInstallMemFileHandler(void)
Install "memory" file system handler.
Definition: cpl_vsi_mem.cpp:795
GByte * VSIGetMemFileBuffer(const char *pszFilename, vsi_l_offset *pnDataLength, int bUnlinkAndSeize)
Fetch buffer underlying memory file.
Definition: cpl_vsi_mem.cpp:881
size_t VSIFWriteL(const void *, size_t, size_t, VSILFILE *)
Write bytes to file.
Definition: cpl_vsil.cpp:738
char ** VSIReadDirRecursive(const char *pszPath)
Read names in a directory recursively.
Definition: cpl_vsil.cpp:106

Generated for GDAL by doxygen 1.8.11.