diff options
| author | ruki <[email protected]> | 2018-09-29 20:17:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-29 20:17:46 +0800 |
| commit | 27658956cfe3f4223753059a3324a9b320320ad7 (patch) | |
| tree | 44406ce7a61553f0af9086e818bb79d5a11682d7 /core | |
| parent | 2f283df97b8527cc69c3139efec7ad27a6851611 (diff) | |
add os.ln and os.islink
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/xmake/machine.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 2 | ||||
| -rw-r--r-- | core/src/xmake/os/islink.c | 65 | ||||
| -rw-r--r-- | core/src/xmake/os/link.c | 55 |
4 files changed, 126 insertions, 0 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index a9541e410..f54ab9df3 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -60,6 +60,7 @@ typedef struct __xm_machine_t // the os functions tb_int_t xm_os_argv(lua_State* lua); tb_int_t xm_os_find(lua_State* lua); +tb_int_t xm_os_link(lua_State* lua); tb_int_t xm_os_isdir(lua_State* lua); tb_int_t xm_os_rmdir(lua_State* lua); tb_int_t xm_os_mkdir(lua_State* lua); @@ -70,6 +71,7 @@ tb_int_t xm_os_sleep(lua_State* lua); tb_int_t xm_os_mclock(lua_State* lua); tb_int_t xm_os_curdir(lua_State* lua); tb_int_t xm_os_tmpdir(lua_State* lua); +tb_int_t xm_os_islink(lua_State* lua); tb_int_t xm_os_isfile(lua_State* lua); tb_int_t xm_os_rmfile(lua_State* lua); tb_int_t xm_os_cpfile(lua_State* lua); @@ -149,6 +151,7 @@ static luaL_Reg const g_os_functions[] = { { "argv", xm_os_argv } , { "find", xm_os_find } +, { "link", xm_os_link } , { "isdir", xm_os_isdir } , { "rmdir", xm_os_rmdir } , { "mkdir", xm_os_mkdir } @@ -159,6 +162,7 @@ static luaL_Reg const g_os_functions[] = , { "mclock", xm_os_mclock } , { "curdir", xm_os_curdir } , { "tmpdir", xm_os_tmpdir } +, { "islink", xm_os_islink } , { "isfile", xm_os_isfile } , { "rmfile", xm_os_rmfile } , { "cpfile", xm_os_cpfile } diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 1b5a939cc..cd05a8b6a 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -16,6 +16,7 @@ xmake_C_FILES += \ machine \ os/argv \ os/find \ + os/link \ os/isdir \ os/rmdir \ os/mkdir \ @@ -27,6 +28,7 @@ xmake_C_FILES += \ os/curdir \ os/tmpdir \ os/isfile \ + os/islink \ os/rmfile \ os/cpfile \ os/rename \ diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c new file mode 100644 index 000000000..3af6166ff --- /dev/null +++ b/core/src/xmake/os/islink.c @@ -0,0 +1,65 @@ +/*!The Make-like Build Utility based on Lua + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 - 2018, TBOOX Open Source Group. + * + * @author ruki + * @file islink.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "islink" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#ifndef TB_CONFIG_OS_WINDOWS +# include <sys/stat.h> +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_islink(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the path + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + // is link? +#if defined(TB_CONFIG_OS_WINDOWS) + lua_pushboolean(lua, tb_false); +#elif defined(TB_CONFIG_POSIX_HAVE_STAT64) + struct stat64 st = {0}; + lua_pushboolean(lua, !lstat64(path, &st) && S_ISLNK(st.st_mode)); +#else + struct stat st = {0}; + lua_pushboolean(lua, !lstat(path, &st) && S_ISLNK(st.st_mode)); +#endif + + // ok + return 1; +} diff --git a/core/src/xmake/os/link.c b/core/src/xmake/os/link.c new file mode 100644 index 000000000..cf5cf6b7d --- /dev/null +++ b/core/src/xmake/os/link.c @@ -0,0 +1,55 @@ +/*!The Make-like Build Utility based on Lua + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 - 2018, TBOOX Open Source Group. + * + * @author ruki + * @file link.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "link" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_link(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the source and destination + tb_char_t const* src = luaL_checkstring(lua, 1); + tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_check_return_val(src && dst, 0); + + // do os.link(src, dst) + lua_pushboolean(lua, tb_file_link(src, dst)); + + // ok + return 1; +} |
