diff --git a/nntrainer/app_context.cpp b/nntrainer/app_context.cpp index 43eaaa0b93..fbf560f761 100644 --- a/nntrainer/app_context.cpp +++ b/nntrainer/app_context.cpp @@ -393,7 +393,7 @@ void AppContext::setWorkingDirectory(const std::string &base) { } closedir(dir); - char *ret = realpath(base.c_str(), nullptr); + char *ret = getRealpath(base.c_str(), nullptr); if (ret == nullptr) { std::stringstream ss; diff --git a/nntrainer/models/model_loader.cpp b/nntrainer/models/model_loader.cpp index 3000c9f020..0a22303fb3 100644 --- a/nntrainer/models/model_loader.cpp +++ b/nntrainer/models/model_loader.cpp @@ -470,7 +470,7 @@ int ModelLoader::loadFromConfig(std::string config, NeuralNetwork &model) { model_file_context = std::make_unique(); - auto config_realpath_char = realpath(config.c_str(), nullptr); + auto config_realpath_char = getRealpath(config.c_str(), nullptr); if (config_realpath_char == nullptr) { ml_loge("failed to resolve config path to absolute path, reason: %s", strerror(errno)); diff --git a/nntrainer/utils/util_func.cpp b/nntrainer/utils/util_func.cpp index 1bd1469663..5cf04368d5 100644 --- a/nntrainer/utils/util_func.cpp +++ b/nntrainer/utils/util_func.cpp @@ -20,6 +20,10 @@ * */ +#ifdef _WIN32 +#define MAX_PATH_LENGTH 1024 +#endif + #include #include #include @@ -197,4 +201,12 @@ bool istrequal(const std::string &a, const std::string &b) { }); } +char *getRealpath(const char *__restrict name, char *__restrict resolved) { +#ifdef _WIN32 + return _fullpath(resolved, name, MAX_PATH_LENGTH); +#else + return realpath(name, resolved); +#endif +} + } // namespace nntrainer diff --git a/nntrainer/utils/util_func.h b/nntrainer/utils/util_func.h index 5147accb9d..f51e796bba 100644 --- a/nntrainer/utils/util_func.h +++ b/nntrainer/utils/util_func.h @@ -271,6 +271,16 @@ template T enum_class_or(T e1, T e2) { return static_cast(i1 | i2); } +/** + * @brief Convert a relative path into an absolute path. + * + * @param name relative path + * @param resolved variable to store the result value. + * + * @return absolute path + */ +char *getRealpath(const char *__restrict name, char *__restrict resolved); + } /* namespace nntrainer */ #endif /* __cplusplus */