Make platform-specific code in fx_stream.h more consistent.
With commit 251ae3b655f04afbe19fb0899c0abb310ac8a412, the Windows and
non-Windows code are starting to look similar in several places. Align
the two sides to follow the same patterns and share code when possible.
Change-Id: I788f4022128144df26d5ffead265c1d62e3ee2a8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52271
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_stream.cpp b/core/fxcrt/fx_stream.cpp
index 6f30521..c02bbce 100644
--- a/core/fxcrt/fx_stream.cpp
+++ b/core/fxcrt/fx_stream.cpp
@@ -18,11 +18,21 @@
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
#include <direct.h>
-struct CFindFileDataA {
+struct FX_FolderHandle {
HANDLE m_Handle;
bool m_bEnd;
WIN32_FIND_DATAA m_FindData;
};
+#else
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+struct FX_FolderHandle {
+ ByteString m_Path;
+ DIR* m_Dir;
+};
#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
namespace {
@@ -112,25 +122,24 @@
}
FX_FolderHandle* FX_OpenFolder(const char* path) {
+ auto handle = pdfium::MakeUnique<FX_FolderHandle>();
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
- auto pData = pdfium::MakeUnique<CFindFileDataA>();
- pData->m_Handle =
+ handle->m_Handle =
FindFirstFileExA((ByteString(path) + "/*.*").c_str(), FindExInfoStandard,
- &pData->m_FindData, FindExSearchNameMatch, nullptr, 0);
- if (pData->m_Handle == INVALID_HANDLE_VALUE)
+ &handle->m_FindData, FindExSearchNameMatch, nullptr, 0);
+ if (handle->m_Handle == INVALID_HANDLE_VALUE)
return nullptr;
- pData->m_bEnd = false;
- return pData.release();
+ handle->m_bEnd = false;
#else
DIR* dir = opendir(path);
if (!dir)
return nullptr;
- auto handle = pdfium::MakeUnique<FX_FolderHandle>();
+
handle->m_Path = path;
handle->m_Dir = dir;
- return handle.release();
#endif
+ return handle.release();
}
bool FX_GetNextFile(FX_FolderHandle* handle,
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index 8ce75fd..81d010c 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -11,24 +11,7 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
-#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
-
-struct CFindFileDataA;
-typedef CFindFileDataA FX_FolderHandle;
-
-#else // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
-
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-struct FX_FolderHandle {
- ByteString m_Path;
- DIR* m_Dir;
-};
-
-#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+struct FX_FolderHandle;
FX_FolderHandle* FX_OpenFolder(const char* path);
bool FX_GetNextFile(FX_FolderHandle* handle,