Skip to content

Commit

Permalink
frmts/ ogr/ .cpp: replace all remaining uses of CPLFormFilename() wit…
Browse files Browse the repository at this point in the history
…h CPLFormFilenameSafe()
  • Loading branch information
rouault committed Jan 14, 2025
1 parent 469e59d commit 99e6b7a
Show file tree
Hide file tree
Showing 78 changed files with 864 additions and 770 deletions.
5 changes: 3 additions & 2 deletions frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,15 +1223,16 @@ GDALDataset *AAIGDataset::CommonOpen(GDALOpenInfo *poOpenInfo,
char *const pszBasename =
CPLStrdup(CPLGetBasenameSafe(poOpenInfo->pszFilename).c_str());

poDS->osPrjFilename = CPLFormFilename(pszDirname, pszBasename, "prj");
poDS->osPrjFilename = CPLFormFilenameSafe(pszDirname, pszBasename, "prj");
int nRet = 0;
{
VSIStatBufL sStatBuf;
nRet = VSIStatL(poDS->osPrjFilename, &sStatBuf);
}
if (nRet != 0 && VSIIsCaseSensitiveFS(poDS->osPrjFilename))
{
poDS->osPrjFilename = CPLFormFilename(pszDirname, pszBasename, "PRJ");
poDS->osPrjFilename =
CPLFormFilenameSafe(pszDirname, pszBasename, "PRJ");

VSIStatBufL sStatBuf;
nRet = VSIStatL(poDS->osPrjFilename, &sStatBuf);
Expand Down
14 changes: 7 additions & 7 deletions frmts/adrg/adrgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,9 @@ char **ADRGDataset::GetGENListFromTHF(const char *pszFileName)
{
if (EQUAL(*ptrDir, *ptr))
{
osGENFileName =
CPLFormFilename(osGENFileName.c_str(),
*ptrDir, nullptr);
osGENFileName = CPLFormFilenameSafe(
osGENFileName.c_str(), *ptrDir,
nullptr);
CPLDebug("ADRG",
"Building GEN full file name : %s",
osGENFileName.c_str());
Expand Down Expand Up @@ -1475,7 +1475,7 @@ char **ADRGDataset::GetIMGListFromGEN(const char *pszFileName,
CPLString osGENDir(CPLGetDirnameSafe(pszFileName));

const CPLString osFileName =
CPLFormFilename(osGENDir.c_str(), osBAD.c_str(), nullptr);
CPLFormFilenameSafe(osGENDir.c_str(), osBAD.c_str(), nullptr);
VSIStatBufL sStatBuf;
if (VSIStatL(osFileName, &sStatBuf) == 0)
{
Expand All @@ -1498,8 +1498,8 @@ char **ADRGDataset::GetIMGListFromGEN(const char *pszFileName,
{
if (EQUAL(*ptrDir, osBAD.c_str()))
{
osBAD =
CPLFormFilename(osGENDir.c_str(), *ptrDir, nullptr);
osBAD = CPLFormFilenameSafe(osGENDir.c_str(), *ptrDir,
nullptr);
CPLDebug("ADRG", "Building IMG full file name : %s",
osBAD.c_str());
break;
Expand Down Expand Up @@ -1735,7 +1735,7 @@ GDALDataset *ADRGDataset::Create(const char *pszFilename, int nXSize,

CPLString osDirname(CPLGetDirnameSafe(pszFilename));
CPLString osTransh01THF(
CPLFormFilename(osDirname.c_str(), "TRANSH01.THF", nullptr));
CPLFormFilenameSafe(osDirname.c_str(), "TRANSH01.THF", nullptr));
VSILFILE *fdTHF = VSIFOpenL(osTransh01THF.c_str(), "wb");
if (fdTHF == nullptr)
{
Expand Down
10 changes: 5 additions & 5 deletions frmts/adrg/srpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ char **SRPDataset::GetGENListFromTHF(const char *pszFileName)
"GEN"))
{
bFound = 1;
osGENFileName = CPLFormFilename(
osGENFileName = CPLFormFilenameSafe(
osDatasetDir.c_str(), *ptrDir, nullptr);
CPLDebug("SRP",
"Building GEN full file name : %s",
Expand Down Expand Up @@ -1168,7 +1168,7 @@ char **SRPDataset::GetGENListFromTHF(const char *pszFileName)
osName, 6))
{
bFound = 1;
osGENFileName = CPLFormFilename(
osGENFileName = CPLFormFilenameSafe(
osDirName.c_str(), *ptrDir, nullptr);
CPLDebug("SRP",
"Building GEN full file name : %s",
Expand Down Expand Up @@ -1406,7 +1406,7 @@ char **SRPDataset::GetIMGListFromGEN(const char *pszFileName,
const CPLString osGENDir(CPLGetDirnameSafe(pszFileName));

const CPLString osFileName =
CPLFormFilename(osGENDir.c_str(), osBAD.c_str(), nullptr);
CPLFormFilenameSafe(osGENDir.c_str(), osBAD.c_str(), nullptr);
VSIStatBufL sStatBuf;
if (VSIStatL(osFileName, &sStatBuf) == 0)
{
Expand All @@ -1429,8 +1429,8 @@ char **SRPDataset::GetIMGListFromGEN(const char *pszFileName,
{
if (EQUAL(*ptrDir, osBAD.c_str()))
{
osBAD =
CPLFormFilename(osGENDir.c_str(), *ptrDir, nullptr);
osBAD = CPLFormFilenameSafe(osGENDir.c_str(), *ptrDir,
nullptr);
CPLDebug("SRP", "Building IMG full file name : %s",
osBAD.c_str());
break;
Expand Down
7 changes: 4 additions & 3 deletions frmts/aigrid/aigdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ char **AIGDataset::GetFileList()

papszFileList = CSLAddString(
papszFileList,
CPLFormFilename(GetDescription(), papszCoverFiles[i], nullptr));
CPLFormFilenameSafe(GetDescription(), papszCoverFiles[i], nullptr)
.c_str());
}
CSLDestroy(papszCoverFiles);

Expand Down Expand Up @@ -663,8 +664,8 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo)
if (!EQUAL(osExt.c_str(), "clr") && !EQUAL(osExt.c_str(), "CLR"))
continue;

osClrFilename =
CPLFormFilename(psInfo->pszCoverName, papszFiles[iFile], nullptr);
osClrFilename = CPLFormFilenameSafe(psInfo->pszCoverName,
papszFiles[iFile], nullptr);
break;
}

Expand Down
41 changes: 17 additions & 24 deletions frmts/ceos2/sar_ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ GDALDataset *SAR_CEOSDataset::Open(GDALOpenInfo *poOpenInfo)
int e = 0;
while (CeosExtension[e][iFile] != nullptr)
{
char *pszFilename = nullptr;
std::string osFilename;

/* build filename */
if (EQUAL(CeosExtension[e][5], "base"))
Expand All @@ -1852,18 +1852,18 @@ GDALDataset *SAR_CEOSDataset::Open(GDALOpenInfo *poOpenInfo)

snprintf(szMadeBasename, sizeof(szMadeBasename),
CeosExtension[e][iFile], nBand);
pszFilename = CPLStrdup(
CPLFormFilename(pszPath, szMadeBasename, pszExtension));
osFilename =
CPLFormFilenameSafe(pszPath, szMadeBasename, pszExtension);
}
else if (EQUAL(CeosExtension[e][5], "ext"))
{
pszFilename = CPLStrdup(CPLFormFilename(
pszPath, pszBasename, CeosExtension[e][iFile]));
osFilename = CPLFormFilenameSafe(pszPath, pszBasename,
CeosExtension[e][iFile]);
}
else if (EQUAL(CeosExtension[e][5], "whole"))
{
pszFilename = CPLStrdup(
CPLFormFilename(pszPath, CeosExtension[e][iFile], ""));
osFilename =
CPLFormFilenameSafe(pszPath, CeosExtension[e][iFile], "");
}

// This is for SAR SLC as per the SAR Toolbox (from ASF).
Expand All @@ -1878,37 +1878,33 @@ GDALDataset *SAR_CEOSDataset::Open(GDALOpenInfo *poOpenInfo)
snprintf(szThisExtension, sizeof(szThisExtension), "%s",
CeosExtension[e][iFile]);

pszFilename = CPLStrdup(
CPLFormFilename(pszPath, pszBasename, szThisExtension));
osFilename =
CPLFormFilenameSafe(pszPath, pszBasename, szThisExtension);
}

CPLAssert(pszFilename != nullptr);
if (pszFilename == nullptr)
return nullptr;

/* try to open */
VSILFILE *process_fp = VSIFOpenL(pszFilename, "rb");
VSILFILE *process_fp = VSIFOpenL(osFilename.c_str(), "rb");

/* try upper case */
if (process_fp == nullptr)
{
for (int i = static_cast<int>(strlen(pszFilename)) - 1;
i >= 0 && pszFilename[i] != '/' && pszFilename[i] != '\\';
for (int i = static_cast<int>(osFilename.size()) - 1;
i >= 0 && osFilename[i] != '/' && osFilename[i] != '\\';
i--)
{
if (pszFilename[i] >= 'a' && pszFilename[i] <= 'z')
pszFilename[i] = pszFilename[i] - 'a' + 'A';
if (osFilename[i] >= 'a' && osFilename[i] <= 'z')
osFilename[i] = osFilename[i] - 'a' + 'A';
}

process_fp = VSIFOpenL(pszFilename, "rb");
process_fp = VSIFOpenL(osFilename.c_str(), "rb");
}

if (process_fp != nullptr)
{
CPLDebug("CEOS", "Opened %s.\n", pszFilename);
CPLDebug("CEOS", "Opened %s.\n", osFilename.c_str());

poDS->papszExtraFiles =
CSLAddString(poDS->papszExtraFiles, pszFilename);
CSLAddString(poDS->papszExtraFiles, osFilename.c_str());

CPL_IGNORE_RET_VAL(VSIFSeekL(process_fp, 0, SEEK_END));
if (ProcessData(process_fp, iFile, psVolume, -1,
Expand All @@ -1931,15 +1927,12 @@ GDALDataset *SAR_CEOSDataset::Open(GDALOpenInfo *poOpenInfo)
}

CPL_IGNORE_RET_VAL(VSIFCloseL(process_fp));
CPLFree(pszFilename);
break; /* Exit the while loop, we have this data type*/
}

CPL_IGNORE_RET_VAL(VSIFCloseL(process_fp));
}

CPLFree(pszFilename);

e++;
}
}
Expand Down
16 changes: 8 additions & 8 deletions frmts/coasp/coasp_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ GDALDataset *COASPDataset::Open(GDALOpenInfo *poOpenInfo)
/* Horizontal transmit, horizontal receive */
psChan[0] = 'h';
psChan[1] = 'h';
const char *pszFilename = CPLFormFilename(pszDir, pszBase, pszExt);
std::string osFilename = CPLFormFilenameSafe(pszDir, pszBase, pszExt);

poDS->fpBinHH = VSIFOpenL(pszFilename, "r");
poDS->fpBinHH = VSIFOpenL(osFilename.c_str(), "r");

if (poDS->fpBinHH != nullptr)
{
Expand All @@ -491,9 +491,9 @@ GDALDataset *COASPDataset::Open(GDALOpenInfo *poOpenInfo)
/* Horizontal transmit, vertical receive */
psChan[0] = 'h';
psChan[1] = 'v';
pszFilename = CPLFormFilename(pszDir, pszBase, pszExt);
osFilename = CPLFormFilenameSafe(pszDir, pszBase, pszExt);

poDS->fpBinHV = VSIFOpenL(pszFilename, "r");
poDS->fpBinHV = VSIFOpenL(osFilename.c_str(), "r");

if (poDS->fpBinHV != nullptr)
{
Expand All @@ -504,9 +504,9 @@ GDALDataset *COASPDataset::Open(GDALOpenInfo *poOpenInfo)
/* Vertical transmit, horizontal receive */
psChan[0] = 'v';
psChan[1] = 'h';
pszFilename = CPLFormFilename(pszDir, pszBase, pszExt);
osFilename = CPLFormFilenameSafe(pszDir, pszBase, pszExt);

poDS->fpBinVH = VSIFOpenL(pszFilename, "r");
poDS->fpBinVH = VSIFOpenL(osFilename.c_str(), "r");

if (poDS->fpBinVH != nullptr)
{
Expand All @@ -517,9 +517,9 @@ GDALDataset *COASPDataset::Open(GDALOpenInfo *poOpenInfo)
/* Vertical transmit, vertical receive */
psChan[0] = 'v';
psChan[1] = 'v';
pszFilename = CPLFormFilename(pszDir, pszBase, pszExt);
osFilename = CPLFormFilenameSafe(pszDir, pszBase, pszExt);

poDS->fpBinVV = VSIFOpenL(pszFilename, "r");
poDS->fpBinVV = VSIFOpenL(osFilename.c_str(), "r");

if (poDS->fpBinVV != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/dimap/dimapdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
{
CPLString osPath =
CPLGetPathSafe(osMDFilename.c_str());
osImageDSFilename = CPLFormFilename(
osImageDSFilename = CPLFormFilenameSafe(
osPath, pszDataFileHref, nullptr);
}
}
Expand Down
Loading

0 comments on commit 99e6b7a

Please sign in to comment.