From f249d118b2fe45a4f94c6c03d451a5091ff6ff2c Mon Sep 17 00:00:00 2001 From: Thakee Nathees Date: Mon, 13 Jun 2022 13:22:06 +0530 Subject: [PATCH] cwd added to search paths --- src/libs/std_path.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/std_path.c b/src/libs/std_path.c index 714ea82..c820a26 100644 --- a/src/libs/std_path.c +++ b/src/libs/std_path.c @@ -98,12 +98,17 @@ static char* tryImportPaths(PKVM* vm, char* path, char* buff) { "", ".pk", + +#ifdef _WIN32 + "\\_init.pk", +#else "/_init.pk", +#endif #ifndef PK_NO_DL #if defined(_WIN32) ".dll", - "/_init.dll", + "\\_init.dll", #elif defined(__APPLE__) ".dylib", @@ -412,14 +417,24 @@ DEF(_pathListDir, // Add the executables path and exe_path + 'libs/' as a search path for // the PKVM. void _registerSearchPaths(PKVM* vm) { + enum cwk_path_style ps = cwk_path_get_style(); + + char cwd[MAX_PATH_LEN]; + if (getcwd(cwd, sizeof(cwd)) != NULL) { + size_t len = strlen(cwd); + if (len < MAX_PATH_LEN - 1) { + cwd[len] = (ps == CWK_STYLE_WINDOWS) ? '\\' : '/'; + cwd[++len] = '\0'; + pkAddSearchPath(vm, cwd); + } + } + char buff[MAX_PATH_LEN]; if (!osGetExeFilePath(buff, MAX_PATH_LEN)) return; size_t length; cwk_path_get_dirname(buff, &length); if (length == 0) return; - enum cwk_path_style ps = cwk_path_get_style(); - // Add path separator. Otherwise pkAddSearchPath will fail an assertion. char last = buff[length - 1]; if (last != '/' && last != '\\') { @@ -430,6 +445,7 @@ void _registerSearchPaths(PKVM* vm) { // FIXME: the bellow code is hard coded. ASSERT(length + strlen("libs/") < MAX_PATH_LEN, OOPS); strcpy(buff + length, (ps == CWK_STYLE_WINDOWS) ? "libs\\" : "libs/"); + pkAddSearchPath(vm, buff); }