summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-31 23:32:36 +0800
committerruki <[email protected]>2022-07-31 23:32:36 +0800
commitbb28bbb01c73ab1d7e455479f3338466a983d7d4 (patch)
treec77b6942e68f972e01ef835ab794c42f4962c27e /core/src
parent1f27cde3a9c4b7e6866d677a2dd4e8a9cd6027e6 (diff)
add os.touch
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c2
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/os/touch.c49
3 files changed, 52 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 6458dee1c..b3d798e4f 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -98,6 +98,7 @@ 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_touch(lua_State* lua);
tb_int_t xm_os_rmfile(lua_State* lua);
tb_int_t xm_os_cpfile(lua_State* lua);
tb_int_t xm_os_rename(lua_State* lua);
@@ -319,6 +320,7 @@ static luaL_Reg const g_os_functions[] =
, { "tmpdir", xm_os_tmpdir }
, { "islink", xm_os_islink }
, { "isfile", xm_os_isfile }
+, { "touch", xm_os_touch }
, { "rmfile", xm_os_rmfile }
, { "cpfile", xm_os_cpfile }
, { "rename", xm_os_rename }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 44fb9a0b3..5ce8942bb 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -30,6 +30,7 @@ xmake_C_FILES += \
os/tmpdir \
os/isfile \
os/islink \
+ os/touch \
os/rmfile \
os/cpfile \
os/rename \
diff --git a/core/src/xmake/os/touch.c b/core/src/xmake/os/touch.c
new file mode 100644
index 000000000..04b655908
--- /dev/null
+++ b/core/src/xmake/os/touch.c
@@ -0,0 +1,49 @@
+/*!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-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file touch.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "touch"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_touch(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ tb_char_t const* path = luaL_checkstring(lua, 1);
+ tb_check_return_val(path, 0);
+
+ tb_time_t atime = (tb_time_t)luaL_checknumber(lua, 2);
+ tb_time_t mtime = (tb_time_t)luaL_checknumber(lua, 3);
+
+ lua_pushboolean(lua, tb_file_touch(path, atime, mtime));
+ return 1;
+}