Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_1_Build_1019 / libraries / libjni-gdal-macosx / include / cpl_vsi.h @ 28163

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

    
124
#ifndef CPL_VSI_H_INCLUDED
125
#define CPL_VSI_H_INCLUDED
126

    
127
#include "cpl_port.h"
128
/**
129
 * \file cpl_vsi.h
130
 *
131
 * Standard C Covers
132
 *
133
 * The VSI functions are intended to be hookable aliases for Standard C
134
 * I/O, memory allocation and other system functions. They are intended
135
 * to allow virtualization of disk I/O so that non file data sources
136
 * can be made to appear as files, and so that additional error trapping
137
 * and reporting can be interested.  The memory access API is aliased
138
 * so that special application memory management services can be used.
139
 *
140
 * Is is intended that each of these functions retains exactly the same
141
 * calling pattern as the original Standard C functions they relate to.
142
 * This means we don't have to provide custom documentation, and also means
143
 * that the default implementation is very simple.
144
 */
145

    
146

    
147
/* -------------------------------------------------------------------- */
148
/*      We need access to ``struct stat''.                              */
149
/* -------------------------------------------------------------------- */
150
#ifndef _WIN32
151
#  include <unistd.h>
152
#endif
153
#if !defined(macos_pre10)
154
#  include <sys/stat.h>
155
#endif
156

    
157
CPL_C_START
158

    
159
/* ==================================================================== */
160
/*      stdio file access functions.                                    */
161
/* ==================================================================== */
162

    
163
FILE CPL_DLL *  VSIFOpen( const char *, const char * );
164
int CPL_DLL     VSIFClose( FILE * );
165
int CPL_DLL     VSIFSeek( FILE *, long, int );
166
long CPL_DLL    VSIFTell( FILE * );
167
void CPL_DLL    VSIRewind( FILE * );
168
void CPL_DLL    VSIFFlush( FILE * );
169

    
170
size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
171
size_t CPL_DLL  VSIFWrite( void *, size_t, size_t, FILE * );
172
char CPL_DLL   *VSIFGets( char *, int, FILE * );
173
int CPL_DLL     VSIFPuts( const char *, FILE * );
174
int CPL_DLL     VSIFPrintf( FILE *, const char *, ... );
175

    
176
int CPL_DLL     VSIFGetc( FILE * );
177
int CPL_DLL     VSIFPutc( int, FILE * );
178
int CPL_DLL     VSIUngetc( int, FILE * );
179
int CPL_DLL     VSIFEof( FILE * );
180

    
181
/* ==================================================================== */
182
/*      VSIStat() related.                                              */
183
/* ==================================================================== */
184

    
185
typedef struct stat VSIStatBuf;
186
int CPL_DLL VSIStat( const char *, VSIStatBuf * );
187

    
188
#ifdef _WIN32
189
#  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
190
#  define VSI_ISREG(x)  ((x) & S_IFREG)
191
#  define VSI_ISDIR(x)  ((x) & S_IFDIR)
192
#  define VSI_ISCHR(x)  ((x) & S_IFCHR)
193
#  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
194
#else
195
#  define VSI_ISLNK(x)  S_ISLNK(x)
196
#  define VSI_ISREG(x)  S_ISREG(x)
197
#  define VSI_ISDIR(x)  S_ISDIR(x)
198
#  define VSI_ISCHR(x)  S_ISCHR(x)
199
#  define VSI_ISBLK(x)  S_ISBLK(x)
200
#endif
201

    
202
/* ==================================================================== */
203
/*      64bit stdio file access functions.  If we have a big size       */
204
/*      defined, then provide protypes for the large file API,          */
205
/*      otherwise redefine to use the regular api.                      */
206
/* ==================================================================== */
207
#ifdef VSI_LARGE_API_SUPPORTED
208

    
209
typedef GUIntBig vsi_l_offset;
210

    
211
FILE CPL_DLL *  VSIFOpenL( const char *, const char * );
212
int CPL_DLL     VSIFCloseL( FILE * );
213
int CPL_DLL     VSIFSeekL( FILE *, vsi_l_offset, int );
214
vsi_l_offset CPL_DLL VSIFTellL( FILE * );
215
void CPL_DLL    VSIRewindL( FILE * );
216
size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, FILE * );
217
size_t CPL_DLL  VSIFWriteL( void *, size_t, size_t, FILE * );
218
int CPL_DLL     VSIFEofL( FILE * );
219
void CPL_DLL    VSIFFlushL( FILE * );
220

    
221
#ifndef WIN32
222
typedef struct stat64 VSIStatBufL;
223
int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
224
#else
225
#define VSIStatBufL    VSIStatBuf
226
#define VSIStatL       VSIStat
227
#endif
228

    
229
#else
230

    
231
typedef long vsi_l_offset;
232

    
233
#define vsi_l_offset long
234

    
235
#define VSIFOpenL      VSIFOpen
236
#define VSIFCloseL     VSIFClose
237
#define VSIFSeekL      VSIFSeek
238
#define VSIFTellL      VSIFTell
239
#define VSIFRewindL    VSIFRewind
240
#define VSIFReadL      VSIFRead
241
#define VSIFWriteL     VSIFWrite
242
#define VSIFEofL       VSIFEof
243
#define VSIFFlushL     VSIFFlush
244
#define VSIStatBufL    VSIStatBuf
245
#define VSIStatL       VSIStat
246

    
247
#endif
248

    
249
/* ==================================================================== */
250
/*      Memory allocation                                               */
251
/* ==================================================================== */
252

    
253
void CPL_DLL   *VSICalloc( size_t, size_t );
254
void CPL_DLL   *VSIMalloc( size_t );
255
void CPL_DLL    VSIFree( void * );
256
void CPL_DLL   *VSIRealloc( void *, size_t );
257
char CPL_DLL   *VSIStrdup( const char * );
258

    
259
/* ==================================================================== */
260
/*      Other...                                                        */
261
/* ==================================================================== */
262

    
263
int CPL_DLL VSIMkdir( const char * pathname, long mode );
264
int CPL_DLL VSIRmdir( const char * pathname );
265
int CPL_DLL VSIUnlink( const char * pathname );
266
char CPL_DLL *VSIStrerror( int );
267

    
268
/* ==================================================================== */
269
/*      Time quering.                                                   */
270
/* ==================================================================== */
271

    
272
unsigned long CPL_DLL VSITime( unsigned long * );
273
const char CPL_DLL *VSICTime( unsigned long );
274
struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
275
                              struct tm *poBrokenTime );
276
struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
277
                                 struct tm *poBrokenTime );
278

    
279
/* -------------------------------------------------------------------- */
280
/*      the following can be turned on for detailed logging of          */
281
/*      almost all IO calls.                                            */
282
/* -------------------------------------------------------------------- */
283
#ifdef VSI_DEBUG
284

    
285
#ifndef DEBUG
286
#  define DEBUG
287
#endif
288

    
289
#include "cpl_error.h"
290

    
291
#define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
292
#define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
293
#define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
294
#define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
295
#else
296
#define VSIDebug4( f, a1, a2, a3, a4 ) {}
297
#define VSIDebug3( f, a1, a2, a3 ) {}
298
#define VSIDebug2( f, a1, a2 )     {}
299
#define VSIDebug1( f, a1 )         {}
300
#endif
301

    
302
CPL_C_END
303

    
304
#endif /* ndef CPL_VSI_H_INCLUDED */