1 : /******************************************************************************
2 : * $Id: shp_vsi.c 20996 2010-10-28 18:38:15Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: IO Redirection via VSI services for shp/dbf io.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2007, Frank Warmerdam
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "shapefil.h"
31 : #include "cpl_vsi.h"
32 : #include "cpl_error.h"
33 : #include "cpl_conv.h"
34 :
35 : CPL_CVSID("$Id: shp_vsi.c 20996 2010-10-28 18:38:15Z rouault $");
36 :
37 : /************************************************************************/
38 : /* VSI_SHP_Open() */
39 : /************************************************************************/
40 :
41 23397 : SAFile VSI_SHP_Open( const char *pszFilename, const char *pszAccess )
42 :
43 : {
44 23397 : return (SAFile) VSIFOpenL( pszFilename, pszAccess );
45 : }
46 :
47 : /************************************************************************/
48 : /* VSI_SHP_Read() */
49 : /************************************************************************/
50 :
51 2612411 : SAOffset VSI_SHP_Read( void *p, SAOffset size, SAOffset nmemb, SAFile file )
52 :
53 : {
54 2612411 : return (SAOffset) VSIFReadL( p, (size_t) size, (size_t) nmemb,
55 : (VSILFILE *) file );
56 : }
57 :
58 : /************************************************************************/
59 : /* VSI_SHP_Write() */
60 : /************************************************************************/
61 :
62 113217 : SAOffset VSI_SHP_Write( void *p, SAOffset size, SAOffset nmemb, SAFile file )
63 :
64 : {
65 113217 : return (SAOffset) VSIFWriteL( p, (size_t) size, (size_t) nmemb,
66 : (VSILFILE *) file );
67 : }
68 :
69 : /************************************************************************/
70 : /* VSI_SHP_Seek() */
71 : /************************************************************************/
72 :
73 717265 : SAOffset VSI_SHP_Seek( SAFile file, SAOffset offset, int whence )
74 :
75 : {
76 717265 : return (SAOffset) VSIFSeekL( (VSILFILE *) file, (vsi_l_offset) offset, whence );
77 : }
78 :
79 : /************************************************************************/
80 : /* VSI_SHP_Tell() */
81 : /************************************************************************/
82 :
83 1808 : SAOffset VSI_SHP_Tell( SAFile file )
84 :
85 : {
86 1808 : return (SAOffset) VSIFTellL( (VSILFILE *) file );
87 : }
88 :
89 : /************************************************************************/
90 : /* VSI_SHP_Flush() */
91 : /************************************************************************/
92 :
93 3890 : int VSI_SHP_Flush( SAFile file )
94 :
95 : {
96 3890 : return VSIFFlushL( (VSILFILE *) file );
97 : }
98 :
99 : /************************************************************************/
100 : /* VSI_SHP_Close() */
101 : /************************************************************************/
102 :
103 15372 : int VSI_SHP_Close( SAFile file )
104 :
105 : {
106 15372 : return VSIFCloseL( (VSILFILE *) file );
107 : }
108 :
109 : /************************************************************************/
110 : /* SADError() */
111 : /************************************************************************/
112 :
113 51 : void VSI_SHP_Error( const char *message )
114 :
115 : {
116 51 : CPLError( CE_Failure, CPLE_AppDefined, "%s", message );
117 51 : }
118 :
119 : /************************************************************************/
120 : /* VSI_SHP_Remove() */
121 : /************************************************************************/
122 :
123 1222 : int VSI_SHP_Remove( const char *pszFilename )
124 :
125 : {
126 1222 : return VSIUnlink( pszFilename );
127 : }
128 :
129 : /************************************************************************/
130 : /* SASetupDefaultHooks() */
131 : /************************************************************************/
132 :
133 10397 : void SASetupDefaultHooks( SAHooks *psHooks )
134 :
135 : {
136 10397 : psHooks->FOpen = VSI_SHP_Open;
137 10397 : psHooks->FRead = VSI_SHP_Read;
138 10397 : psHooks->FWrite = VSI_SHP_Write;
139 10397 : psHooks->FSeek = VSI_SHP_Seek;
140 10397 : psHooks->FTell = VSI_SHP_Tell;
141 10397 : psHooks->FFlush = VSI_SHP_Flush;
142 10397 : psHooks->FClose = VSI_SHP_Close;
143 :
144 10397 : psHooks->Remove = VSI_SHP_Remove;
145 10397 : psHooks->Atof = CPLAtof;
146 :
147 10397 : psHooks->Error = VSI_SHP_Error;
148 10397 : }
|