MCPcopy Index your code
hub / github.com/MapServer/MapServer / msDBFOpen

Function msDBFOpen

mapxbase.c:145–252  ·  view source on GitHub ↗

/ msDBFOpen() */ / Open a .dbf file. */ /

Source from the content-addressed store, hash-verified

143/* Open a .dbf file. */
144/************************************************************************/
145DBFHandle msDBFOpen( const char * pszFilename, const char * pszAccess )
146
147{
148 DBFHandle psDBF;
149 uchar *pabyBuf;
150 int nFields, nRecords, nHeadLen, nRecLen, iField;
151 char *pszDBFFilename;
152
153 /* -------------------------------------------------------------------- */
154 /* We only allow the access strings "rb" and "r+". */
155 /* -------------------------------------------------------------------- */
156 if( strcmp(pszAccess,"r") != 0 && strcmp(pszAccess,"r+") != 0
157 && strcmp(pszAccess,"rb") != 0 && strcmp(pszAccess,"r+b") != 0 )
158 return( NULL );
159
160 /* -------------------------------------------------------------------- */
161 /* Ensure the extension is converted to dbf or DBF if it is */
162 /* currently .shp or .shx. */
163 /* -------------------------------------------------------------------- */
164 pszDBFFilename = (char *) msSmallMalloc(strlen(pszFilename)+1);
165 strcpy( pszDBFFilename, pszFilename );
166
167 if( strcmp(pszFilename+strlen(pszFilename)-4,".shp")
168 || strcmp(pszFilename+strlen(pszFilename)-4,".shx") )
169 {
170 strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".dbf");
171 }
172 else if( strcmp(pszFilename+strlen(pszFilename)-4,".SHP")
173 || strcmp(pszFilename+strlen(pszFilename)-4,".SHX") )
174 {
175 strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".DBF");
176 }
177
178 /* -------------------------------------------------------------------- */
179 /* Open the file. */
180 /* -------------------------------------------------------------------- */
181 psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
182 MS_CHECK_ALLOC(psDBF, sizeof(DBFInfo), NULL);
183 psDBF->fp = fopen( pszDBFFilename, pszAccess );
184 if( psDBF->fp == NULL )
185 return( NULL );
186
187 psDBF->bNoHeader = MS_FALSE;
188 psDBF->nCurrentRecord = -1;
189 psDBF->bCurrentRecordModified = MS_FALSE;
190
191 psDBF->pszStringField = NULL;
192 psDBF->nStringFieldLen = 0;
193
194 free( pszDBFFilename );
195
196 /* -------------------------------------------------------------------- */
197 /* Read Table Header info */
198 /* -------------------------------------------------------------------- */
199 pabyBuf = (uchar *) msSmallMalloc(500);
200 fread( pabyBuf, 32, 1, psDBF->fp );
201
202 psDBF->nRecords = nRecords =

Callers 4

process_shapefilesFunction · 0.85
mainFunction · 0.85
msShapefileOpenFunction · 0.85
msDBFJoinConnectFunction · 0.85

Calls 2

msSmallMallocFunction · 0.85
SfReallocFunction · 0.70

Tested by

no test coverage detected