PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ DBFCreateLL()

DBFHandle SHPAPI_CALL DBFCreateLL ( const char *  pszFilename,
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  {
690  free(pszBasename);
691  free(pszFullname);
692  return( NULL );
693  }
694 
695  psHooks->FWrite( &chZero, 1, 1, fp );
696  psHooks->FClose( fp );
697 
698  fp = psHooks->FOpen( pszFullname, "rb+" );
699  if( fp == NULL )
700  {
701  free(pszBasename);
702  free(pszFullname);
703  return( NULL );
704  }
705 
706 
707  sprintf( pszFullname, "%s.cpg", pszBasename );
708  if( pszCodePage != NULL )
709  {
710  if( strncmp( pszCodePage, "LDID/", 5 ) == 0 )
711  {
712  ldid = atoi( pszCodePage + 5 );
713  if( ldid > 255 )
714  ldid = -1; /* don't use 0 to indicate out of range as LDID/0 is a valid one */
715  }
716  if( ldid < 0 )
717  {
718  SAFile fpCPG = psHooks->FOpen( pszFullname, "w" );
719  psHooks->FWrite( (char*) pszCodePage, strlen(pszCodePage), 1, fpCPG );
720  psHooks->FClose( fpCPG );
721  }
722  }
723  if( pszCodePage == NULL || ldid >= 0 )
724  {
725  psHooks->Remove( pszFullname );
726  }
727 
728  free( pszBasename );
729  free( pszFullname );
730 
731 /* -------------------------------------------------------------------- */
732 /* Create the info structure. */
733 /* -------------------------------------------------------------------- */
734  psDBF = (DBFHandle) calloc(1,sizeof(DBFInfo));
735 
736  memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
737  psDBF->fp = fp;
738  psDBF->nRecords = 0;
739  psDBF->nFields = 0;
740  psDBF->nRecordLength = 1;
741  psDBF->nHeaderLength = 33;
742 
743  psDBF->panFieldOffset = NULL;
744  psDBF->panFieldSize = NULL;
745  psDBF->panFieldDecimals = NULL;
746  psDBF->pachFieldType = NULL;
747  psDBF->pszHeader = NULL;
748 
749  psDBF->nCurrentRecord = -1;
750  psDBF->bCurrentRecordModified = FALSE;
751  psDBF->pszCurrentRecord = NULL;
752 
753  psDBF->bNoHeader = TRUE;
754 
755  psDBF->iLanguageDriver = ldid > 0 ? ldid : 0;
756  psDBF->pszCodePage = NULL;
757  if( pszCodePage )
758  {
759  psDBF->pszCodePage = (char * ) malloc( strlen(pszCodePage) + 1 );
760  strcpy( psDBF->pszCodePage, pszCodePage );
761  }
762 
763  return( psDBF );
764 }
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: