Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal / include / cpl_vsi.h @ 716

History | View | Annotate | Download (9.95 KB)

1
/******************************************************************************
2
 * Copyright (c) 1998, Frank Warmerdam
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * and/or sell copies of the Software, and to permit persons to whom the
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included
12
 * in all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
 * DEALINGS IN THE SOFTWARE.
21
 ******************************************************************************
22
 *
23
 * cpl_vsi.h
24
 *
25
 * Include file defining the Virtual System Interface (VSI) functions.  This
26
 * should normally be included by all translators using VSI functions for
27
 * accessing system services.  It is also used by the GDAL core, and can be
28
 * used by higher level applications which adhere to VSI use.
29
 *
30
 * Most VSI functions are direct analogs of Posix C library functions.
31
 * VSI exists to allow ``hooking'' these functions to provide application
32
 * specific checking, io redirection and so on. 
33
 * 
34
 * $Log$
35
 * Revision 1.1  2004-12-28 14:06:59  igbrotru
36
 * *** empty log message ***
37
 *
38
 * Revision 1.1  2004/10/28 12:08:47  igbrotru
39
 * *** empty log message ***
40
 *
41
 * Revision 1.1  2004/09/27 08:27:48  igbrotru
42
 * *** empty log message ***
43
 *
44
 * Revision 1.1  2004/09/08 12:39:04  igbrotru
45
 * *** empty log message ***
46
 *
47
 * Revision 1.18  2003/09/10 19:44:36  warmerda
48
 * added VSIStrerrno()
49
 *
50
 * Revision 1.17  2003/09/08 08:11:40  dron
51
 * Added VSIGMTime() and VSILocalTime().
52
 *
53
 * Revision 1.16  2003/05/27 20:44:40  warmerda
54
 * added VSI io debugging macros
55
 *
56
 * Revision 1.15  2002/06/17 14:10:14  warmerda
57
 * no stat64 on Win32
58
 *
59
 * Revision 1.14  2002/06/17 14:00:16  warmerda
60
 * segregate VSIStatL() and VSIStatBufL.
61
 *
62
 * Revision 1.13  2002/06/15 02:13:13  aubin
63
 * remove debug test for 64bit compile
64
 *
65
 * Revision 1.12  2002/06/15 00:07:23  aubin
66
 * mods to enable 64bit file i/o
67
 *
68
 * Revision 1.11  2001/04/30 18:19:06  warmerda
69
 * avoid stat on macos_pre10
70
 *
71
 * Revision 1.10  2001/01/19 21:16:41  warmerda
72
 * expanded tabs
73
 *
74
 * Revision 1.9  2001/01/03 17:41:44  warmerda
75
 * added #define for VSIFFlushL
76
 *
77
 * Revision 1.8  2001/01/03 16:17:50  warmerda
78
 * added large file API
79
 *
80
 * Revision 1.7  2000/12/14 18:29:48  warmerda
81
 * added VSIMkdir
82
 *
83
 * Revision 1.6  2000/01/25 03:11:03  warmerda
84
 * added unlink and mkdir
85
 *
86
 * Revision 1.5  1999/05/23 02:43:57  warmerda
87
 * Added documentation block.
88
 *
89
 * Revision 1.4  1999/02/25 04:48:11  danmo
90
 * Added VSIStat() macros specific to _WIN32 (for MSVC++)
91
 *
92
 * Revision 1.3  1999/01/28 18:31:25  warmerda
93
 * Test on _WIN32 rather than WIN32.  It seems to be more reliably defined.
94
 *
95
 * Revision 1.2  1998/12/04 21:42:57  danmo
96
 * Added #ifndef WIN32 arounf #include <unistd.h>
97
 *
98
 * Revision 1.1  1998/12/03 18:26:02  warmerda
99
 * New
100
 *
101
 */
102

    
103
#ifndef CPL_VSI_H_INCLUDED
104
#define CPL_VSI_H_INCLUDED
105

    
106
#include "cpl_port.h"
107
/**
108
 * \file cpl_vsi.h
109
 *
110
 * Standard C Covers
111
 *
112
 * The VSI functions are intended to be hookable aliases for Standard C
113
 * I/O, memory allocation and other system functions. They are intended
114
 * to allow virtualization of disk I/O so that non file data sources
115
 * can be made to appear as files, and so that additional error trapping
116
 * and reporting can be interested.  The memory access API is aliased
117
 * so that special application memory management services can be used.
118
 *
119
 * Is is intended that each of these functions retains exactly the same
120
 * calling pattern as the original Standard C functions they relate to.
121
 * This means we don't have to provide custom documentation, and also means
122
 * that the default implementation is very simple.
123
 */
124

    
125

    
126
/* -------------------------------------------------------------------- */
127
/*      We need access to ``struct stat''.                              */
128
/* -------------------------------------------------------------------- */
129
#ifndef _WIN32
130
#  include <unistd.h>
131
#endif
132
#if !defined(macos_pre10)
133
#  include <sys/stat.h>
134
#endif
135

    
136
CPL_C_START
137

    
138
/* ==================================================================== */
139
/*      stdio file access functions.                                    */
140
/* ==================================================================== */
141

    
142
FILE CPL_DLL *  VSIFOpen( const char *, const char * );
143
int CPL_DLL     VSIFClose( FILE * );
144
int CPL_DLL     VSIFSeek( FILE *, long, int );
145
long CPL_DLL    VSIFTell( FILE * );
146
void CPL_DLL    VSIRewind( FILE * );
147
void CPL_DLL    VSIFFlush( FILE * );
148

    
149
size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
150
size_t CPL_DLL  VSIFWrite( void *, size_t, size_t, FILE * );
151
char CPL_DLL   *VSIFGets( char *, int, FILE * );
152
int CPL_DLL     VSIFPuts( const char *, FILE * );
153
int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
154

    
155
int CPL_DLL     VSIFGetc( FILE * );
156
int CPL_DLL     VSIFPutc( int, FILE * );
157
int CPL_DLL     VSIUngetc( int, FILE * );
158
int CPL_DLL     VSIFEof( FILE * );
159

    
160
/* ==================================================================== */
161
/*      VSIStat() related.                                              */
162
/* ==================================================================== */
163

    
164
typedef struct stat VSIStatBuf;
165
int CPL_DLL VSIStat( const char *, VSIStatBuf * );
166

    
167
#ifdef _WIN32
168
#  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
169
#  define VSI_ISREG(x)  ((x) & S_IFREG)
170
#  define VSI_ISDIR(x)  ((x) & S_IFDIR)
171
#  define VSI_ISCHR(x)  ((x) & S_IFCHR)
172
#  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
173
#else
174
#  define VSI_ISLNK(x)  S_ISLNK(x)
175
#  define VSI_ISREG(x)  S_ISREG(x)
176
#  define VSI_ISDIR(x)  S_ISDIR(x)
177
#  define VSI_ISCHR(x)  S_ISCHR(x)
178
#  define VSI_ISBLK(x)  S_ISBLK(x)
179
#endif
180

    
181
/* ==================================================================== */
182
/*      64bit stdio file access functions.  If we have a big size       */
183
/*      defined, then provide protypes for the large file API,          */
184
/*      otherwise redefine to use the regular api.                      */
185
/* ==================================================================== */
186
#ifdef VSI_LARGE_API_SUPPORTED
187

    
188
typedef GUIntBig vsi_l_offset;
189

    
190
FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
191
int CPL_DLL     VSIFCloseL( FILE * );
192
int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
193
vsi_l_offset CPL_DLL VSIFTellL( FILE * );
194
void CPL_DLL    VSIRewindL( FILE * );
195
size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
196
size_t CPL_DLL  VSIFWriteL( void *, size_t, size_t, FILE * );
197
int CPL_DLL     VSIFEofL( FILE * );
198
void CPL_DLL    VSIFFlushL( FILE * );
199

    
200
#ifndef WIN32
201
typedef struct stat64 VSIStatBufL;
202
int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
203
#else
204
#define VSIStatBufL    VSIStatBuf
205
#define VSIStatL       VSIStat
206
#endif
207

    
208
#else
209

    
210
typedef long vsi_l_offset;
211

    
212
#define vsi_l_offset long
213

    
214
#define VSIFOpenL      VSIFOpen
215
#define VSIFCloseL     VSIFClose
216
#define VSIFSeekL      VSIFSeek
217
#define VSIFTellL      VSIFTell
218
#define VSIFRewindL    VSIFRewind
219
#define VSIFReadL      VSIFRead
220
#define VSIFWriteL     VSIFWrite
221
#define VSIFEofL       VSIFEof
222
#define VSIFFlushL     VSIFFlush
223
#define VSIStatBufL    VSIStatBuf
224
#define VSIStatL       VSIStat
225

    
226
#endif
227

    
228
/* ==================================================================== */
229
/*      Memory allocation                                               */
230
/* ==================================================================== */
231

    
232
void CPL_DLL   *VSICalloc( size_t, size_t );
233
void CPL_DLL   *VSIMalloc( size_t );
234
void CPL_DLL    VSIFree( void * );
235
void CPL_DLL   *VSIRealloc( void *, size_t );
236
char CPL_DLL   *VSIStrdup( const char * );
237

    
238
/* ==================================================================== */
239
/*      Other...                                                        */
240
/* ==================================================================== */
241

    
242
int CPL_DLL VSIMkdir( const char * pathname, long mode );
243
int CPL_DLL VSIRmdir( const char * pathname );
244
int CPL_DLL VSIUnlink( const char * pathname );
245
char CPL_DLL *VSIStrerror( int );
246

    
247
/* ==================================================================== */
248
/*      Time quering.                                                   */
249
/* ==================================================================== */
250

    
251
unsigned long CPL_DLL VSITime( unsigned long * );
252
const char CPL_DLL *VSICTime( unsigned long );
253
struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
254
                              struct tm *poBrokenTime );
255
struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
256
                                 struct tm *poBrokenTime );
257

    
258
/* -------------------------------------------------------------------- */
259
/*      the following can be turned on for detailed logging of          */
260
/*      almost all IO calls.                                            */
261
/* -------------------------------------------------------------------- */
262
#ifdef VSI_DEBUG
263

    
264
#ifndef DEBUG
265
#  define DEBUG
266
#endif
267

    
268
#include "cpl_error.h"
269

    
270
#define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
271
#define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
272
#define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
273
#define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
274
#else
275
#define VSIDebug4( f, a1, a2, a3, a4 ) {}
276
#define VSIDebug3( f, a1, a2, a3 ) {}
277
#define VSIDebug2( f, a1, a2 )     {}
278
#define VSIDebug1( f, a1 )         {}
279
#endif
280

    
281
CPL_C_END
282

    
283
#endif /* ndef CPL_VSI_H_INCLUDED */