PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ DBFCreateLL()

DBFHandle SHPAPI_CALL DBFCreateLL ( const char *  pszDBFFile,
const char *  pszCodePage,
SAHooks psHooks 
)

Definition at line 658 of file dbfopen.c.

References FALSE, SAHooks::FClose, SAHooks::FOpen, free(), SAHooks::FWrite, malloc(), SAHooks::Remove, SHPAPI_CALL, and TRUE.

Referenced by DBFCreateEx().

660 {
661  DBFHandle psDBF;
662  SAFile fp;
663  char *pszFullname, *pszBasename;
664  int i, ldid = -1;
665  char chZero = '\0';
666 
667 /* -------------------------------------------------------------------- */
668 /* Compute the base (layer) name. If there is any extension */
669 /* on the passed in filename we will strip it off. */
670 /* -------------------------------------------------------------------- */
671  pszBasename = (char *) malloc(strlen(pszFilename)+5);
672  strcpy( pszBasename, pszFilename );
673  for( i = strlen(pszBasename)-1;
674  i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
675  && pszBasename[i] != '\\';
676  i-- ) {}
677 
678  if( pszBasename[i] == '.' )
679  pszBasename[i] = '\0';
680 
681  pszFullname = (char *) malloc(strlen(pszBasename) + 5);
682  sprintf( pszFullname, "%s.dbf", pszBasename );
683 
684 /* -------------------------------------------------------------------- */
685 /* Create the file. */
686 /* -------------------------------------------------------------------- */
687  fp = psHooks->FOpen( pszFullname, "wb" );
688  if( fp == NULL )
689  return( NULL );
690 
691  psHooks->FWrite( &chZero, 1, 1, fp );
692  psHooks->FClose( fp );
693 
694  fp = psHooks->FOpen( pszFullname, "rb+" );
695  if( fp == NULL )
696  {
697  free(pszBasename);
698  free(pszFullname);
699  return( NULL );
700  }
701 
702 
703  sprintf( pszFullname, "%s.cpg", pszBasename );
704  if( pszCodePage != NULL )
705  {
706  if( strncmp( pszCodePage, "LDID/", 5 ) == 0 )
707  {
708  ldid = atoi( pszCodePage + 5 );
709  if( ldid > 255 )
710  ldid = -1; /* don't use 0 to indicate out of range as LDID/0 is a valid one */
711  }
712  if( ldid < 0 )
713  {
714  SAFile fpCPG = psHooks->FOpen( pszFullname, "w" );
715  psHooks->FWrite( (char*) pszCodePage, strlen(pszCodePage), 1, fpCPG );
716  psHooks->FClose( fpCPG );
717  }
718  }
719  if( pszCodePage == NULL || ldid >= 0 )
720  {
721  psHooks->Remove( pszFullname );
722  }
723 
724  free( pszBasename );
725  free( pszFullname );
726 
727 /* -------------------------------------------------------------------- */
728 /* Create the info structure. */
729 /* -------------------------------------------------------------------- */
730  psDBF = (DBFHandle) calloc(1,sizeof(DBFInfo));
731 
732  memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
733  psDBF->fp = fp;
734  psDBF->nRecords = 0;
735  psDBF->nFields = 0;
736  psDBF->nRecordLength = 1;
737  psDBF->nHeaderLength = 33;
738 
739  psDBF->panFieldOffset = NULL;
740  psDBF->panFieldSize = NULL;
741  psDBF->panFieldDecimals = NULL;
742  psDBF->pachFieldType = NULL;
743  psDBF->pszHeader = NULL;
744 
745  psDBF->nCurrentRecord = -1;
746  psDBF->bCurrentRecordModified = FALSE;
747  psDBF->pszCurrentRecord = NULL;
748 
749  psDBF->bNoHeader = TRUE;
750 
751  psDBF->iLanguageDriver = ldid > 0 ? ldid : 0;
752  psDBF->pszCodePage = NULL;
753  if( pszCodePage )
754  {
755  psDBF->pszCodePage = (char * ) malloc( strlen(pszCodePage) + 1 );
756  strcpy( psDBF->pszCodePage, pszCodePage );
757  }
758 
759  return( psDBF );
760 }
int(* FClose)(SAFile file)
Definition: shapefil.h:261
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
Definition: shapefil.h:257
int(* Remove)(const char *filename)
Definition: shapefil.h:262
#define FALSE
Definition: dbfopen.c:168
void free(void *)
void * malloc(YYSIZE_T)
int * SAFile
Definition: shapefil.h:242
SAFile(* FOpen)(const char *filename, const char *access)
Definition: shapefil.h:255
#define TRUE
Definition: dbfopen.c:169
Here is the call graph for this function:
Here is the caller graph for this function: