Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

cpl_vsisimple.cpp

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

Generated at Tue Jan 16 12:43:36 2001 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000