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

Generated at Sat Dec 21 14:01:57 2002 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000