!5436 Convert input path to absolute path.

Merge pull request !5436 from huangbingjian/master
pull/5436/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit 1b6f628bd0

@ -24,6 +24,7 @@
namespace mindspore {
namespace system {
namespace sha256 {
constexpr int kPathMax = 4096;
constexpr int kBitNumber = 8;
constexpr int kDigestSize = 8;
constexpr int kIterationNumber = 64;
@ -46,7 +47,17 @@ inline uint32_t sigma2(uint32_t x) { return (x >> 7 | x << 25) ^ (x >> 18 | x <<
inline uint32_t sigma3(uint32_t x) { return (x >> 17 | x << 15) ^ (x >> 19 | x << 13) ^ (x >> 10); }
std::string LoadFilePath(const std::string &path) {
std::ifstream bin_stream(path, std::ios::binary);
char real_path[kPathMax] = {0};
#if defined(_WIN32) || defined(_WIN64)
if (path.size() > kPathMax || _fullpath(real_path, path.c_str(), kPathMax) == nullptr) {
return "";
}
#else
if (path.size() > kPathMax || realpath(path.c_str(), real_path) == nullptr) {
return "";
}
#endif
std::ifstream bin_stream(real_path, std::ios::binary);
if (!bin_stream.is_open()) {
return "";
}

Loading…
Cancel
Save