cpl_vsi.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_vsi.h,v 1.31 2006/03/27 15:24:41 fwarmerdam Exp $
00003  *
00004  * Project:  CPL - Common Portability Library
00005  * Author:   Frank Warmerdam, warmerdam@pobox.com
00006  * Purpose:  Include file defining Virtual File System (VSI) functions, a
00007  *           layer over POSIX file and other system services. 
00008  *
00009  ******************************************************************************
00010  * Copyright (c) 1998, Frank Warmerdam
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00028  * DEALINGS IN THE SOFTWARE.
00029  ******************************************************************************
00030  * 
00031  * $Log: cpl_vsi.h,v $
00032  * Revision 1.31  2006/03/27 15:24:41  fwarmerdam
00033  * buffer in FWrite is const
00034  *
00035  * Revision 1.30  2006/03/21 20:11:54  fwarmerdam
00036  * fixup headers a bit
00037  *
00038  * Revision 1.29  2006/02/19 21:54:34  mloskot
00039  * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers.
00040  *
00041  * Revision 1.28  2006/01/10 17:03:56  fwarmerdam
00042  * added VSI Rename support
00043  *
00044  * Revision 1.27  2005/10/07 00:26:27  fwarmerdam
00045  * add documentation
00046  *
00047  * Revision 1.26  2005/10/03 18:56:40  fwarmerdam
00048  * always define large file api - cygwin fix
00049  *
00050  * Revision 1.25  2005/09/15 18:32:35  fwarmerdam
00051  * added VSICleanupFileManager
00052  *
00053  * Revision 1.24  2005/09/12 16:53:33  fwarmerdam
00054  * fixed VSIGetMemFileBuffer declaration
00055  *
00056  * Revision 1.23  2005/09/12 16:50:37  fwarmerdam
00057  * added VSIMemFile buffer fetcher
00058  *
00059  * Revision 1.22  2005/09/11 18:31:41  fwarmerdam
00060  * ensure a distinct VSIStatL() exists on win32
00061  *
00062  * Revision 1.21  2005/09/11 18:01:28  fwarmerdam
00063  * preliminary implementatin of fully virtualized large file api
00064  *
00065  * Revision 1.20  2005/04/12 03:51:11  fwarmerdam
00066  * Fixed stat64 problem.
00067  *
00068  * Revision 1.19  2005/04/12 00:27:39  fwarmerdam
00069  * added macos large file support
00070  *
00071  * Revision 1.18  2003/09/10 19:44:36  warmerda
00072  * added VSIStrerrno()
00073  *
00074  * Revision 1.17  2003/09/08 08:11:40  dron
00075  * Added VSIGMTime() and VSILocalTime().
00076  *
00077  * Revision 1.16  2003/05/27 20:44:40  warmerda
00078  * added VSI io debugging macros
00079  */
00080 
00081 #ifndef CPL_VSI_H_INCLUDED
00082 #define CPL_VSI_H_INCLUDED
00083 
00084 #include "cpl_port.h"
00104 /* -------------------------------------------------------------------- */
00105 /*      We need access to ``struct stat''.                              */
00106 /* -------------------------------------------------------------------- */
00107 
00108 /* Unix */
00109 #if !defined(_WIN32) && !defined(_WIN32_WCE)
00110 #  include <unistd.h>
00111 #endif
00112 
00113 /* Windows */
00114 #if !defined(macos_pre10) && !defined(_WIN32_WCE)
00115 #  include <sys/stat.h>
00116 #endif
00117 
00118 /* Windows CE */
00119 #if defined(_WIN32_WCE)
00120 #  include <wce_stat.h>
00121 #endif
00122 
00123 CPL_C_START
00124 
00125 /* ==================================================================== */
00126 /*      stdio file access functions.  These may not support large       */
00127 /*      files, and don't necessarily go through the virtualization      */
00128 /*      API.                                                            */
00129 /* ==================================================================== */
00130 
00131 FILE CPL_DLL *  VSIFOpen( const char *, const char * );
00132 int CPL_DLL     VSIFClose( FILE * );
00133 int CPL_DLL     VSIFSeek( FILE *, long, int );
00134 long CPL_DLL    VSIFTell( FILE * );
00135 void CPL_DLL    VSIRewind( FILE * );
00136 void CPL_DLL    VSIFFlush( FILE * );
00137 
00138 size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
00139 size_t CPL_DLL  VSIFWrite( const void *, size_t, size_t, FILE * );
00140 char CPL_DLL   *VSIFGets( char *, int, FILE * );
00141 int CPL_DLL     VSIFPuts( const char *, FILE * );
00142 int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
00143 
00144 int CPL_DLL     VSIFGetc( FILE * );
00145 int CPL_DLL     VSIFPutc( int, FILE * );
00146 int CPL_DLL     VSIUngetc( int, FILE * );
00147 int CPL_DLL     VSIFEof( FILE * );
00148 
00149 /* ==================================================================== */
00150 /*      VSIStat() related.                                              */
00151 /* ==================================================================== */
00152 
00153 typedef struct stat VSIStatBuf;
00154 int CPL_DLL VSIStat( const char *, VSIStatBuf * );
00155 
00156 #ifdef _WIN32
00157 #  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
00158 #  define VSI_ISREG(x)  ((x) & S_IFREG)
00159 #  define VSI_ISDIR(x)  ((x) & S_IFDIR)
00160 #  define VSI_ISCHR(x)  ((x) & S_IFCHR)
00161 #  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
00162 #else
00163 #  define VSI_ISLNK(x)  S_ISLNK(x)
00164 #  define VSI_ISREG(x)  S_ISREG(x)
00165 #  define VSI_ISDIR(x)  S_ISDIR(x)
00166 #  define VSI_ISCHR(x)  S_ISCHR(x)
00167 #  define VSI_ISBLK(x)  S_ISBLK(x)
00168 #endif
00169 
00170 /* ==================================================================== */
00171 /*      64bit stdio file access functions.  If we have a big size       */
00172 /*      defined, then provide protypes for the large file API,          */
00173 /*      otherwise redefine to use the regular api.                      */
00174 /* ==================================================================== */
00175 typedef GUIntBig vsi_l_offset;
00176 
00177 FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
00178 int CPL_DLL     VSIFCloseL( FILE * );
00179 int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
00180 vsi_l_offset CPL_DLL VSIFTellL( FILE * );
00181 void CPL_DLL    VSIRewindL( FILE * );
00182 size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
00183 size_t CPL_DLL  VSIFWriteL( const void *, size_t, size_t, FILE * );
00184 int CPL_DLL     VSIFEofL( FILE * );
00185 int CPL_DLL    VSIFFlushL( FILE * );
00186 
00187 #if defined(VSI_STAT64_T)
00188 typedef struct VSI_STAT64_T VSIStatBufL;
00189 #else
00190 #define VSIStatBufL    VSIStatBuf
00191 #endif
00192 
00193 int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
00194 
00195 /* ==================================================================== */
00196 /*      Memory allocation                                               */
00197 /* ==================================================================== */
00198 
00199 void CPL_DLL   *VSICalloc( size_t, size_t );
00200 void CPL_DLL   *VSIMalloc( size_t );
00201 void CPL_DLL    VSIFree( void * );
00202 void CPL_DLL   *VSIRealloc( void *, size_t );
00203 char CPL_DLL   *VSIStrdup( const char * );
00204 
00205 /* ==================================================================== */
00206 /*      Other...                                                        */
00207 /* ==================================================================== */
00208 
00209 int CPL_DLL VSIMkdir( const char * pathname, long mode );
00210 int CPL_DLL VSIRmdir( const char * pathname );
00211 int CPL_DLL VSIUnlink( const char * pathname );
00212 int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
00213 char CPL_DLL *VSIStrerror( int );
00214 
00215 /* ==================================================================== */
00216 /*      Install special file access handlers.                           */
00217 /* ==================================================================== */
00218 void CPL_DLL VSIInstallMemFileHandler(void);
00219 void CPL_DLL VSIInstallLargeFileHandler(void);
00220 void CPL_DLL VSICleanupFileManager(void);
00221 
00222 FILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename, 
00223                                     GByte *pabyData, 
00224                                     vsi_l_offset nDataLength,
00225                                     int bTakeOwnership );
00226 GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename, 
00227                                     vsi_l_offset *pnDataLength, 
00228                                     int bUnlinkAndSeize );
00229 
00230 /* ==================================================================== */
00231 /*      Time quering.                                                   */
00232 /* ==================================================================== */
00233 
00234 unsigned long CPL_DLL VSITime( unsigned long * );
00235 const char CPL_DLL *VSICTime( unsigned long );
00236 struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
00237                               struct tm *poBrokenTime );
00238 struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
00239                                  struct tm *poBrokenTime );
00240 
00241 /* -------------------------------------------------------------------- */
00242 /*      the following can be turned on for detailed logging of          */
00243 /*      almost all IO calls.                                            */
00244 /* -------------------------------------------------------------------- */
00245 #ifdef VSI_DEBUG
00246 
00247 #ifndef DEBUG
00248 #  define DEBUG
00249 #endif
00250 
00251 #include "cpl_error.h"
00252 
00253 #define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
00254 #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
00255 #define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
00256 #define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
00257 #else
00258 #define VSIDebug4( f, a1, a2, a3, a4 ) {}
00259 #define VSIDebug3( f, a1, a2, a3 ) {}
00260 #define VSIDebug2( f, a1, a2 )     {}
00261 #define VSIDebug1( f, a1 )         {}
00262 #endif
00263 
00264 CPL_C_END
00265 
00266 #endif /* ndef CPL_VSI_H_INCLUDED */

Generated for GDAL by doxygen 1.5.1.