<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>cpl_vsisimple.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:28 2002 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>cpl_vsisimple.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> 00002 <font class="comment"> * Copyright (c) 1998, Frank Warmerdam</font> 00003 <font class="comment"> *</font> 00004 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font> 00005 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font> 00006 <font class="comment"> * to deal in the Software without restriction, including without limitation</font> 00007 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font> 00008 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font> 00009 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font> 00010 <font class="comment"> *</font> 00011 <font class="comment"> * The above copyright notice and this permission notice shall be included</font> 00012 <font class="comment"> * in all copies or substantial portions of the Software.</font> 00013 <font class="comment"> *</font> 00014 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font> 00015 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font> 00016 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font> 00017 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font> 00018 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font> 00019 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font> 00020 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font> 00021 <font class="comment"> ******************************************************************************</font> 00022 <font class="comment"> *</font> 00023 <font class="comment"> * cpl_vsisimple.cpp</font> 00024 <font class="comment"> *</font> 00025 <font class="comment"> * This is a simple implementation (direct to Posix) of the Virtual System</font> 00026 <font class="comment"> * Interface (VSI). See gdal_vsi.h.</font> 00027 <font class="comment"> *</font> 00028 <font class="comment"> * TODO:</font> 00029 <font class="comment"> * - add some assertions to ensure that arguments are widely legal. For</font> 00030 <font class="comment"> * instance validation of access strings to fopen().</font> 00031 <font class="comment"> * </font> 00032 <font class="comment"> * $Log: cpl_vsisimple_cpp-source.html,v $ 00032 <font class="comment"> * Revision 1.10 2002/04/16 13:11:48 warmerda 00032 <font class="comment"> * updated 00032 <font class="comment"> *</font> 00033 <font class="comment"> * Revision 1.10 2001/07/18 04:00:49 warmerda</font> 00034 <font class="comment"> * added CPL_CVSID</font> 00035 <font class="comment"> *</font> 00036 <font class="comment"> * Revision 1.9 2001/04/30 18:19:06 warmerda</font> 00037 <font class="comment"> * avoid stat on macos_pre10</font> 00038 <font class="comment"> *</font> 00039 <font class="comment"> * Revision 1.8 2001/01/19 21:16:41 warmerda</font> 00040 <font class="comment"> * expanded tabs</font> 00041 <font class="comment"> *</font> 00042 <font class="comment"> * Revision 1.7 2001/01/03 05:33:17 warmerda</font> 00043 <font class="comment"> * added VSIFlush</font> 00044 <font class="comment"> *</font> 00045 <font class="comment"> * Revision 1.6 2000/12/14 18:29:48 warmerda</font> 00046 <font class="comment"> * added VSIMkdir</font> 00047 <font class="comment"> *</font> 00048 <font class="comment"> * Revision 1.5 2000/01/26 19:06:29 warmerda</font> 00049 <font class="comment"> * fix up mkdir/unlink for windows</font> 00050 <font class="comment"> *</font> 00051 <font class="comment"> * Revision 1.4 2000/01/25 03:11:03 warmerda</font> 00052 <font class="comment"> * added unlink and mkdir</font> 00053 <font class="comment"> *</font> 00054 <font class="comment"> * Revision 1.3 1998/12/14 04:50:33 warmerda</font> 00055 <font class="comment"> * Avoid C++ comments so it will be C compilable as well.</font> 00056 <font class="comment"> *</font> 00057 <font class="comment"> * Revision 1.2 1998/12/04 21:42:57 danmo</font> 00058 <font class="comment"> * Added #ifndef WIN32 arounf #include <unistd.h></font> 00059 <font class="comment"> *</font> 00060 <font class="comment"> * Revision 1.1 1998/12/03 18:26:03 warmerda</font> 00061 <font class="comment"> * New</font> 00062 <font class="comment"> *</font> 00063 <font class="comment"> */</font> 00064 00065 <font class="preprocessor">#include "<a class="code" href="cpl_vsi_h.html">cpl_vsi.h</a>"</font> 00066 00067 CPL_CVSID(<font class="stringliteral">"$Id: cpl_vsisimple_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $"</font>); 00068 00069 <font class="comment">/* for stat() */</font> 00070 00071 <font class="preprocessor">#ifndef WIN32</font> 00072 <font class="preprocessor"></font><font class="preprocessor"># include <unistd.h></font> 00073 <font class="preprocessor">#else</font> 00074 <font class="preprocessor"></font><font class="preprocessor"># include <io.h></font> 00075 <font class="preprocessor"># include <fcntl.h></font> 00076 <font class="preprocessor"># include <direct.h></font> 00077 <font class="preprocessor">#endif</font> 00078 <font class="preprocessor"></font><font class="preprocessor">#include <sys/stat.h></font> 00079 00080 <font class="comment">/************************************************************************/</font> 00081 <font class="comment">/* VSIFOpen() */</font> 00082 <font class="comment">/************************************************************************/</font> 00083 00084 FILE *VSIFOpen( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszAccess )<font class="keyword"></font> 00085 <font class="keyword"></font> 00086 <font class="keyword"></font>{ 00087 <font class="keywordflow">return</font>( fopen( (<font class="keywordtype">char</font> *) pszFilename, (<font class="keywordtype">char</font> *) pszAccess ) ); 00088 } 00089 00090 <font class="comment">/************************************************************************/</font> 00091 <font class="comment">/* VSIFClose() */</font> 00092 <font class="comment">/************************************************************************/</font> 00093 00094 <font class="keywordtype">int</font> VSIFClose( FILE * fp )<font class="keyword"></font> 00095 <font class="keyword"></font> 00096 <font class="keyword"></font>{ 00097 <font class="keywordflow">return</font>( fclose(fp) ); 00098 } 00099 00100 <font class="comment">/************************************************************************/</font> 00101 <font class="comment">/* VSIFSeek() */</font> 00102 <font class="comment">/************************************************************************/</font> 00103 00104 <font class="keywordtype">int</font> VSIFSeek( FILE * fp, <font class="keywordtype">long</font> nOffset, <font class="keywordtype">int</font> nWhence )<font class="keyword"></font> 00105 <font class="keyword"></font> 00106 <font class="keyword"></font>{ 00107 <font class="keywordflow">return</font>( fseek( fp, nOffset, nWhence ) ); 00108 } 00109 00110 <font class="comment">/************************************************************************/</font> 00111 <font class="comment">/* VSIFTell() */</font> 00112 <font class="comment">/************************************************************************/</font> 00113 00114 <font class="keywordtype">long</font> VSIFTell( FILE * fp )<font class="keyword"></font> 00115 <font class="keyword"></font> 00116 <font class="keyword"></font>{ 00117 <font class="keywordflow">return</font>( ftell( fp ) ); 00118 } 00119 00120 <font class="comment">/************************************************************************/</font> 00121 <font class="comment">/* VSIRewind() */</font> 00122 <font class="comment">/************************************************************************/</font> 00123 00124 <font class="keywordtype">void</font> VSIRewind( FILE * fp )<font class="keyword"></font> 00125 <font class="keyword"></font> 00126 <font class="keyword"></font>{ 00127 rewind( fp ); 00128 } 00129 00130 <font class="comment">/************************************************************************/</font> 00131 <font class="comment">/* VSIFRead() */</font> 00132 <font class="comment">/************************************************************************/</font> 00133 00134 size_t VSIFRead( <font class="keywordtype">void</font> * pBuffer, size_t nSize, size_t nCount, FILE * fp )<font class="keyword"></font> 00135 <font class="keyword"></font> 00136 <font class="keyword"></font>{ 00137 <font class="keywordflow">return</font>( fread( pBuffer, nSize, nCount, fp ) ); 00138 } 00139 00140 <font class="comment">/************************************************************************/</font> 00141 <font class="comment">/* VSIFWrite() */</font> 00142 <font class="comment">/************************************************************************/</font> 00143 00144 size_t VSIFWrite( <font class="keywordtype">void</font> * pBuffer, size_t nSize, size_t nCount, FILE * fp )<font class="keyword"></font> 00145 <font class="keyword"></font> 00146 <font class="keyword"></font>{ 00147 <font class="keywordflow">return</font>( fwrite( pBuffer, nSize, nCount, fp ) ); 00148 } 00149 00150 <font class="comment">/************************************************************************/</font> 00151 <font class="comment">/* VSIFFlush() */</font> 00152 <font class="comment">/************************************************************************/</font> 00153 00154 <font class="keywordtype">void</font> VSIFFlush( FILE * fp )<font class="keyword"></font> 00155 <font class="keyword"></font> 00156 <font class="keyword"></font>{ 00157 fflush( fp ); 00158 } 00159 00160 <font class="comment">/************************************************************************/</font> 00161 <font class="comment">/* VSIFGets() */</font> 00162 <font class="comment">/************************************************************************/</font> 00163 00164 <font class="keywordtype">char</font> *VSIFGets( <font class="keywordtype">char</font> *pszBuffer, <font class="keywordtype">int</font> nBufferSize, FILE * fp )<font class="keyword"></font> 00165 <font class="keyword"></font> 00166 <font class="keyword"></font>{ 00167 <font class="keywordflow">return</font>( fgets( pszBuffer, nBufferSize, fp ) ); 00168 } 00169 00170 <font class="comment">/************************************************************************/</font> 00171 <font class="comment">/* VSIFGetc() */</font> 00172 <font class="comment">/************************************************************************/</font> 00173 00174 <font class="keywordtype">int</font> VSIFGetc( FILE * fp )<font class="keyword"></font> 00175 <font class="keyword"></font> 00176 <font class="keyword"></font>{ 00177 <font class="keywordflow">return</font>( fgetc( fp ) ); 00178 } 00179 00180 <font class="comment">/************************************************************************/</font> 00181 <font class="comment">/* VSIUngetc() */</font> 00182 <font class="comment">/************************************************************************/</font> 00183 00184 <font class="keywordtype">int</font> VSIUngetc( <font class="keywordtype">int</font> c, FILE * fp )<font class="keyword"></font> 00185 <font class="keyword"></font> 00186 <font class="keyword"></font>{ 00187 <font class="keywordflow">return</font>( ungetc( c, fp ) ); 00188 } 00189 00190 <font class="comment">/************************************************************************/</font> 00191 <font class="comment">/* VSIFPrintf() */</font> 00192 <font class="comment">/* */</font> 00193 <font class="comment">/* This is a little more complicated than just calling */</font> 00194 <font class="comment">/* fprintf() because of the variable arguments. Instead we */</font> 00195 <font class="comment">/* have to use vfprintf(). */</font> 00196 <font class="comment">/************************************************************************/</font> 00197 00198 <font class="keywordtype">int</font> VSIFPrintf( FILE * fp, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFormat, ... )<font class="keyword"></font> 00199 <font class="keyword"></font> 00200 <font class="keyword"></font>{ 00201 va_list args; 00202 <font class="keywordtype">int</font> nReturn; 00203 00204 va_start( args, pszFormat ); 00205 nReturn = vfprintf( fp, pszFormat, args ); 00206 va_end( args ); 00207 00208 <font class="keywordflow">return</font>( nReturn ); 00209 } 00210 00211 <font class="comment">/************************************************************************/</font> 00212 <font class="comment">/* VSIFEof() */</font> 00213 <font class="comment">/************************************************************************/</font> 00214 00215 <font class="keywordtype">int</font> VSIFEof( FILE * fp )<font class="keyword"></font> 00216 <font class="keyword"></font> 00217 <font class="keyword"></font>{ 00218 <font class="keywordflow">return</font>( feof( fp ) ); 00219 } 00220 00221 <font class="comment">/************************************************************************/</font> 00222 <font class="comment">/* VSIFPuts() */</font> 00223 <font class="comment">/************************************************************************/</font> 00224 00225 <font class="keywordtype">int</font> VSIFPuts( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszString, FILE * fp )<font class="keyword"></font> 00226 <font class="keyword"></font> 00227 <font class="keyword"></font>{ 00228 <font class="keywordflow">return</font> fputs( pszString, fp ); 00229 } 00230 00231 <font class="comment">/************************************************************************/</font> 00232 <font class="comment">/* VSIFPutc() */</font> 00233 <font class="comment">/************************************************************************/</font> 00234 00235 <font class="keywordtype">int</font> VSIFPutc( <font class="keywordtype">int</font> nChar, FILE * fp )<font class="keyword"></font> 00236 <font class="keyword"></font> 00237 <font class="keyword"></font>{ 00238 <font class="keywordflow">return</font>( fputc( nChar, fp ) ); 00239 } 00240 00241 <font class="comment">/************************************************************************/</font> 00242 <font class="comment">/* VSICalloc() */</font> 00243 <font class="comment">/************************************************************************/</font> 00244 00245 <font class="keywordtype">void</font> *VSICalloc( size_t nCount, size_t nSize )<font class="keyword"></font> 00246 <font class="keyword"></font> 00247 <font class="keyword"></font>{ 00248 <font class="keywordflow">return</font>( calloc( nCount, nSize ) ); 00249 } 00250 00251 <font class="comment">/************************************************************************/</font> 00252 <font class="comment">/* VSIMalloc() */</font> 00253 <font class="comment">/************************************************************************/</font> 00254 00255 <font class="keywordtype">void</font> *VSIMalloc( size_t nSize )<font class="keyword"></font> 00256 <font class="keyword"></font> 00257 <font class="keyword"></font>{ 00258 <font class="keywordflow">return</font>( malloc( nSize ) ); 00259 } 00260 00261 <font class="comment">/************************************************************************/</font> 00262 <font class="comment">/* VSIRealloc() */</font> 00263 <font class="comment">/************************************************************************/</font> 00264 00265 <font class="keywordtype">void</font> * VSIRealloc( <font class="keywordtype">void</font> * pData, size_t nNewSize )<font class="keyword"></font> 00266 <font class="keyword"></font> 00267 <font class="keyword"></font>{ 00268 <font class="keywordflow">return</font>( realloc( pData, nNewSize ) ); 00269 } 00270 00271 <font class="comment">/************************************************************************/</font> 00272 <font class="comment">/* VSIFree() */</font> 00273 <font class="comment">/************************************************************************/</font> 00274 00275 <font class="keywordtype">void</font> VSIFree( <font class="keywordtype">void</font> * pData )<font class="keyword"></font> 00276 <font class="keyword"></font> 00277 <font class="keyword"></font>{ 00278 <font class="keywordflow">if</font>( pData != NULL ) 00279 free( pData ); 00280 } 00281 00282 <font class="comment">/************************************************************************/</font> 00283 <font class="comment">/* VSIStrdup() */</font> 00284 <font class="comment">/************************************************************************/</font> 00285 00286 <font class="keywordtype">char</font> *VSIStrdup( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszString )<font class="keyword"></font> 00287 <font class="keyword"></font> 00288 <font class="keyword"></font>{ 00289 <font class="keywordflow">return</font>( strdup( pszString ) ); 00290 } 00291 00292 <font class="comment">/************************************************************************/</font> 00293 <font class="comment">/* VSIStat() */</font> 00294 <font class="comment">/************************************************************************/</font> 00295 00296 <font class="keywordtype">int</font> VSIStat( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename, VSIStatBuf * pStatBuf )<font class="keyword"></font> 00297 <font class="keyword"></font> 00298 <font class="keyword"></font>{ 00299 <font class="preprocessor">#if defined(macos_pre10)</font> 00300 <font class="preprocessor"></font> <font class="keywordflow">return</font> -1; 00301 <font class="preprocessor">#else</font> 00302 <font class="preprocessor"></font> <font class="keywordflow">return</font>( stat( pszFilename, pStatBuf ) ); 00303 <font class="preprocessor">#endif</font> 00304 <font class="preprocessor"></font>} 00305 00306 <font class="comment">/************************************************************************/</font> 00307 <font class="comment">/* VSIMkdir() */</font> 00308 <font class="comment">/************************************************************************/</font> 00309 00310 <font class="keywordtype">int</font> VSIMkdir( <font class="keyword">const</font> <font class="keywordtype">char</font> *pszPathname, <font class="keywordtype">long</font> mode )<font class="keyword"></font> 00311 <font class="keyword"></font> 00312 <font class="keyword"></font>{ 00313 <font class="preprocessor">#ifdef WIN32</font> 00314 <font class="preprocessor"></font> <font class="keywordflow">return</font> mkdir( pszPathname ); 00315 <font class="preprocessor">#elif defined(macos_pre10)</font> 00316 <font class="preprocessor"></font> <font class="keywordflow">return</font> -1; 00317 <font class="preprocessor">#else</font> 00318 <font class="preprocessor"></font> <font class="keywordflow">return</font> mkdir( pszPathname, mode ); 00319 <font class="preprocessor">#endif</font> 00320 <font class="preprocessor"></font>} 00321 00322 <font class="comment">/************************************************************************/</font> 00323 <font class="comment">/* VSIUnlink() */</font> 00324 <font class="comment">/*************************a***********************************************/</font> 00325 00326 <font class="keywordtype">int</font> VSIUnlink( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename )<font class="keyword"></font> 00327 <font class="keyword"></font> 00328 <font class="keyword"></font>{ 00329 <font class="keywordflow">return</font> unlink( pszFilename ); 00330 } 00331 00332 <font class="comment">/************************************************************************/</font> 00333 <font class="comment">/* VSIRmdir() */</font> 00334 <font class="comment">/************************************************************************/</font> 00335 00336 <font class="keywordtype">int</font> VSIRmdir( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename )<font class="keyword"></font> 00337 <font class="keyword"></font> 00338 <font class="keyword"></font>{ 00339 <font class="keywordflow">return</font> rmdir( pszFilename ); 00340 } 00341 00342 </div></pre><hr><address><small>Generated at Thu Mar 28 09:47:28 2002 for GDAL by <a href="http://www.stack.nl/~dimitri/doxygen/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2000</small></address> </body> </html>