summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-27 00:26:03 +0800
committerruki <[email protected]>2018-01-27 00:26:03 +0800
commit25f2dfa8baa7121817dd1d614bfd15dc2cb12f00 (patch)
treefe1376b8689e4ba908dc4f82d68782b99474d52a /core/src
parentaeae3a633365811cdc138b537942ef12e2218fd0 (diff)
add os.filesize and modify changelogs
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/machine.c2
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/os/filesize.c57
3 files changed, 60 insertions, 0 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 02bf760e7..d35631a1c 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -77,6 +77,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_filesize(lua_State* lua);
tb_int_t xm_os_emptydir(lua_State* lua);
tb_int_t xm_os_strerror(lua_State* lua);
tb_int_t xm_os_getwinsize(lua_State* lua);
@@ -165,6 +166,7 @@ static luaL_Reg const g_os_functions[] =
, { "getenv", xm_os_getenv }
, { "emptydir", xm_os_emptydir }
, { "strerror", xm_os_strerror }
+, { "filesize", xm_os_filesize }
, { "getwinsize", xm_os_getwinsize}
, { "versioninfo", xm_os_versioninfo}
#ifndef TB_CONFIG_OS_WINDOWS
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index a8afcd30d..5c11d0a62 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -35,6 +35,7 @@ xmake_C_FILES += \
os/getenv \
os/emptydir \
os/strerror \
+ os/filesize \
os/getwinsize \
os/versioninfo \
os/uid \
diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c
new file mode 100644
index 000000000..c8c3fcfe6
--- /dev/null
+++ b/core/src/xmake/os/filesize.c
@@ -0,0 +1,57 @@
+/*!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 filesize.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "filesize"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_filesize(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);
+
+ // done os.filesize(path)
+ tb_file_info_t info = {0};
+ if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE))
+ lua_pushinteger(lua, (lua_Integer)info.size);
+ else lua_pushinteger(lua, 0);
+
+ // ok
+ return 1;
+}