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.10  2002/04/16 13:11:48  warmerda
00032  * updated
00032  *
00033  * Revision 1.10  2001/07/18 04:00:49  warmerda
00034  * added CPL_CVSID
00035  *
00036  * Revision 1.9  2001/04/30 18:19:06  warmerda
00037  * avoid stat on macos_pre10
00038  *
00039  * Revision 1.8  2001/01/19 21:16:41  warmerda
00040  * expanded tabs
00041  *
00042  * Revision 1.7  2001/01/03 05:33:17  warmerda
00043  * added VSIFlush
00044  *
00045  * Revision 1.6  2000/12/14 18:29:48  warmerda
00046  * added VSIMkdir
00047  *
00048  * Revision 1.5  2000/01/26 19:06:29  warmerda
00049  * fix up mkdir/unlink for windows
00050  *
00051  * Revision 1.4  2000/01/25 03:11:03  warmerda
00052  * added unlink and mkdir
00053  *
00054  * Revision 1.3  1998/12/14 04:50:33  warmerda
00055  * Avoid C++ comments so it will be C compilable as well.
00056  *
00057  * Revision 1.2  1998/12/04 21:42:57  danmo
00058  * Added #ifndef WIN32 arounf #include <unistd.h>
00059  *
00060  * Revision 1.1  1998/12/03 18:26:03  warmerda
00061  * New
00062  *
00063  */
00064 
00065 #include "cpl_vsi.h"
00066 
00067 CPL_CVSID("$Id: cpl_vsisimple_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $");
00068 
00069 /* for stat() */
00070 
00071 #ifndef WIN32
00072 #  include <unistd.h>
00073 #else
00074 #  include <io.h>
00075 #  include <fcntl.h>
00076 #  include <direct.h>
00077 #endif
00078 #include <sys/stat.h>
00079 
00080 /************************************************************************/
00081 /*                              VSIFOpen()                              */
00082 /************************************************************************/
00083 
00084 FILE *VSIFOpen( const char * pszFilename, const char * pszAccess )
00085 
00086 {
00087     return( fopen( (char *) pszFilename, (char *) pszAccess ) );
00088 }
00089 
00090 /************************************************************************/
00091 /*                             VSIFClose()                              */
00092 /************************************************************************/
00093 
00094 int VSIFClose( FILE * fp )
00095 
00096 {
00097     return( fclose(fp) );
00098 }
00099 
00100 /************************************************************************/
00101 /*                              VSIFSeek()                              */
00102 /************************************************************************/
00103 
00104 int VSIFSeek( FILE * fp, long nOffset, int nWhence )
00105 
00106 {
00107     return( fseek( fp, nOffset, nWhence ) );
00108 }
00109 
00110 /************************************************************************/
00111 /*                              VSIFTell()                              */
00112 /************************************************************************/
00113 
00114 long VSIFTell( FILE * fp )
00115 
00116 {
00117     return( ftell( fp ) );
00118 }
00119 
00120 /************************************************************************/
00121 /*                             VSIRewind()                              */
00122 /************************************************************************/
00123 
00124 void VSIRewind( FILE * fp )
00125 
00126 {
00127     rewind( fp );
00128 }
00129 
00130 /************************************************************************/
00131 /*                              VSIFRead()                              */
00132 /************************************************************************/
00133 
00134 size_t VSIFRead( void * pBuffer, size_t nSize, size_t nCount, FILE * fp )
00135 
00136 {
00137     return( fread( pBuffer, nSize, nCount, fp ) );
00138 }
00139 
00140 /************************************************************************/
00141 /*                             VSIFWrite()                              */
00142 /************************************************************************/
00143 
00144 size_t VSIFWrite( void * pBuffer, size_t nSize, size_t nCount, FILE * fp )
00145 
00146 {
00147     return( fwrite( pBuffer, nSize, nCount, fp ) );
00148 }
00149 
00150 /************************************************************************/
00151 /*                             VSIFFlush()                              */
00152 /************************************************************************/
00153 
00154 void VSIFFlush( FILE * fp )
00155 
00156 {
00157     fflush( fp );
00158 }
00159 
00160 /************************************************************************/
00161 /*                              VSIFGets()                              */
00162 /************************************************************************/
00163 
00164 char *VSIFGets( char *pszBuffer, int nBufferSize, FILE * fp )
00165 
00166 {
00167     return( fgets( pszBuffer, nBufferSize, fp ) );
00168 }
00169 
00170 /************************************************************************/
00171 /*                              VSIFGetc()                              */
00172 /************************************************************************/
00173 
00174 int VSIFGetc( FILE * fp )
00175 
00176 {
00177     return( fgetc( fp ) );
00178 }
00179 
00180 /************************************************************************/
00181 /*                             VSIUngetc()                              */
00182 /************************************************************************/
00183 
00184 int VSIUngetc( int c, FILE * fp )
00185 
00186 {
00187     return( ungetc( c, fp ) );
00188 }
00189 
00190 /************************************************************************/
00191 /*                             VSIFPrintf()                             */
00192 /*                                                                      */
00193 /*      This is a little more complicated than just calling             */
00194 /*      fprintf() because of the variable arguments.  Instead we        */
00195 /*      have to use vfprintf().                                         */
00196 /************************************************************************/
00197 
00198 int     VSIFPrintf( FILE * fp, const char * pszFormat, ... )
00199 
00200 {
00201     va_list     args;
00202     int         nReturn;
00203 
00204     va_start( args, pszFormat );
00205     nReturn = vfprintf( fp, pszFormat, args );
00206     va_end( args );
00207 
00208     return( nReturn );
00209 }
00210 
00211 /************************************************************************/
00212 /*                              VSIFEof()                               */
00213 /************************************************************************/
00214 
00215 int VSIFEof( FILE * fp )
00216 
00217 {
00218     return( feof( fp ) );
00219 }
00220 
00221 /************************************************************************/
00222 /*                              VSIFPuts()                              */
00223 /************************************************************************/
00224 
00225 int VSIFPuts( const char * pszString, FILE * fp )
00226 
00227 {
00228     return fputs( pszString, fp );
00229 }
00230 
00231 /************************************************************************/
00232 /*                              VSIFPutc()                              */
00233 /************************************************************************/
00234 
00235 int VSIFPutc( int nChar, FILE * fp )
00236 
00237 {
00238     return( fputc( nChar, fp ) );
00239 }
00240 
00241 /************************************************************************/
00242 /*                             VSICalloc()                              */
00243 /************************************************************************/
00244 
00245 void *VSICalloc( size_t nCount, size_t nSize )
00246 
00247 {
00248     return( calloc( nCount, nSize ) );
00249 }
00250 
00251 /************************************************************************/
00252 /*                             VSIMalloc()                              */
00253 /************************************************************************/
00254 
00255 void *VSIMalloc( size_t nSize )
00256 
00257 {
00258     return( malloc( nSize ) );
00259 }
00260 
00261 /************************************************************************/
00262 /*                             VSIRealloc()                             */
00263 /************************************************************************/
00264 
00265 void * VSIRealloc( void * pData, size_t nNewSize )
00266 
00267 {
00268     return( realloc( pData, nNewSize ) );
00269 }
00270 
00271 /************************************************************************/
00272 /*                              VSIFree()                               */
00273 /************************************************************************/
00274 
00275 void VSIFree( void * pData )
00276 
00277 {
00278     if( pData != NULL )
00279         free( pData );
00280 }
00281 
00282 /************************************************************************/
00283 /*                             VSIStrdup()                              */
00284 /************************************************************************/
00285 
00286 char *VSIStrdup( const char * pszString )
00287 
00288 {
00289     return( strdup( pszString ) );
00290 }
00291 
00292 /************************************************************************/
00293 /*                              VSIStat()                               */
00294 /************************************************************************/
00295 
00296 int VSIStat( const char * pszFilename, VSIStatBuf * pStatBuf )
00297 
00298 {
00299 #if defined(macos_pre10)
00300     return -1;
00301 #else
00302     return( stat( pszFilename, pStatBuf ) );
00303 #endif
00304 }
00305 
00306 /************************************************************************/
00307 /*                              VSIMkdir()                              */
00308 /************************************************************************/
00309 
00310 int VSIMkdir( const char *pszPathname, long mode )
00311 
00312 {
00313 #ifdef WIN32
00314     return mkdir( pszPathname );
00315 #elif defined(macos_pre10)
00316     return -1;
00317 #else
00318     return mkdir( pszPathname, mode );
00319 #endif
00320 }
00321 
00322 /************************************************************************/
00323 /*                             VSIUnlink()                              */
00324 /*************************a***********************************************/
00325 
00326 int VSIUnlink( const char * pszFilename )
00327 
00328 {
00329     return unlink( pszFilename );
00330 }
00331 
00332 /************************************************************************/
00333 /*                              VSIRmdir()                              */
00334 /************************************************************************/
00335 
00336 int VSIRmdir( const char * pszFilename )
00337 
00338 {
00339     return rmdir( pszFilename );
00340 }
00341 
00342 

Generated at Thu Mar 28 09:47:28 2002 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000