Skip to content

Commit 23863f6

Browse files
authored
Remove filesystem header (#2998)
1 parent b82d9c6 commit 23863f6

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

sherpa-onnx/csrc/file-utils.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
#include <string>
1111
#include <vector>
1212

13+
#ifdef _WIN32
14+
#include <windows.h>
15+
#else
16+
#include <limits.h>
17+
#include <stdlib.h>
18+
#endif
19+
1320
#include "sherpa-onnx/csrc/macros.h"
1421

1522
namespace sherpa_onnx {
@@ -107,4 +114,38 @@ std::vector<char> ReadFile(NativeResourceManager *mgr,
107114
}
108115
#endif
109116

117+
std::string ResolveAbsolutePath(const std::string &path) {
118+
if (path.empty()) {
119+
return path;
120+
}
121+
122+
#ifdef _WIN32
123+
// Check if path is already absolute (drive letter or UNC path)
124+
if ((path.size() > 1 && path[1] == ':') ||
125+
(path.size() > 1 && path[0] == '\\' && path[1] == '\\')) {
126+
return path;
127+
}
128+
129+
char buffer[MAX_PATH];
130+
if (GetFullPathNameA(path.c_str(), MAX_PATH, buffer, nullptr)) {
131+
return std::string(buffer);
132+
}
133+
134+
return path; // fallback on failure
135+
136+
#else
137+
// POSIX: absolute paths start with '/'
138+
if (path[0] == '/') {
139+
return path;
140+
}
141+
142+
char buffer[PATH_MAX];
143+
if (realpath(path.c_str(), buffer)) {
144+
return std::string(buffer);
145+
}
146+
147+
return path; // fallback on failure
148+
#endif
149+
}
150+
110151
} // namespace sherpa_onnx

sherpa-onnx/csrc/file-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ std::vector<char> ReadFile(NativeResourceManager *mgr,
4444
const std::string &filename);
4545
#endif
4646

47+
std::string ResolveAbsolutePath(const std::string &path);
48+
4749
} // namespace sherpa_onnx
4850

4951
#endif // SHERPA_ONNX_CSRC_FILE_UTILS_H_

sherpa-onnx/csrc/offline-funasr-nano-model.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <cmath>
1010
#include <cstdint>
1111
#include <cstring>
12-
#include <filesystem>
1312
#include <memory>
1413
#include <sstream>
1514
#include <string>
@@ -1016,10 +1015,7 @@ class OfflineFunASRNanoModel::Impl {
10161015
bool has_external_data = FileExists(data_path);
10171016

10181017
// Resolve absolute path for model file
1019-
std::string abs_model_path = model_path;
1020-
if (!model_path.empty() && !std::filesystem::path(model_path).is_absolute()) {
1021-
abs_model_path = std::filesystem::absolute(model_path).string();
1022-
}
1018+
std::string abs_model_path = ResolveAbsolutePath(model_path);
10231019

10241020
if (has_external_data) {
10251021
// When external data exists, use absolute file path to create session.

0 commit comments

Comments
 (0)