PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ DBFCreateLL()

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

Definition at line 644 of file dbfopen.c.

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

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

Referenced by DBFCreateEx().

Here is the call graph for this function:
Here is the caller graph for this function: