OGR
cpl_vsi.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: cpl_vsi.h 24442 2012-05-18 15:47:54Z 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  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef CPL_VSI_H_INCLUDED
32 #define CPL_VSI_H_INCLUDED
33 
34 #include "cpl_port.h"
54 /* -------------------------------------------------------------------- */
55 /* We need access to ``struct stat''. */
56 /* -------------------------------------------------------------------- */
57 
58 /* Unix */
59 #if !defined(_WIN32) && !defined(_WIN32_WCE)
60 # include <unistd.h>
61 #endif
62 
63 /* Windows */
64 #if !defined(macos_pre10) && !defined(_WIN32_WCE)
65 # include <sys/stat.h>
66 #endif
67 
68 /* Windows CE */
69 #if defined(_WIN32_WCE)
70 # include <wce_stat.h>
71 #endif
72 
73 CPL_C_START
74 
75 /* ==================================================================== */
76 /* stdio file access functions. These may not support large */
77 /* files, and don't necessarily go through the virtualization */
78 /* API. */
79 /* ==================================================================== */
80 
81 FILE CPL_DLL * VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
82 int CPL_DLL VSIFClose( FILE * );
83 int CPL_DLL VSIFSeek( FILE *, long, int );
84 long CPL_DLL VSIFTell( FILE * );
85 void CPL_DLL VSIRewind( FILE * );
86 void CPL_DLL VSIFFlush( FILE * );
87 
88 size_t CPL_DLL VSIFRead( void *, size_t, size_t, FILE * );
89 size_t CPL_DLL VSIFWrite( const void *, size_t, size_t, FILE * );
90 char CPL_DLL *VSIFGets( char *, int, FILE * );
91 int CPL_DLL VSIFPuts( const char *, FILE * );
92 int CPL_DLL VSIFPrintf( FILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
93 
94 int CPL_DLL VSIFGetc( FILE * );
95 int CPL_DLL VSIFPutc( int, FILE * );
96 int CPL_DLL VSIUngetc( int, FILE * );
97 int CPL_DLL VSIFEof( FILE * );
98 
99 /* ==================================================================== */
100 /* VSIStat() related. */
101 /* ==================================================================== */
102 
103 typedef struct stat VSIStatBuf;
104 int CPL_DLL VSIStat( const char *, VSIStatBuf * );
105 
106 #ifdef _WIN32
107 # define VSI_ISLNK(x) ( 0 ) /* N/A on Windows */
108 # define VSI_ISREG(x) ((x) & S_IFREG)
109 # define VSI_ISDIR(x) ((x) & S_IFDIR)
110 # define VSI_ISCHR(x) ((x) & S_IFCHR)
111 # define VSI_ISBLK(x) ( 0 ) /* N/A on Windows */
112 #else
113 # define VSI_ISLNK(x) S_ISLNK(x)
114 # define VSI_ISREG(x) S_ISREG(x)
115 # define VSI_ISDIR(x) S_ISDIR(x)
116 # define VSI_ISCHR(x) S_ISCHR(x)
117 # define VSI_ISBLK(x) S_ISBLK(x)
118 #endif
119 
120 /* ==================================================================== */
121 /* 64bit stdio file access functions. If we have a big size */
122 /* defined, then provide protypes for the large file API, */
123 /* otherwise redefine to use the regular api. */
124 /* ==================================================================== */
125 typedef GUIntBig vsi_l_offset;
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 int CPL_DLL VSIFCloseL( VSILFILE * );
140 int CPL_DLL VSIFSeekL( VSILFILE *, vsi_l_offset, int );
141 vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * );
142 void CPL_DLL VSIRewindL( VSILFILE * );
143 size_t CPL_DLL VSIFReadL( void *, size_t, size_t, VSILFILE * );
144 int CPL_DLL VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * );
145 size_t CPL_DLL VSIFWriteL( const void *, size_t, size_t, VSILFILE * );
146 int CPL_DLL VSIFEofL( VSILFILE * );
147 int CPL_DLL VSIFTruncateL( VSILFILE *, vsi_l_offset );
148 int CPL_DLL VSIFFlushL( VSILFILE * );
149 int CPL_DLL VSIFPrintfL( VSILFILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
150 int CPL_DLL VSIFPutcL( int, VSILFILE * );
151 
152 #if defined(VSI_STAT64_T)
153 typedef struct VSI_STAT64_T VSIStatBufL;
154 #else
155 #define VSIStatBufL VSIStatBuf
156 #endif
157 
158 int CPL_DLL VSIStatL( const char *, VSIStatBufL * );
159 
160 #define VSI_STAT_EXISTS_FLAG 0x1
161 #define VSI_STAT_NATURE_FLAG 0x2
162 #define VSI_STAT_SIZE_FLAG 0x4
163 
164 int CPL_DLL VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags );
165 
166 int CPL_DLL VSIIsCaseSensitiveFS( const char * pszFilename );
167 
168 /* ==================================================================== */
169 /* Memory allocation */
170 /* ==================================================================== */
171 
172 void CPL_DLL *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
173 void CPL_DLL *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
174 void CPL_DLL VSIFree( void * );
175 void CPL_DLL *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
176 char CPL_DLL *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
177 
185 void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
186 
194 void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
195 
196 
197 /* ==================================================================== */
198 /* Other... */
199 /* ==================================================================== */
200 
201 #define CPLReadDir VSIReadDir
202 char CPL_DLL **VSIReadDir( const char * );
203 char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
204 int CPL_DLL VSIMkdir( const char * pathname, long mode );
205 int CPL_DLL VSIRmdir( const char * pathname );
206 int CPL_DLL VSIUnlink( const char * pathname );
207 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
208 char CPL_DLL *VSIStrerror( int );
209 
210 /* ==================================================================== */
211 /* Install special file access handlers. */
212 /* ==================================================================== */
213 void CPL_DLL VSIInstallMemFileHandler(void);
214 void CPL_DLL VSIInstallLargeFileHandler(void);
215 void CPL_DLL VSIInstallSubFileHandler(void);
216 void VSIInstallCurlFileHandler(void);
218 void VSIInstallGZipFileHandler(void); /* No reason to export that */
219 void VSIInstallZipFileHandler(void); /* No reason to export that */
220 void VSIInstallStdinHandler(void); /* No reason to export that */
221 void VSIInstallStdoutHandler(void); /* No reason to export that */
222 void CPL_DLL VSIInstallSparseFileHandler(void);
223 void VSIInstallTarFileHandler(void); /* No reason to export that */
224 void CPL_DLL VSICleanupFileManager(void);
225 
226 VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
227  GByte *pabyData,
228  vsi_l_offset nDataLength,
229  int bTakeOwnership );
230 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
231  vsi_l_offset *pnDataLength,
232  int bUnlinkAndSeize );
233 
234 /* ==================================================================== */
235 /* Time quering. */
236 /* ==================================================================== */
237 
238 unsigned long CPL_DLL VSITime( unsigned long * );
239 const char CPL_DLL *VSICTime( unsigned long );
240 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
241  struct tm *poBrokenTime );
242 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
243  struct tm *poBrokenTime );
244 
245 /* -------------------------------------------------------------------- */
246 /* the following can be turned on for detailed logging of */
247 /* almost all IO calls. */
248 /* -------------------------------------------------------------------- */
249 #ifdef VSI_DEBUG
250 
251 #ifndef DEBUG
252 # define DEBUG
253 #endif
254 
255 #include "cpl_error.h"
256 
257 #define VSIDebug4(f,a1,a2,a3,a4) CPLDebug( "VSI", f, a1, a2, a3, a4 );
258 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
259 #define VSIDebug2( f, a1, a2 ) CPLDebug( "VSI", f, a1, a2 );
260 #define VSIDebug1( f, a1 ) CPLDebug( "VSI", f, a1 );
261 #else
262 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
263 #define VSIDebug3( f, a1, a2, a3 ) {}
264 #define VSIDebug2( f, a1, a2 ) {}
265 #define VSIDebug1( f, a1 ) {}
266 #endif
267 
268 CPL_C_END
269 
270 #endif /* ndef CPL_VSI_H_INCLUDED */

Generated for GDAL by doxygen 1.8.1.2.