Statistics
| Revision:

svn-gvsig-desktop / tags / v1_2_Build_1202 / libraries / libjni-gdal / include / cpl_vsi.h @ 33918

History | View | Annotate | Download (10.3 KB)

1 716 igbrotru
/******************************************************************************
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 7765 nacho
 * Revision 1.3  2006-10-03 07:05:18  nacho
36 716 igbrotru
 * *** empty log message ***
37
 *
38 7765 nacho
 * Revision 1.1  2006/07/18 16:21:00  nacho
39
 * *** empty log message ***
40
 *
41
 * Revision 1.1  2006/06/29 16:23:27  nacho
42
 * *** empty log message ***
43
 *
44
 * Revision 1.2  2006/01/09 12:50:13  nacho
45
 * *** empty log message ***
46
 *
47 3540 nacho
 * Revision 1.1  2005/07/27 08:22:55  igbrotru
48
 * *** empty log message ***
49
 *
50
 * Revision 1.1  2004/12/28 14:06:59  igbrotru
51
 * *** empty log message ***
52
 *
53 716 igbrotru
 * Revision 1.1  2004/10/28 12:08:47  igbrotru
54
 * *** empty log message ***
55
 *
56
 * Revision 1.1  2004/09/27 08:27:48  igbrotru
57
 * *** empty log message ***
58
 *
59
 * Revision 1.1  2004/09/08 12:39:04  igbrotru
60
 * *** empty log message ***
61
 *
62
 * Revision 1.18  2003/09/10 19:44:36  warmerda
63
 * added VSIStrerrno()
64
 *
65
 * Revision 1.17  2003/09/08 08:11:40  dron
66
 * Added VSIGMTime() and VSILocalTime().
67
 *
68
 * Revision 1.16  2003/05/27 20:44:40  warmerda
69
 * added VSI io debugging macros
70
 *
71
 * Revision 1.15  2002/06/17 14:10:14  warmerda
72
 * no stat64 on Win32
73
 *
74
 * Revision 1.14  2002/06/17 14:00:16  warmerda
75
 * segregate VSIStatL() and VSIStatBufL.
76
 *
77
 * Revision 1.13  2002/06/15 02:13:13  aubin
78
 * remove debug test for 64bit compile
79
 *
80
 * Revision 1.12  2002/06/15 00:07:23  aubin
81
 * mods to enable 64bit file i/o
82
 *
83
 * Revision 1.11  2001/04/30 18:19:06  warmerda
84
 * avoid stat on macos_pre10
85
 *
86
 * Revision 1.10  2001/01/19 21:16:41  warmerda
87
 * expanded tabs
88
 *
89
 * Revision 1.9  2001/01/03 17:41:44  warmerda
90
 * added #define for VSIFFlushL
91
 *
92
 * Revision 1.8  2001/01/03 16:17:50  warmerda
93
 * added large file API
94
 *
95
 * Revision 1.7  2000/12/14 18:29:48  warmerda
96
 * added VSIMkdir
97
 *
98
 * Revision 1.6  2000/01/25 03:11:03  warmerda
99
 * added unlink and mkdir
100
 *
101
 * Revision 1.5  1999/05/23 02:43:57  warmerda
102
 * Added documentation block.
103
 *
104
 * Revision 1.4  1999/02/25 04:48:11  danmo
105
 * Added VSIStat() macros specific to _WIN32 (for MSVC++)
106
 *
107
 * Revision 1.3  1999/01/28 18:31:25  warmerda
108
 * Test on _WIN32 rather than WIN32.  It seems to be more reliably defined.
109
 *
110
 * Revision 1.2  1998/12/04 21:42:57  danmo
111
 * Added #ifndef WIN32 arounf #include <unistd.h>
112
 *
113
 * Revision 1.1  1998/12/03 18:26:02  warmerda
114
 * New
115
 *
116
 */
117
118
#ifndef CPL_VSI_H_INCLUDED
119
#define CPL_VSI_H_INCLUDED
120
121
#include "cpl_port.h"
122
/**
123
 * \file cpl_vsi.h
124
 *
125
 * Standard C Covers
126
 *
127
 * The VSI functions are intended to be hookable aliases for Standard C
128
 * I/O, memory allocation and other system functions. They are intended
129
 * to allow virtualization of disk I/O so that non file data sources
130
 * can be made to appear as files, and so that additional error trapping
131
 * and reporting can be interested.  The memory access API is aliased
132
 * so that special application memory management services can be used.
133
 *
134
 * Is is intended that each of these functions retains exactly the same
135
 * calling pattern as the original Standard C functions they relate to.
136
 * This means we don't have to provide custom documentation, and also means
137
 * that the default implementation is very simple.
138
 */
139
140
141
/* -------------------------------------------------------------------- */
142
/*      We need access to ``struct stat''.                              */
143
/* -------------------------------------------------------------------- */
144
#ifndef _WIN32
145
#  include <unistd.h>
146
#endif
147
#if !defined(macos_pre10)
148
#  include <sys/stat.h>
149
#endif
150
151
CPL_C_START
152
153
/* ==================================================================== */
154
/*      stdio file access functions.                                    */
155
/* ==================================================================== */
156
157
FILE CPL_DLL *  VSIFOpen( const char *, const char * );
158
int CPL_DLL     VSIFClose( FILE * );
159
int CPL_DLL     VSIFSeek( FILE *, long, int );
160
long CPL_DLL    VSIFTell( FILE * );
161
void CPL_DLL    VSIRewind( FILE * );
162
void CPL_DLL    VSIFFlush( FILE * );
163
164
size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
165
size_t CPL_DLL  VSIFWrite( void *, size_t, size_t, FILE * );
166
char CPL_DLL   *VSIFGets( char *, int, FILE * );
167
int CPL_DLL     VSIFPuts( const char *, FILE * );
168
int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
169
170
int CPL_DLL     VSIFGetc( FILE * );
171
int CPL_DLL     VSIFPutc( int, FILE * );
172
int CPL_DLL     VSIUngetc( int, FILE * );
173
int CPL_DLL     VSIFEof( FILE * );
174
175
/* ==================================================================== */
176
/*      VSIStat() related.                                              */
177
/* ==================================================================== */
178
179
typedef struct stat VSIStatBuf;
180
int CPL_DLL VSIStat( const char *, VSIStatBuf * );
181
182
#ifdef _WIN32
183
#  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
184
#  define VSI_ISREG(x)  ((x) & S_IFREG)
185
#  define VSI_ISDIR(x)  ((x) & S_IFDIR)
186
#  define VSI_ISCHR(x)  ((x) & S_IFCHR)
187
#  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
188
#else
189
#  define VSI_ISLNK(x)  S_ISLNK(x)
190
#  define VSI_ISREG(x)  S_ISREG(x)
191
#  define VSI_ISDIR(x)  S_ISDIR(x)
192
#  define VSI_ISCHR(x)  S_ISCHR(x)
193
#  define VSI_ISBLK(x)  S_ISBLK(x)
194
#endif
195
196
/* ==================================================================== */
197
/*      64bit stdio file access functions.  If we have a big size       */
198
/*      defined, then provide protypes for the large file API,          */
199
/*      otherwise redefine to use the regular api.                      */
200
/* ==================================================================== */
201
#ifdef VSI_LARGE_API_SUPPORTED
202
203
typedef GUIntBig vsi_l_offset;
204
205
FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
206
int CPL_DLL     VSIFCloseL( FILE * );
207
int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
208
vsi_l_offset CPL_DLL VSIFTellL( FILE * );
209
void CPL_DLL    VSIRewindL( FILE * );
210
size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
211
size_t CPL_DLL  VSIFWriteL( void *, size_t, size_t, FILE * );
212
int CPL_DLL     VSIFEofL( FILE * );
213
void CPL_DLL    VSIFFlushL( FILE * );
214
215
#ifndef WIN32
216
typedef struct stat64 VSIStatBufL;
217
int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
218
#else
219
#define VSIStatBufL    VSIStatBuf
220
#define VSIStatL       VSIStat
221
#endif
222
223
#else
224
225
typedef long vsi_l_offset;
226
227
#define vsi_l_offset long
228
229
#define VSIFOpenL      VSIFOpen
230
#define VSIFCloseL     VSIFClose
231
#define VSIFSeekL      VSIFSeek
232
#define VSIFTellL      VSIFTell
233
#define VSIFRewindL    VSIFRewind
234
#define VSIFReadL      VSIFRead
235
#define VSIFWriteL     VSIFWrite
236
#define VSIFEofL       VSIFEof
237
#define VSIFFlushL     VSIFFlush
238
#define VSIStatBufL    VSIStatBuf
239
#define VSIStatL       VSIStat
240
241
#endif
242
243
/* ==================================================================== */
244
/*      Memory allocation                                               */
245
/* ==================================================================== */
246
247
void CPL_DLL   *VSICalloc( size_t, size_t );
248
void CPL_DLL   *VSIMalloc( size_t );
249
void CPL_DLL    VSIFree( void * );
250
void CPL_DLL   *VSIRealloc( void *, size_t );
251
char CPL_DLL   *VSIStrdup( const char * );
252
253
/* ==================================================================== */
254
/*      Other...                                                        */
255
/* ==================================================================== */
256
257
int CPL_DLL VSIMkdir( const char * pathname, long mode );
258
int CPL_DLL VSIRmdir( const char * pathname );
259
int CPL_DLL VSIUnlink( const char * pathname );
260
char CPL_DLL *VSIStrerror( int );
261
262
/* ==================================================================== */
263
/*      Time quering.                                                   */
264
/* ==================================================================== */
265
266
unsigned long CPL_DLL VSITime( unsigned long * );
267
const char CPL_DLL *VSICTime( unsigned long );
268
struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
269
                              struct tm *poBrokenTime );
270
struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
271
                                 struct tm *poBrokenTime );
272
273
/* -------------------------------------------------------------------- */
274
/*      the following can be turned on for detailed logging of          */
275
/*      almost all IO calls.                                            */
276
/* -------------------------------------------------------------------- */
277
#ifdef VSI_DEBUG
278
279
#ifndef DEBUG
280
#  define DEBUG
281
#endif
282
283
#include "cpl_error.h"
284
285
#define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
286
#define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
287
#define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
288
#define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
289
#else
290
#define VSIDebug4( f, a1, a2, a3, a4 ) {}
291
#define VSIDebug3( f, a1, a2, a3 ) {}
292
#define VSIDebug2( f, a1, a2 )     {}
293
#define VSIDebug1( f, a1 )         {}
294
#endif
295
296
CPL_C_END
297
298
#endif /* ndef CPL_VSI_H_INCLUDED */