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

Function msDBFReadAttribute

mapxbase.c:506–594  ·  view source on GitHub ↗

/ msDBFReadAttribute() */ / Read one of the attribute fields of a record. */ /

Source from the content-addressed store, hash-verified

504/* Read one of the attribute fields of a record. */
505/************************************************************************/
506static char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField )
507
508{
509 int i;
510 unsigned int nRecordOffset;
511 uchar *pabyRec;
512 char *pReturnField = NULL;
513
514 /* -------------------------------------------------------------------- */
515 /* Is the request valid? */
516 /* -------------------------------------------------------------------- */
517 if( iField < 0 || iField >= psDBF->nFields )
518 {
519 msSetError(MS_DBFERR, "Invalid field index %d.", "msDBFReadAttribute()",iField );
520 return( NULL );
521 }
522
523 if( hEntity < 0 || hEntity >= psDBF->nRecords )
524 {
525 msSetError(MS_DBFERR, "Invalid record number %d.", "msDBFReadAttribute()",hEntity );
526 return( NULL );
527 }
528
529 /* -------------------------------------------------------------------- */
530 /* Have we read the record? */
531 /* -------------------------------------------------------------------- */
532 if( psDBF->nCurrentRecord != hEntity )
533 {
534 flushRecord( psDBF );
535
536 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;
537
538 safe_fseek( psDBF->fp, nRecordOffset, 0 );
539 fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
540
541 psDBF->nCurrentRecord = hEntity;
542 }
543
544 pabyRec = (uchar *) psDBF->pszCurrentRecord;
545 /* DEBUG */
546 /* printf("CurrentRecord(%c):%s\n", psDBF->pachFieldType[iField], pabyRec); */
547
548 /* -------------------------------------------------------------------- */
549 /* Ensure our field buffer is large enough to hold this buffer. */
550 /* -------------------------------------------------------------------- */
551 if( psDBF->panFieldSize[iField]+1 > psDBF->nStringFieldLen )
552 {
553 psDBF->nStringFieldLen = psDBF->panFieldSize[iField]*2 + 10;
554 psDBF->pszStringField = (char *) SfRealloc(psDBF->pszStringField,psDBF->nStringFieldLen);
555 }
556
557 /* -------------------------------------------------------------------- */
558 /* Extract the requested field. */
559 /* -------------------------------------------------------------------- */
560 strncpy( psDBF->pszStringField,(char *) pabyRec+psDBF->panFieldOffset[iField], psDBF->panFieldSize[iField] );
561 psDBF->pszStringField[psDBF->panFieldSize[iField]] = '\0';
562
563 /*

Callers 3

msDBFReadDoubleAttributeFunction · 0.85
msDBFReadStringAttributeFunction · 0.85

Calls 4

msSetErrorFunction · 0.85
flushRecordFunction · 0.85
DBFIsValueNULLFunction · 0.85
SfReallocFunction · 0.70

Tested by

no test coverage detected