Statistics
| Revision:

root / trunk / libraries / libjni-gdal / include / cpl_vsi.h @ 6503

History | View | Annotate | Download (10.1 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.2  2006-01-09 12:50:13  nacho
36
 * *** empty log message ***
37
 *
38
 * Revision 1.1  2005/07/27 08:22:55  igbrotru
39
 * *** empty log message ***
40
 *
41
 * Revision 1.1  2004/12/28 14:06:59  igbrotru
42
 * *** empty log message ***
43
 *
44
 * Revision 1.1  2004/10/28 12:08:47  igbrotru
45
 * *** empty log message ***
46
 *
47
 * Revision 1.1  2004/09/27 08:27:48  igbrotru
48
 * *** empty log message ***
49
 *
50
 * Revision 1.1  2004/09/08 12:39:04  igbrotru
51
 * *** empty log message ***
52
 *
53
 * Revision 1.18  2003/09/10 19:44:36  warmerda
54
 * added VSIStrerrno()
55
 *
56
 * Revision 1.17  2003/09/08 08:11:40  dron
57
 * Added VSIGMTime() and VSILocalTime().
58
 *
59
 * Revision 1.16  2003/05/27 20:44:40  warmerda
60
 * added VSI io debugging macros
61
 *
62
 * Revision 1.15  2002/06/17 14:10:14  warmerda
63
 * no stat64 on Win32
64
 *
65
 * Revision 1.14  2002/06/17 14:00:16  warmerda
66
 * segregate VSIStatL() and VSIStatBufL.
67
 *
68
 * Revision 1.13  2002/06/15 02:13:13  aubin
69
 * remove debug test for 64bit compile
70
 *
71
 * Revision 1.12  2002/06/15 00:07:23  aubin
72
 * mods to enable 64bit file i/o
73
 *
74
 * Revision 1.11  2001/04/30 18:19:06  warmerda
75
 * avoid stat on macos_pre10
76
 *
77
 * Revision 1.10  2001/01/19 21:16:41  warmerda
78
 * expanded tabs
79
 *
80
 * Revision 1.9  2001/01/03 17:41:44  warmerda
81
 * added #define for VSIFFlushL
82
 *
83
 * Revision 1.8  2001/01/03 16:17:50  warmerda
84
 * added large file API
85
 *
86
 * Revision 1.7  2000/12/14 18:29:48  warmerda
87
 * added VSIMkdir
88
 *
89
 * Revision 1.6  2000/01/25 03:11:03  warmerda
90
 * added unlink and mkdir
91
 *
92
 * Revision 1.5  1999/05/23 02:43:57  warmerda
93
 * Added documentation block.
94
 *
95
 * Revision 1.4  1999/02/25 04:48:11  danmo
96
 * Added VSIStat() macros specific to _WIN32 (for MSVC++)
97
 *
98
 * Revision 1.3  1999/01/28 18:31:25  warmerda
99
 * Test on _WIN32 rather than WIN32.  It seems to be more reliably defined.
100
 *
101
 * Revision 1.2  1998/12/04 21:42:57  danmo
102
 * Added #ifndef WIN32 arounf #include <unistd.h>
103
 *
104
 * Revision 1.1  1998/12/03 18:26:02  warmerda
105
 * New
106
 *
107
 */
108

    
109
#ifndef CPL_VSI_H_INCLUDED
110
#define CPL_VSI_H_INCLUDED
111

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

    
131

    
132
/* -------------------------------------------------------------------- */
133
/*      We need access to ``struct stat''.                              */
134
/* -------------------------------------------------------------------- */
135
#ifndef _WIN32
136
#  include <unistd.h>
137
#endif
138
#if !defined(macos_pre10)
139
#  include <sys/stat.h>
140
#endif
141

    
142
CPL_C_START
143

    
144
/* ==================================================================== */
145
/*      stdio file access functions.                                    */
146
/* ==================================================================== */
147

    
148
FILE CPL_DLL *  VSIFOpen( const char *, const char * );
149
int CPL_DLL     VSIFClose( FILE * );
150
int CPL_DLL     VSIFSeek( FILE *, long, int );
151
long CPL_DLL    VSIFTell( FILE * );
152
void CPL_DLL    VSIRewind( FILE * );
153
void CPL_DLL    VSIFFlush( FILE * );
154

    
155
size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
156
size_t CPL_DLL  VSIFWrite( void *, size_t, size_t, FILE * );
157
char CPL_DLL   *VSIFGets( char *, int, FILE * );
158
int CPL_DLL     VSIFPuts( const char *, FILE * );
159
int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
160

    
161
int CPL_DLL     VSIFGetc( FILE * );
162
int CPL_DLL     VSIFPutc( int, FILE * );
163
int CPL_DLL     VSIUngetc( int, FILE * );
164
int CPL_DLL     VSIFEof( FILE * );
165

    
166
/* ==================================================================== */
167
/*      VSIStat() related.                                              */
168
/* ==================================================================== */
169

    
170
typedef struct stat VSIStatBuf;
171
int CPL_DLL VSIStat( const char *, VSIStatBuf * );
172

    
173
#ifdef _WIN32
174
#  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
175
#  define VSI_ISREG(x)  ((x) & S_IFREG)
176
#  define VSI_ISDIR(x)  ((x) & S_IFDIR)
177
#  define VSI_ISCHR(x)  ((x) & S_IFCHR)
178
#  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
179
#else
180
#  define VSI_ISLNK(x)  S_ISLNK(x)
181
#  define VSI_ISREG(x)  S_ISREG(x)
182
#  define VSI_ISDIR(x)  S_ISDIR(x)
183
#  define VSI_ISCHR(x)  S_ISCHR(x)
184
#  define VSI_ISBLK(x)  S_ISBLK(x)
185
#endif
186

    
187
/* ==================================================================== */
188
/*      64bit stdio file access functions.  If we have a big size       */
189
/*      defined, then provide protypes for the large file API,          */
190
/*      otherwise redefine to use the regular api.                      */
191
/* ==================================================================== */
192
#ifdef VSI_LARGE_API_SUPPORTED
193

    
194
typedef GUIntBig vsi_l_offset;
195

    
196
FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
197
int CPL_DLL     VSIFCloseL( FILE * );
198
int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
199
vsi_l_offset CPL_DLL VSIFTellL( FILE * );
200
void CPL_DLL    VSIRewindL( FILE * );
201
size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
202
size_t CPL_DLL  VSIFWriteL( void *, size_t, size_t, FILE * );
203
int CPL_DLL     VSIFEofL( FILE * );
204
void CPL_DLL    VSIFFlushL( FILE * );
205

    
206
#ifndef WIN32
207
typedef struct stat64 VSIStatBufL;
208
int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
209
#else
210
#define VSIStatBufL    VSIStatBuf
211
#define VSIStatL       VSIStat
212
#endif
213

    
214
#else
215

    
216
typedef long vsi_l_offset;
217

    
218
#define vsi_l_offset long
219

    
220
#define VSIFOpenL      VSIFOpen
221
#define VSIFCloseL     VSIFClose
222
#define VSIFSeekL      VSIFSeek
223
#define VSIFTellL      VSIFTell
224
#define VSIFRewindL    VSIFRewind
225
#define VSIFReadL      VSIFRead
226
#define VSIFWriteL     VSIFWrite
227
#define VSIFEofL       VSIFEof
228
#define VSIFFlushL     VSIFFlush
229
#define VSIStatBufL    VSIStatBuf
230
#define VSIStatL       VSIStat
231

    
232
#endif
233

    
234
/* ==================================================================== */
235
/*      Memory allocation                                               */
236
/* ==================================================================== */
237

    
238
void CPL_DLL   *VSICalloc( size_t, size_t );
239
void CPL_DLL   *VSIMalloc( size_t );
240
void CPL_DLL    VSIFree( void * );
241
void CPL_DLL   *VSIRealloc( void *, size_t );
242
char CPL_DLL   *VSIStrdup( const char * );
243

    
244
/* ==================================================================== */
245
/*      Other...                                                        */
246
/* ==================================================================== */
247

    
248
int CPL_DLL VSIMkdir( const char * pathname, long mode );
249
int CPL_DLL VSIRmdir( const char * pathname );
250
int CPL_DLL VSIUnlink( const char * pathname );
251
char CPL_DLL *VSIStrerror( int );
252

    
253
/* ==================================================================== */
254
/*      Time quering.                                                   */
255
/* ==================================================================== */
256

    
257
unsigned long CPL_DLL VSITime( unsigned long * );
258
const char CPL_DLL *VSICTime( unsigned long );
259
struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
260
                              struct tm *poBrokenTime );
261
struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
262
                                 struct tm *poBrokenTime );
263

    
264
/* -------------------------------------------------------------------- */
265
/*      the following can be turned on for detailed logging of          */
266
/*      almost all IO calls.                                            */
267
/* -------------------------------------------------------------------- */
268
#ifdef VSI_DEBUG
269

    
270
#ifndef DEBUG
271
#  define DEBUG
272
#endif
273

    
274
#include "cpl_error.h"
275

    
276
#define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
277
#define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
278
#define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
279
#define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
280
#else
281
#define VSIDebug4( f, a1, a2, a3, a4 ) {}
282
#define VSIDebug3( f, a1, a2, a3 ) {}
283
#define VSIDebug2( f, a1, a2 )     {}
284
#define VSIDebug1( f, a1 )         {}
285
#endif
286

    
287
CPL_C_END
288

    
289
#endif /* ndef CPL_VSI_H_INCLUDED */