diff options
| author | ruki <[email protected]> | 2019-04-27 00:02:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-26 18:17:00 +0800 |
| commit | 6e34dd3a9f72eb9c7743b1eebb10f7fbc5996025 (patch) | |
| tree | f89a7bc61fb1fa692651867ba6ed627f441035f3 /core/src | |
| parent | 695a5e99906bbf0c4f11b68c9339222af3ebfb7d (diff) | |
add os.getenvs
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/machine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/os/getenvs.c | 85 |
3 files changed, 88 insertions, 0 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 9c9cccec9..2ca2227c5 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -75,6 +75,7 @@ tb_int_t xm_os_rename(lua_State* lua); tb_int_t xm_os_exists(lua_State* lua); tb_int_t xm_os_setenv(lua_State* lua); tb_int_t xm_os_getenv(lua_State* lua); +tb_int_t xm_os_getenvs(lua_State* lua); tb_int_t xm_os_readlink(lua_State* lua); tb_int_t xm_os_filesize(lua_State* lua); tb_int_t xm_os_emptydir(lua_State* lua); @@ -167,6 +168,7 @@ static luaL_Reg const g_os_functions[] = , { "exists", xm_os_exists } , { "setenv", xm_os_setenv } , { "getenv", xm_os_getenv } +, { "getenvs", xm_os_getenvs } , { "readlink", xm_os_readlink } , { "emptydir", xm_os_emptydir } , { "strerror", xm_os_strerror } diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index fb6c1b76d..7589e4ccf 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -35,6 +35,7 @@ xmake_C_FILES += \ os/exists \ os/setenv \ os/getenv \ + os/getenvs \ os/readlink \ os/emptydir \ os/strerror \ diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c new file mode 100644 index 000000000..81e0b68c7 --- /dev/null +++ b/core/src/xmake/os/getenvs.c @@ -0,0 +1,85 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015 - 2019, TBOOX Open Source Group. + * + * @author ruki + * @file getenvs.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "getenvs" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * macros + */ + +// the separator +#ifdef TB_CONFIG_OS_WINDOWS +# define XM_OS_ENV_SEP ';' +#else +# define XM_OS_ENV_SEP ':' +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * globals + */ + +// the user environment +#ifndef TB_CONFIG_OS_WINDOWS +extern tb_char_t** environ; +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_getenvs(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // init table + lua_newtable(lua); + +#ifdef TB_CONFIG_OS_WINDOWS +#else + tb_char_t const** p = (tb_char_t const**)environ; + if (p) + { + tb_int_t i = 0; + while (*p) + { + tb_size_t n = tb_strlen(*p); + if (n) + { + lua_pushstring(lua, *p); + lua_rawseti(lua, -2, i++); + } + p++; + } + } +#endif + + // ok + return 1; +} |
