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

doxygen1.2.2 Dimitri van Heesch, © 1997-2000