Skip to content

Commit 62bd71c

Browse files
Echo-NieManfredss
authored andcommitted
add Windows logic for help.h (PaddlePaddle#76259)
1 parent 593e359 commit 62bd71c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

paddle/fluid/inference/api/helper.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
#pragma once
1616
#include <glog/logging.h>
1717
#include <sys/stat.h>
18-
18+
#ifdef _WIN32
19+
#include <windows.h>
20+
#include <codecvt>
21+
#endif
1922
#include <fstream>
2023
#if !defined(_WIN32)
2124
#include <sys/time.h>
@@ -425,20 +428,34 @@ static void PrintTime(int batch_size,
425428
}
426429

427430
static bool IsFileExists(const std::string &path) {
428-
std::ifstream file(path);
431+
#ifdef _WIN32
432+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
433+
std::wstring wpath = converter.from_bytes(path);
434+
std::ifstream file(wpath, std::ios::binary);
435+
#else
436+
std::ifstream file(path, std::ios::binary);
437+
#endif
429438
bool exists = file.is_open();
430439
file.close();
431440
return exists;
432441
}
433442

434443
static bool IsDirectory(const std::string &path) {
444+
#ifdef _WIN32
445+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
446+
std::wstring wpath = converter.from_bytes(path);
447+
DWORD attr = GetFileAttributesW(wpath.c_str());
448+
if (attr == INVALID_FILE_ATTRIBUTES) return false;
449+
return (attr & FILE_ATTRIBUTE_DIRECTORY);
450+
#else
435451
struct stat info;
436452
if (stat(path.c_str(), &info) != 0) {
437453
return false;
438454
} else if (info.st_mode & S_IFDIR) {
439455
return true;
440456
}
441457
return false;
458+
#endif
442459
}
443460

444461
void RegisterAllCustomOperator(bool use_pir);

0 commit comments

Comments
 (0)