Skip to content

Commit eccfdbf

Browse files
committed
BugFix get module path
1 parent 61d4ccd commit eccfdbf

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/common/directory.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ class directory {
2626
auto len = GetModuleFileName(NULL, temp, MAX_PATH);
2727
if (0 == len)
2828
throw std::runtime_error(moon::format("module_path error: %u", GetLastError()));
29-
std::string res(temp, len);
30-
fs::path p = fs::path(res);
29+
fs::path p = fs::path(std::string_view(temp, len));
3130
#elif TARGET_PLATFORM == PLATFORM_MAC
3231
char temp[1024];
33-
uint32_t bufferSize = sizeof(temp);
34-
if (_NSGetExecutablePath(temp, &bufferSize) != 0)
32+
uint32_t len = sizeof(temp);
33+
if (_NSGetExecutablePath(temp, &len) != 0)
3534
throw std::runtime_error("module_path error: buffer too small");
36-
size_t actual_len = strlen(temp);
37-
std::string res(temp, actual_len);
38-
fs::path p = fs::canonical(fs::path(res));
35+
fs::path p = fs::canonical(fs::path(temp));
3936
#else
4037
char temp[1024];
4138
auto len = readlink("/proc/self/exe", temp, sizeof(temp) - 1);

0 commit comments

Comments
 (0)