From 28a89016c47a921b18321e0557ec6114046a883c Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 10 Apr 2024 23:22:26 +0800 Subject: [PATCH] ORC-1686: [C++] Avoid using std::filesystem --- c++/src/Adaptor.cc | 16 ++++++++++++++++ c++/src/Adaptor.hh.in | 1 + c++/src/Timezone.cc | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/c++/src/Adaptor.cc b/c++/src/Adaptor.cc index d9390131b6..d5dd7802f3 100644 --- a/c++/src/Adaptor.cc +++ b/c++/src/Adaptor.cc @@ -53,6 +53,12 @@ ssize_t pread(int fd, void* buf, size_t size, off_t offset) { #endif #endif +#ifdef _MSC_VER +#include +#else +#include +#endif + namespace orc { #ifdef HAS_DOUBLE_TO_STRING std::string to_string(double val) { @@ -73,4 +79,14 @@ namespace orc { return std::to_string(static_cast(val)); } #endif + + bool fileExists(const char* path) { +#ifdef _MSC_VER + return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES; +#else + struct stat st; + return stat(path, &st) == 0; +#endif + } + } // namespace orc diff --git a/c++/src/Adaptor.hh.in b/c++/src/Adaptor.hh.in index b0edc3e3e9..2cce8158e2 100644 --- a/c++/src/Adaptor.hh.in +++ b/c++/src/Adaptor.hh.in @@ -110,6 +110,7 @@ typedef SSIZE_T ssize_t; namespace orc { std::string to_string(double val); std::string to_string(int64_t val); + bool fileExists(const char* path); } #ifdef HAS_BUILTIN_OVERFLOW_CHECK diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc index fbad35fbcf..32276a850d 100644 --- a/c++/src/Timezone.cc +++ b/c++/src/Timezone.cc @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -675,7 +674,7 @@ namespace orc { if (itr != timezoneCache.end()) { return *(itr->second).get(); } - if (!std::filesystem::exists(std::filesystem::path(filename))) { + if (!fileExists(filename.c_str())) { std::stringstream ss; ss << "Time zone file " << filename << " does not exist." << " Please install IANA time zone database and set TZDIR env.";