PostGIS  2.1.10dev-r@@SVN_REVISION@@
DBFHandle SHPAPI_CALL DBFCreateLL ( const char *  pszDBFFile,
const char *  pszCodePage,
SAHooks psHooks 
)

Definition at line 659 of file dbfopen.c.

References FALSE, SAHooks::FClose, SAHooks::FOpen, SAHooks::FWrite, SAHooks::Remove, and TRUE.

Referenced by DBFCreateEx().

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

Here is the caller graph for this function: