1 /******************************************************************************
2 * $Id: cpl_vsil_simple.cpp 10645 2007-01-18 02:22:39Z warmerdam $
3 *
4 * Project: VSI Virtual File System
5 * Purpose: Alternatve simplified implementation VSI*L File API that just
6 * uses plain VSI API and/or posix calls. This module isn't
7 * normally built into GDAL. It is for simple packages like
8 * dgnlib.
9 * Author: Frank Warmerdam, warmerdam@pobox.com
10 *
11 ******************************************************************************
12 * Copyright (c) 2006, Frank Warmerdam <warmerdam@pobox.com>
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
31 ****************************************************************************/
32
33 #include "cpl_vsi.h"
34
35 CPL_CVSID("$Id: cpl_vsil_simple.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
36
37 #ifdef WIN32
38 # include <sys/stat.h>
39 # include <sys/types.h>
40 # include <io.h>
41 # include <fcntl.h>
42 # include <direct.h>
43 #else
44 # include <unistd.h>
45 # include <sys/stat.h>
46 # include <sys/types.h>
47 # include <dirent.h>
48 #endif
49
50 /************************************************************************/
51 /* VSIMkdir() */
52 /************************************************************************/
53
VSIMkdir(const char * pszPathname,long mode)54 int VSIMkdir( const char *pszPathname, long mode )
55
56 {
57 #ifdef WIN32
58 return mkdir( pszPathname );
59 #else
60 return mkdir( pszPathname, mode );
61 #endif
62 }
63
64 /************************************************************************/
65 /* VSIUnlink() */
66 /*************************a***********************************************/
67
VSIUnlink(const char * pszFilename)68 int VSIUnlink( const char * pszFilename )
69
70 {
71 return unlink( pszFilename );
72 }
73
74 /************************************************************************/
75 /* VSIRename() */
76 /************************************************************************/
77
VSIRename(const char * oldpath,const char * newpath)78 int VSIRename( const char * oldpath, const char * newpath )
79
80 {
81 return rename( oldpath, newpath );
82 }
83
84 /************************************************************************/
85 /* VSIRmdir() */
86 /************************************************************************/
87
VSIRmdir(const char * pszDirname)88 int VSIRmdir( const char * pszDirname )
89
90 {
91 return rmdir( pszDirname );
92 }
93
94 /************************************************************************/
95 /* VSIStatL() */
96 /************************************************************************/
97
VSIStatL(const char * pszFilename,VSIStatBufL * psStatBuf)98 int VSIStatL( const char * pszFilename, VSIStatBufL *psStatBuf )
99
100 {
101 return( VSIStat( pszFilename, (VSIStatBuf *) psStatBuf ) );
102 }
103
104 /************************************************************************/
105 /* VSIFOpenL() */
106 /************************************************************************/
107
VSIFOpenL(const char * pszFilename,const char * pszAccess)108 FILE *VSIFOpenL( const char * pszFilename, const char * pszAccess )
109
110 {
111 return VSIFOpen( pszFilename, pszAccess );
112 }
113
114 /************************************************************************/
115 /* VSIFCloseL() */
116 /************************************************************************/
117
VSIFCloseL(FILE * fp)118 int VSIFCloseL( FILE * fp )
119
120 {
121 return VSIFClose( fp );
122 }
123
124 /************************************************************************/
125 /* VSIFSeekL() */
126 /************************************************************************/
127
VSIFSeekL(FILE * fp,vsi_l_offset nOffset,int nWhence)128 int VSIFSeekL( FILE * fp, vsi_l_offset nOffset, int nWhence )
129
130 {
131 return VSIFSeek( fp, (int) nOffset, nWhence );
132 }
133
134 /************************************************************************/
135 /* VSIFTellL() */
136 /************************************************************************/
137
VSIFTellL(FILE * fp)138 vsi_l_offset VSIFTellL( FILE * fp )
139
140 {
141 return (vsi_l_offset) VSIFTell( fp );
142 }
143
144 /************************************************************************/
145 /* VSIRewindL() */
146 /************************************************************************/
147
VSIRewindL(FILE * fp)148 void VSIRewindL( FILE * fp )
149
150 {
151 VSIFSeekL( fp, 0, SEEK_SET );
152 }
153
154 /************************************************************************/
155 /* VSIFFlushL() */
156 /************************************************************************/
157
VSIFFlushL(FILE * fp)158 int VSIFFlushL( FILE * fp )
159
160 {
161 VSIFFlush( fp );
162 return 0;
163 }
164
165 /************************************************************************/
166 /* VSIFReadL() */
167 /************************************************************************/
168
VSIFReadL(void * pBuffer,size_t nSize,size_t nCount,FILE * fp)169 size_t VSIFReadL( void * pBuffer, size_t nSize, size_t nCount, FILE * fp )
170
171 {
172 return VSIFRead( pBuffer, nSize, nCount, fp );
173 }
174
175 /************************************************************************/
176 /* VSIFWriteL() */
177 /************************************************************************/
178
VSIFWriteL(void * pBuffer,size_t nSize,size_t nCount,FILE * fp)179 size_t VSIFWriteL( void * pBuffer, size_t nSize, size_t nCount, FILE * fp )
180
181 {
182 return VSIFWrite( pBuffer, nSize, nCount, fp );
183 }
184
185 /************************************************************************/
186 /* VSIFEofL() */
187 /************************************************************************/
188
VSIFEofL(FILE * fp)189 int VSIFEofL( FILE * fp )
190
191 {
192 return VSIFEof( fp );
193 }
194