cpl_vsi.h

Go to the documentation of this file.
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_vsi.h
00024  *
00025  * Include file defining the Virtual System Interface (VSI) functions.  This
00026  * should normally be included by all translators using VSI functions for
00027  * accessing system services.  It is also used by the GDAL core, and can be
00028  * used by higher level applications which adhere to VSI use.
00029  *
00030  * Most VSI functions are direct analogs of Posix C library functions.
00031  * VSI exists to allow ``hooking'' these functions to provide application
00032  * specific checking, io redirection and so on. 
00033  * 
00034  * $Log: cpl_vsi.h,v $
00035  * Revision 1.26  2005/10/03 18:56:40  fwarmerdam
00036  * always define large file api - cygwin fix
00037  *
00038  * Revision 1.25  2005/09/15 18:32:35  fwarmerdam
00039  * added VSICleanupFileManager
00040  *
00041  * Revision 1.24  2005/09/12 16:53:33  fwarmerdam
00042  * fixed VSIGetMemFileBuffer declaration
00043  *
00044  * Revision 1.23  2005/09/12 16:50:37  fwarmerdam
00045  * added VSIMemFile buffer fetcher
00046  *
00047  * Revision 1.22  2005/09/11 18:31:41  fwarmerdam
00048  * ensure a distinct VSIStatL() exists on win32
00049  *
00050  * Revision 1.21  2005/09/11 18:01:28  fwarmerdam
00051  * preliminary implementatin of fully virtualized large file api
00052  *
00053  * Revision 1.20  2005/04/12 03:51:11  fwarmerdam
00054  * Fixed stat64 problem.
00055  *
00056  * Revision 1.19  2005/04/12 00:27:39  fwarmerdam
00057  * added macos large file support
00058  *
00059  * Revision 1.18  2003/09/10 19:44:36  warmerda
00060  * added VSIStrerrno()
00061  *
00062  * Revision 1.17  2003/09/08 08:11:40  dron
00063  * Added VSIGMTime() and VSILocalTime().
00064  *
00065  * Revision 1.16  2003/05/27 20:44:40  warmerda
00066  * added VSI io debugging macros
00067  *
00068  * Revision 1.15  2002/06/17 14:10:14  warmerda
00069  * no stat64 on Win32
00070  *
00071  * Revision 1.14  2002/06/17 14:00:16  warmerda
00072  * segregate VSIStatL() and VSIStatBufL.
00073  *
00074  * Revision 1.13  2002/06/15 02:13:13  aubin
00075  * remove debug test for 64bit compile
00076  *
00077  * Revision 1.12  2002/06/15 00:07:23  aubin
00078  * mods to enable 64bit file i/o
00079  *
00080  * Revision 1.11  2001/04/30 18:19:06  warmerda
00081  * avoid stat on macos_pre10
00082  *
00083  * Revision 1.10  2001/01/19 21:16:41  warmerda
00084  * expanded tabs
00085  *
00086  * Revision 1.9  2001/01/03 17:41:44  warmerda
00087  * added #define for VSIFFlushL
00088  *
00089  * Revision 1.8  2001/01/03 16:17:50  warmerda
00090  * added large file API
00091  *
00092  * Revision 1.7  2000/12/14 18:29:48  warmerda
00093  * added VSIMkdir
00094  *
00095  * Revision 1.6  2000/01/25 03:11:03  warmerda
00096  * added unlink and mkdir
00097  *
00098  * Revision 1.5  1999/05/23 02:43:57  warmerda
00099  * Added documentation block.
00100  *
00101  * Revision 1.4  1999/02/25 04:48:11  danmo
00102  * Added VSIStat() macros specific to _WIN32 (for MSVC++)
00103  *
00104  * Revision 1.3  1999/01/28 18:31:25  warmerda
00105  * Test on _WIN32 rather than WIN32.  It seems to be more reliably defined.
00106  *
00107  * Revision 1.2  1998/12/04 21:42:57  danmo
00108  * Added #ifndef WIN32 arounf #include <unistd.h>
00109  *
00110  * Revision 1.1  1998/12/03 18:26:02  warmerda
00111  * New
00112  *
00113  */
00114 
00115 #ifndef CPL_VSI_H_INCLUDED
00116 #define CPL_VSI_H_INCLUDED
00117 
00118 #include "cpl_port.h"
00138 /* -------------------------------------------------------------------- */
00139 /*      We need access to ``struct stat''.                              */
00140 /* -------------------------------------------------------------------- */
00141 #ifndef _WIN32
00142 #  include <unistd.h>
00143 #endif
00144 #if !defined(macos_pre10)
00145 #  include <sys/stat.h>
00146 #endif
00147 
00148 CPL_C_START
00149 
00150 /* ==================================================================== */
00151 /*      stdio file access functions.                                    */
00152 /* ==================================================================== */
00153 
00154 FILE CPL_DLL *  VSIFOpen( const char *, const char * );
00155 int CPL_DLL     VSIFClose( FILE * );
00156 int CPL_DLL     VSIFSeek( FILE *, long, int );
00157 long CPL_DLL    VSIFTell( FILE * );
00158 void CPL_DLL    VSIRewind( FILE * );
00159 void CPL_DLL    VSIFFlush( FILE * );
00160 
00161 size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
00162 size_t CPL_DLL  VSIFWrite( void *, size_t, size_t, FILE * );
00163 char CPL_DLL   *VSIFGets( char *, int, FILE * );
00164 int CPL_DLL     VSIFPuts( const char *, FILE * );
00165 int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
00166 
00167 int CPL_DLL     VSIFGetc( FILE * );
00168 int CPL_DLL     VSIFPutc( int, FILE * );
00169 int CPL_DLL     VSIUngetc( int, FILE * );
00170 int CPL_DLL     VSIFEof( FILE * );
00171 
00172 /* ==================================================================== */
00173 /*      VSIStat() related.                                              */
00174 /* ==================================================================== */
00175 
00176 typedef struct stat VSIStatBuf;
00177 int CPL_DLL VSIStat( const char *, VSIStatBuf * );
00178 
00179 #ifdef _WIN32
00180 #  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
00181 #  define VSI_ISREG(x)  ((x) & S_IFREG)
00182 #  define VSI_ISDIR(x)  ((x) & S_IFDIR)
00183 #  define VSI_ISCHR(x)  ((x) & S_IFCHR)
00184 #  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
00185 #else
00186 #  define VSI_ISLNK(x)  S_ISLNK(x)
00187 #  define VSI_ISREG(x)  S_ISREG(x)
00188 #  define VSI_ISDIR(x)  S_ISDIR(x)
00189 #  define VSI_ISCHR(x)  S_ISCHR(x)
00190 #  define VSI_ISBLK(x)  S_ISBLK(x)
00191 #endif
00192 
00193 /* ==================================================================== */
00194 /*      64bit stdio file access functions.  If we have a big size       */
00195 /*      defined, then provide protypes for the large file API,          */
00196 /*      otherwise redefine to use the regular api.                      */
00197 /* ==================================================================== */
00198 typedef GUIntBig vsi_l_offset;
00199 
00200 FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
00201 int CPL_DLL     VSIFCloseL( FILE * );
00202 int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
00203 vsi_l_offset CPL_DLL VSIFTellL( FILE * );
00204 void CPL_DLL    VSIRewindL( FILE * );
00205 size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
00206 size_t CPL_DLL  VSIFWriteL( void *, size_t, size_t, FILE * );
00207 int CPL_DLL     VSIFEofL( FILE * );
00208 int CPL_DLL    VSIFFlushL( FILE * );
00209 
00210 #if defined(VSI_STAT64_T)
00211 typedef struct VSI_STAT64_T VSIStatBufL;
00212 #else
00213 #define VSIStatBufL    VSIStatBuf
00214 #endif
00215 
00216 int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
00217 
00218 /* ==================================================================== */
00219 /*      Memory allocation                                               */
00220 /* ==================================================================== */
00221 
00222 void CPL_DLL   *VSICalloc( size_t, size_t );
00223 void CPL_DLL   *VSIMalloc( size_t );
00224 void CPL_DLL    VSIFree( void * );
00225 void CPL_DLL   *VSIRealloc( void *, size_t );
00226 char CPL_DLL   *VSIStrdup( const char * );
00227 
00228 /* ==================================================================== */
00229 /*      Other...                                                        */
00230 /* ==================================================================== */
00231 
00232 int CPL_DLL VSIMkdir( const char * pathname, long mode );
00233 int CPL_DLL VSIRmdir( const char * pathname );
00234 int CPL_DLL VSIUnlink( const char * pathname );
00235 char CPL_DLL *VSIStrerror( int );
00236 
00237 /* ==================================================================== */
00238 /*      Install special file access handlers.                           */
00239 /* ==================================================================== */
00240 void CPL_DLL VSIInstallMemFileHandler(void);
00241 void CPL_DLL VSIInstallLargeFileHandler(void);
00242 void CPL_DLL VSICleanupFileManager(void);
00243 
00244 FILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename, 
00245                                     GByte *pabyData, 
00246                                     vsi_l_offset nDataLength,
00247                                     int bTakeOwnership );
00248 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename, 
00249                                     vsi_l_offset *pnDataLength, 
00250                                     int bUnlinkAndSeize );
00251 
00252 /* ==================================================================== */
00253 /*      Time quering.                                                   */
00254 /* ==================================================================== */
00255 
00256 unsigned long CPL_DLL VSITime( unsigned long * );
00257 const char CPL_DLL *VSICTime( unsigned long );
00258 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
00259                               struct tm *poBrokenTime );
00260 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
00261                                  struct tm *poBrokenTime );
00262 
00263 /* -------------------------------------------------------------------- */
00264 /*      the following can be turned on for detailed logging of          */
00265 /*      almost all IO calls.                                            */
00266 /* -------------------------------------------------------------------- */
00267 #ifdef VSI_DEBUG
00268 
00269 #ifndef DEBUG
00270 #  define DEBUG
00271 #endif
00272 
00273 #include "cpl_error.h"
00274 
00275 #define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
00276 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
00277 #define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
00278 #define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
00279 #else
00280 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
00281 #define VSIDebug3( f, a1, a2, a3 ) {}
00282 #define VSIDebug2( f, a1, a2 )     {}
00283 #define VSIDebug1( f, a1 )         {}
00284 #endif
00285 
00286 CPL_C_END
00287 
00288 #endif /* ndef CPL_VSI_H_INCLUDED */

Generated on Sun Jul 2 22:18:26 2006 for GDAL by  doxygen 1.4.6