3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-08-09 23:51:08 +00:00

Make proc_self_dirname() work for non-ASCII paths to the binary.

This is achieved by using wide character functions to get the actual
path (there is no workaround here that will do the job) and then
changing the current directory so that no other part of Yosys has to
care about Unicode.

This works because Yosys doesn't try to use absolute paths and does
not change the current directory anywhere else.
This commit is contained in:
Catherine 2026-08-05 13:45:18 +00:00
parent 1410a14345
commit c99879e1ee

View file

@ -537,18 +537,16 @@ std::string proc_self_dirname()
#elif defined(_WIN32)
std::string proc_self_dirname()
{
int i = 0;
char longpath[MAX_PATH + 1];
char shortpath[MAX_PATH + 1];
if (!GetModuleFileNameA(0, longpath, MAX_PATH+1))
log_error("GetModuleFileName() failed.\n");
if (!GetShortPathNameA(longpath, shortpath, MAX_PATH+1))
log_error("GetShortPathName() failed.\n");
while (shortpath[i] != 0)
i++;
while (i > 0 && shortpath[i-1] != '/' && shortpath[i-1] != '\\')
shortpath[--i] = 0;
return shortpath;
wchar_t binpath[MAX_PATH + 1];
if (!GetModuleFileNameW(0, binpath, MAX_PATH+1))
log_error("GetModuleFileNameW() failed.\n");
for (int i = wcslen(binpath); i > 0; i--)
if (binpath[i] == L'\\') {
binpath[i] = 0;
break;
}
_wchdir(binpath);
return "./";
}
#elif defined(__wasm)
std::string proc_self_dirname()