3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-07 01:54:10 +00:00

Added proc_self_dirname() for win32

This commit is contained in:
Clifford Wolf 2014-10-11 11:08:52 +02:00
parent e8c66ee36b
commit 568fee5e74

View file

@ -28,6 +28,10 @@
# include <dlfcn.h> # include <dlfcn.h>
#endif #endif
#ifdef _WIN32
# include <windows.h>
#endif
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
@ -310,7 +314,7 @@ struct TclPass : public Pass {
#if defined(__linux__) #if defined(__linux__)
std::string proc_self_dirname() std::string proc_self_dirname()
{ {
char path [PATH_MAX]; char path[PATH_MAX];
ssize_t buflen = readlink("/proc/self/exe", path, sizeof(path)); ssize_t buflen = readlink("/proc/self/exe", path, sizeof(path));
if (buflen < 0) { if (buflen < 0) {
log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno)); log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno));
@ -323,7 +327,7 @@ std::string proc_self_dirname()
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
std::string proc_self_dirname() std::string proc_self_dirname()
{ {
char * path = NULL; char *path = NULL;
uint32_t buflen = 0; uint32_t buflen = 0;
while (_NSGetExecutablePath(path, &buflen) != 0) while (_NSGetExecutablePath(path, &buflen) != 0)
path = (char *) realloc((void *) path, buflen); path = (char *) realloc((void *) path, buflen);
@ -334,8 +338,12 @@ std::string proc_self_dirname()
#elif defined(_WIN32) #elif defined(_WIN32)
std::string proc_self_dirname() std::string proc_self_dirname()
{ {
#warning Fixme: Implement proc_self_dirname() for win32. char path[MAX_PATH+1];
log_error("proc_self_dirname() is not implemented for win32 yet!\n"); 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) #elif defined(EMSCRIPTEN)
std::string proc_self_dirname() std::string proc_self_dirname()