yhirose 1 year ago
parent
commit
2514ebc20f
2 changed files with 11 additions and 4 deletions
  1. 0 4
      httplib.h
  2. 11 0
      test/test.cc

+ 0 - 4
httplib.h

@@ -2526,12 +2526,8 @@ inline std::string base64_encode(const std::string &in) {
 }
 
 inline bool is_file(const std::string &path) {
-#ifdef _WIN32
-  return _access_s(path.c_str(), 0) == 0;
-#else
   struct stat st;
   return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode);
-#endif
 }
 
 inline bool is_dir(const std::string &path) {

+ 11 - 0
test/test.cc

@@ -7561,3 +7561,14 @@ TEST(UniversalClientImplTest, Ipv6LiteralAddress) {
              CLIENT_PRIVATE_KEY_FILE);
   EXPECT_EQ(cli.port(), port);
 }
+
+TEST(FileSystemTest, FileAndDirExistenceCheck) {
+  auto file_path = "./www/dir/index.html";
+  auto dir_path = "./www/dir";
+
+  EXPECT_TRUE(detail::is_file(file_path));
+  EXPECT_FALSE(detail::is_dir(file_path));
+
+  EXPECT_FALSE(detail::is_file(dir_path));
+  EXPECT_TRUE(detail::is_dir(dir_path));
+}