Avoid c_str() in FX_OpenFolder() calls
We already have a bytestring, and all impls end up requiring a
bytestring, so avoid converting to c-style intermediate form.
Change-Id: Ie744d74d5b8a9e01cb39fed1942e109ec081d1ec
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86770
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_folder.h b/core/fxcrt/fx_folder.h
index 921fbcd..e241f22 100644
--- a/core/fxcrt/fx_folder.h
+++ b/core/fxcrt/fx_folder.h
@@ -11,7 +11,7 @@
struct FX_FolderHandle;
-FX_FolderHandle* FX_OpenFolder(const char* path);
+FX_FolderHandle* FX_OpenFolder(const ByteString& path);
bool FX_GetNextFile(FX_FolderHandle* handle,
ByteString* filename,
bool* bFolder);
diff --git a/core/fxcrt/fx_folder_posix.cpp b/core/fxcrt/fx_folder_posix.cpp
index 33472ee..d50690a 100644
--- a/core/fxcrt/fx_folder_posix.cpp
+++ b/core/fxcrt/fx_folder_posix.cpp
@@ -24,9 +24,9 @@
UnownedPtr<DIR> m_Dir;
};
-FX_FolderHandle* FX_OpenFolder(const char* path) {
+FX_FolderHandle* FX_OpenFolder(const ByteString& path) {
auto handle = std::make_unique<FX_FolderHandle>();
- DIR* dir = opendir(path);
+ DIR* dir = opendir(path.c_str());
if (!dir)
return nullptr;
diff --git a/core/fxcrt/fx_folder_windows.cpp b/core/fxcrt/fx_folder_windows.cpp
index c35aa84..7faef27 100644
--- a/core/fxcrt/fx_folder_windows.cpp
+++ b/core/fxcrt/fx_folder_windows.cpp
@@ -22,10 +22,11 @@
WIN32_FIND_DATAA m_FindData;
};
-FX_FolderHandle* FX_OpenFolder(const char* path) {
+FX_FolderHandle* FX_OpenFolder(const ByteString& path) {
auto handle = std::make_unique<FX_FolderHandle>();
+ ByteString search_path = path + "/*.*";
handle->m_Handle =
- FindFirstFileExA((ByteString(path) + "/*.*").c_str(), FindExInfoStandard,
+ FindFirstFileExA(search_path.c_str(), FindExInfoStandard,
&handle->m_FindData, FindExSearchNameMatch, nullptr, 0);
if (handle->m_Handle == INVALID_HANDLE_VALUE)
return nullptr;
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index f2f72da..00bd9cd 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -358,7 +358,7 @@
void CFPF_SkiaFontMgr::ScanPath(const ByteString& path) {
std::unique_ptr<FX_FolderHandle, FxFolderHandleCloser> handle(
- FX_OpenFolder(path.c_str()));
+ FX_OpenFolder(path));
if (!handle)
return;
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 11a28ac..13d557c 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -162,7 +162,7 @@
void CFX_FolderFontInfo::ScanPath(const ByteString& path) {
std::unique_ptr<FX_FolderHandle, FxFolderHandleCloser> handle(
- FX_OpenFolder(path.c_str()));
+ FX_OpenFolder(path));
if (!handle)
return;