Skip to content

Commit

Permalink
Allow as CWD for preopen
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Jun 19, 2019
1 parent 390e8e0 commit 82ad4c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ inline static std::string wstring_to_string(const std::wstring &wstr)
#endif

#ifdef _WASM
inline static std::string get_cwd_from_env()
inline static std::string get_cwd_from_env(const char* default_pwd)
{
char* value = getenv("PWD");
if (!value) return "/";
if (!value) return default_pwd;
return value;
}
#endif
Expand All @@ -68,8 +68,8 @@ namespace Sass {
{
#ifdef _WASM
// the WASI does not implement getcwd() yet --
// check the environment variables or default to "/".
std::string cwd = get_cwd_from_env();
// check the environment variables or default to "./".
std::string cwd = get_cwd_from_env("./");
#else
const size_t wd_len = 4096;
#ifndef _WIN32
Expand Down Expand Up @@ -189,7 +189,9 @@ namespace Sass {
while((pos = path.find("/./", pos)) != std::string::npos) path.erase(pos, 2);

// remove all leading and trailing self references
while(path.size() >= 2 && path[0] == '.' && path[1] == '/') path.erase(0, 2);
#ifndef PREOPEN_COMPATIBLE
while(path.size() >= 2 && path[0] == '.' && path[1] == '/') path.erase(0, 2);
#endif
while((pos = path.length()) > 1 && path[pos - 2] == '/' && path[pos - 1] == '.') path.erase(pos - 2);


Expand Down
2 changes: 2 additions & 0 deletions src/sass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
// enable loading of plugins for non-wasm
#ifndef _WASM
# define ENABLE_LOAD_PLUGINS
#else
# define PREOPEN_COMPATIBLE
#endif

// path separation char
Expand Down

0 comments on commit 82ad4c5

Please sign in to comment.