Skip to content

Commit

Permalink
Shapelib: resync with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 9, 2023
1 parent 3dd19ec commit 47dff63
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
16 changes: 9 additions & 7 deletions ogr/ogrsf_frmts/shape/dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,22 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess,
memcpy(pszFullname + nLenWithoutExtension, ".dbf", 5);

DBFHandle psDBF = STATIC_CAST(DBFHandle, calloc(1, sizeof(DBFInfo)));
psDBF->fp = psHooks->FOpen(pszFullname, pszAccess);
psDBF->fp = psHooks->FOpen(pszFullname, pszAccess, psHooks->pvUserData);
memcpy(&(psDBF->sHooks), psHooks, sizeof(SAHooks));

if (psDBF->fp == SHPLIB_NULLPTR)
{
memcpy(pszFullname + nLenWithoutExtension, ".DBF", 5);
psDBF->fp = psDBF->sHooks.FOpen(pszFullname, pszAccess);
psDBF->fp =
psDBF->sHooks.FOpen(pszFullname, pszAccess, psHooks->pvUserData);
}

memcpy(pszFullname + nLenWithoutExtension, ".cpg", 5);
SAFile pfCPG = psHooks->FOpen(pszFullname, "r");
SAFile pfCPG = psHooks->FOpen(pszFullname, "r", psHooks->pvUserData);
if (pfCPG == SHPLIB_NULLPTR)
{
memcpy(pszFullname + nLenWithoutExtension, ".CPG", 5);
pfCPG = psHooks->FOpen(pszFullname, "r");
pfCPG = psHooks->FOpen(pszFullname, "r", psHooks->pvUserData);
}

free(pszFullname);
Expand Down Expand Up @@ -643,7 +644,7 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
/* -------------------------------------------------------------------- */
/* Create the file. */
/* -------------------------------------------------------------------- */
SAFile fp = psHooks->FOpen(pszFullname, "wb+");
SAFile fp = psHooks->FOpen(pszFullname, "wb+", psHooks->pvUserData);
if (fp == SHPLIB_NULLPTR)
{
free(pszFullname);
Expand All @@ -663,7 +664,8 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
}
if (ldid < 0)
{
SAFile fpCPG = psHooks->FOpen(pszFullname, "w");
SAFile fpCPG =
psHooks->FOpen(pszFullname, "w", psHooks->pvUserData);
psHooks->FWrite(
CONST_CAST(void *, STATIC_CAST(const void *, pszCodePage)),
strlen(pszCodePage), 1, fpCPG);
Expand All @@ -672,7 +674,7 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
}
if (pszCodePage == SHPLIB_NULLPTR || ldid >= 0)
{
psHooks->Remove(pszFullname);
psHooks->Remove(pszFullname, psHooks->pvUserData);
}

free(pszFullname);
Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/shape/sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ SBNSearchHandle SBNOpenDiskTree(const char *pszSBNFilename,
else
memcpy(&(hSBN->sHooks), psHooks, sizeof(SAHooks));

hSBN->fpSBN = hSBN->sHooks.FOpen(pszSBNFilename, "rb");
hSBN->fpSBN =
hSBN->sHooks.FOpen(pszSBNFilename, "rb", hSBN->sHooks.pvUserData);
if (hSBN->fpSBN == SHPLIB_NULLPTR)
{
free(hSBN);
Expand Down Expand Up @@ -626,7 +627,7 @@ static bool SBNSearchDiskInternal(SearchStruct *psSearch, int nDepth,

if (!psNode->bBBoxInit)
{
/* clang-format off */
/* clang-format off */
#ifdef sanity_checks
/* -------------------------------------------------------------------- */
/* Those tests only check that the shape bounding box in the bin */
Expand Down
6 changes: 4 additions & 2 deletions ogr/ogrsf_frmts/shape/shapefil.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ extern "C"

typedef struct
{
SAFile (*FOpen)(const char *filename, const char *access);
SAFile (*FOpen)(const char *filename, const char *access,
void *pvUserData);
SAOffset (*FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file);
SAOffset (*FWrite)(const void *p, SAOffset size, SAOffset nmemb,
SAFile file);
SAOffset (*FSeek)(SAFile file, SAOffset offset, int whence);
SAOffset (*FTell)(SAFile file);
int (*FFlush)(SAFile file);
int (*FClose)(SAFile file);
int (*Remove)(const char *filename);
int (*Remove)(const char *filename, void *pvUserData);

void (*Error)(const char *message);
double (*Atof)(const char *str);
void *pvUserData;
} SAHooks;

void SHPAPI_CALL SASetupDefaultHooks(SAHooks *psHooks);
Expand Down
18 changes: 12 additions & 6 deletions ogr/ogrsf_frmts/shape/shp_vsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ static SAFile VSI_SHP_OpenInternal(const char *pszFilename,
/* VSI_SHP_Open() */
/************************************************************************/

static SAFile VSI_SHP_Open(const char *pszFilename, const char *pszAccess)
static SAFile VSI_SHP_Open(const char *pszFilename, const char *pszAccess,
void *userData)

{
(void)userData;
return VSI_SHP_OpenInternal(pszFilename, pszAccess, FALSE);
}

Expand All @@ -98,9 +100,10 @@ static SAFile VSI_SHP_Open(const char *pszFilename, const char *pszAccess)
/************************************************************************/

static SAFile VSI_SHP_Open2GBLimit(const char *pszFilename,
const char *pszAccess)
const char *pszAccess, void *userData)

{
(void)userData;
return VSI_SHP_OpenInternal(pszFilename, pszAccess, TRUE);
}

Expand Down Expand Up @@ -231,9 +234,10 @@ static void VSI_SHP_Error(const char *message)
/* VSI_SHP_Remove() */
/************************************************************************/

static int VSI_SHP_Remove(const char *pszFilename)
static int VSI_SHP_Remove(const char *pszFilename, void *userData)

{
(void)userData;
return VSIUnlink(pszFilename);
}

Expand All @@ -255,20 +259,22 @@ void SASetupDefaultHooks(SAHooks *psHooks)

psHooks->Error = VSI_SHP_Error;
psHooks->Atof = CPLAtof;
psHooks->pvUserData = NULL;
}

/************************************************************************/
/* VSI_SHP_GetHook() */
/************************************************************************/

static const SAHooks sOGRHook = {
VSI_SHP_Open, VSI_SHP_Read, VSI_SHP_Write, VSI_SHP_Seek, VSI_SHP_Tell,
VSI_SHP_Flush, VSI_SHP_Close, VSI_SHP_Remove, VSI_SHP_Error, CPLAtof};
VSI_SHP_Open, VSI_SHP_Read, VSI_SHP_Write, VSI_SHP_Seek,
VSI_SHP_Tell, VSI_SHP_Flush, VSI_SHP_Close, VSI_SHP_Remove,
VSI_SHP_Error, CPLAtof, NULL};

static const SAHooks sOGRHook2GBLimit = {
VSI_SHP_Open2GBLimit, VSI_SHP_Read, VSI_SHP_Write, VSI_SHP_Seek,
VSI_SHP_Tell, VSI_SHP_Flush, VSI_SHP_Close, VSI_SHP_Remove,
VSI_SHP_Error, CPLAtof};
VSI_SHP_Error, CPLAtof, NULL};

const SAHooks *VSI_SHP_GetHook(int b2GBLimit)
{
Expand Down
23 changes: 14 additions & 9 deletions ogr/ogrsf_frmts/shape/shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,13 @@ SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess,
char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
memcpy(pszFullname, pszLayer, nLenWithoutExtension);
memcpy(pszFullname + nLenWithoutExtension, ".shp", 5);
psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess);
psSHP->fpSHP =
psSHP->sHooks.FOpen(pszFullname, pszAccess, psSHP->sHooks.pvUserData);
if (psSHP->fpSHP == SHPLIB_NULLPTR)
{
memcpy(pszFullname + nLenWithoutExtension, ".SHP", 5);
psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess);
psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess,
psSHP->sHooks.pvUserData);
}

if (psSHP->fpSHP == SHPLIB_NULLPTR)
Expand All @@ -363,11 +365,13 @@ SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess,
}

memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess);
psSHP->fpSHX =
psSHP->sHooks.FOpen(pszFullname, pszAccess, psSHP->sHooks.pvUserData);
if (psSHP->fpSHX == SHPLIB_NULLPTR)
{
memcpy(pszFullname + nLenWithoutExtension, ".SHX", 5);
psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess);
psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess,
psSHP->sHooks.pvUserData);
}

if (psSHP->fpSHX == SHPLIB_NULLPTR)
Expand Down Expand Up @@ -708,11 +712,11 @@ int SHPAPI_CALL SHPRestoreSHX(const char *pszLayer, const char *pszAccess,
char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
memcpy(pszFullname, pszLayer, nLenWithoutExtension);
memcpy(pszFullname + nLenWithoutExtension, ".shp", 5);
SAFile fpSHP = psHooks->FOpen(pszFullname, pszAccess);
SAFile fpSHP = psHooks->FOpen(pszFullname, pszAccess, psHooks->pvUserData);
if (fpSHP == SHPLIB_NULLPTR)
{
memcpy(pszFullname + nLenWithoutExtension, ".SHP", 5);
fpSHP = psHooks->FOpen(pszFullname, pszAccess);
fpSHP = psHooks->FOpen(pszFullname, pszAccess, psHooks->pvUserData);
}

if (fpSHP == SHPLIB_NULLPTR)
Expand Down Expand Up @@ -756,7 +760,8 @@ int SHPAPI_CALL SHPRestoreSHX(const char *pszLayer, const char *pszAccess,

memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
const char pszSHXAccess[] = "w+b";
SAFile fpSHX = psHooks->FOpen(pszFullname, pszSHXAccess);
SAFile fpSHX =
psHooks->FOpen(pszFullname, pszSHXAccess, psHooks->pvUserData);
if (fpSHX == SHPLIB_NULLPTR)
{
size_t nMessageLen = strlen(pszFullname) * 2 + 256;
Expand Down Expand Up @@ -1037,7 +1042,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
memcpy(pszFullname, pszLayer, nLenWithoutExtension);
memcpy(pszFullname + nLenWithoutExtension, ".shp", 5);
SAFile fpSHP = psHooks->FOpen(pszFullname, "w+b");
SAFile fpSHP = psHooks->FOpen(pszFullname, "w+b", psHooks->pvUserData);
if (fpSHP == SHPLIB_NULLPTR)
{
char szErrorMsg[200];
Expand All @@ -1050,7 +1055,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
}

memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
SAFile fpSHX = psHooks->FOpen(pszFullname, "w+b");
SAFile fpSHX = psHooks->FOpen(pszFullname, "w+b", psHooks->pvUserData);
if (fpSHX == SHPLIB_NULLPTR)
{
char szErrorMsg[200];
Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/shape/shptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ SHPTreeDiskHandle SHPOpenDiskTree(const char *pszQIXFilename,
else
memcpy(&(hDiskTree->sHooks), psHooks, sizeof(SAHooks));

hDiskTree->fpQIX = hDiskTree->sHooks.FOpen(pszQIXFilename, "rb");
hDiskTree->fpQIX = hDiskTree->sHooks.FOpen(pszQIXFilename, "rb",
hDiskTree->sHooks.pvUserData);
if (hDiskTree->fpQIX == SHPLIB_NULLPTR)
{
free(hDiskTree);
Expand Down Expand Up @@ -1125,7 +1126,7 @@ int SHPWriteTreeLL(SHPTree *tree, const char *filename, const SAHooks *psHooks)
/* -------------------------------------------------------------------- */
/* Open the output file. */
/* -------------------------------------------------------------------- */
fp = psHooks->FOpen(filename, "wb");
fp = psHooks->FOpen(filename, "wb", psHooks->pvUserData);
if (fp == SHPLIB_NULLPTR)
{
return FALSE;
Expand Down

0 comments on commit 47dff63

Please sign in to comment.