From: Clifford Wolf Date: Sat, 11 Oct 2014 09:08:52 +0000 (+0200) Subject: Added proc_self_dirname() for win32 X-Git-Tag: yosys-0.4~69 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=568fee5e74093838121ea61ec15d98a111306bba;p=yosys.git Added proc_self_dirname() for win32 --- diff --git a/kernel/yosys.cc b/kernel/yosys.cc index f2492555e..921f2b383 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -28,6 +28,10 @@ # include #endif +#ifdef _WIN32 +# include +#endif + #include #include #include @@ -310,7 +314,7 @@ struct TclPass : public Pass { #if defined(__linux__) std::string proc_self_dirname() { - char path [PATH_MAX]; + char path[PATH_MAX]; ssize_t buflen = readlink("/proc/self/exe", path, sizeof(path)); if (buflen < 0) { log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno)); @@ -323,7 +327,7 @@ std::string proc_self_dirname() #include std::string proc_self_dirname() { - char * path = NULL; + char *path = NULL; uint32_t buflen = 0; while (_NSGetExecutablePath(path, &buflen) != 0) path = (char *) realloc((void *) path, buflen); @@ -334,8 +338,12 @@ std::string proc_self_dirname() #elif defined(_WIN32) std::string proc_self_dirname() { - #warning Fixme: Implement proc_self_dirname() for win32. - log_error("proc_self_dirname() is not implemented for win32 yet!\n"); + char path[MAX_PATH+1]; + if (!GetModuleFileName(0, path, MAX_PATH+1)) + log_error("GetModuleFileName() failed.\n"); + for (int i = strlen(path)-1; i >= 0 && path[i] != '/' && path[i] != '\\' ; i--) + path[i] = 0; + return std::string(path); } #elif defined(EMSCRIPTEN) std::string proc_self_dirname()