diff options
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/engine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/os/access.c | 25 |
2 files changed, 27 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 9ceabd156..a77cc4a9b 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -151,6 +151,7 @@ tb_int_t xm_os_cpuinfo(lua_State *lua); tb_int_t xm_os_meminfo(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_access(lua_State *lua); tb_int_t xm_os_emptydir(lua_State *lua); tb_int_t xm_os_syserror(lua_State *lua); tb_int_t xm_os_strerror(lua_State *lua); @@ -446,6 +447,7 @@ static luaL_Reg const g_os_functions[] = { { "fscase", xm_os_fscase }, { "rename", xm_os_rename }, { "exists", xm_os_exists }, + { "access", xm_os_access }, { "setenv", xm_os_setenv }, { "getenv", xm_os_getenv }, { "getenvs", xm_os_getenvs }, diff --git a/core/src/xmake/os/access.c b/core/src/xmake/os/access.c new file mode 100644 index 000000000..51bf00607 --- /dev/null +++ b/core/src/xmake/os/access.c @@ -0,0 +1,25 @@ +#include "prefix.h" + +tb_int_t xm_os_access(lua_State *lua) { + tb_assert_and_check_return_val(lua, 0); + + // check + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const* mode_str = luaL_checkstring(lua, 2); + tb_check_return_val(path && mode_str, 0); + + // parse mode + tb_size_t mode = 0; + while (*mode_str) { + switch (*mode_str) { + case 'r': mode |= TB_FILE_MODE_RO; break; + case 'w': mode |= TB_FILE_MODE_WO; break; + case 'x': mode |= TB_FILE_MODE_EXEC; break; + } + mode_str++; + } + + // check access + lua_pushboolean(lua, tb_file_access(path, mode)); + return 1; +} |
