diff options
| author | ruki <[email protected]> | 2019-04-27 00:07:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-26 18:46:51 +0800 |
| commit | 2c52aa3ecd3c16da67a266d5a63ded6c4bd9fdd8 (patch) | |
| tree | 4f4d9630001b9dea0dcfa0f19fa793c30a7f25b4 | |
| parent | 6e34dd3a9f72eb9c7743b1eebb10f7fbc5996025 (diff) | |
impl os.getenvs for windows
| -rw-r--r-- | core/src/xmake/os/getenvs.c | 49 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 3 |
2 files changed, 50 insertions, 2 deletions
diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index 81e0b68c7..f504ebab3 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -62,14 +62,59 @@ tb_int_t xm_os_getenvs(lua_State* lua) lua_newtable(lua); #ifdef TB_CONFIG_OS_WINDOWS + tb_wchar_t const* p = (tb_wchar_t const*)tb_kernel32()->GetEnvironmentStringsW(); + if (p) + { + tb_int_t i = 0; + tb_char_t* data = tb_null; + tb_size_t maxn = 0; + tb_char_t line[TB_PATH_MAXN]; + tb_size_t n = 0; + while (*p) + { + n = tb_wcslen(p); + if (n + 1 < tb_arrayn(line)) + { + if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) + { + lua_pushstring(lua, line); + lua_rawseti(lua, -2, i++); + } + } + else + { + if (!data) + { + maxn = n + 1; + data = (tb_char_t*)tb_malloc(maxn); + } + else if (n >= maxn) + { + maxn = n + TB_PATH_MAXN + 1; + data = (tb_char_t*)tb_ralloc(data, maxn); + } + tb_assert_and_check_break(data); + + if (tb_wtoa(data, p, maxn) >= 0) + { + lua_pushstring(lua, data); + lua_rawseti(lua, -2, i++); + } + } + p += n + 1; + } + if (data && data != line) tb_free(data); + data = tb_null; + } #else tb_char_t const** p = (tb_char_t const**)environ; if (p) { - tb_int_t i = 0; + tb_int_t i = 0; + tb_size_t n = 0; while (*p) { - tb_size_t n = tb_strlen(*p); + n = tb_strlen(*p); if (n) { lua_pushstring(lua, *p); diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ee0404971..c20b8ac25 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -907,6 +907,9 @@ function os.getenvs() local p = line:find('=', 1, true) if p then local key = line:sub(1, p - 1):trim() + if os.host() == "windows" then + key = key:upper() + end local values = line:sub(p + 1):trim() if #key > 0 then envs[key] = values |
