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

Generated at Thu Jul 5 09:16:12 2001 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000