From d4aab4ff42e4032f848e0c6f048aaa61cb7db18b Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Mon, 22 May 2017 15:22:16 +0800 Subject: add os.gid() --- core/src/xmake/makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'core/src/xmake/makefile') diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index b1b29ed83..f2be6405d 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -38,6 +38,7 @@ xmake_C_FILES += \ os/getwinsize \ os/versioninfo \ os/uid \ + os/gid \ path/relative \ path/absolute \ path/translate \ -- cgit v1.3.1 From b8e4fb467d8de881749e3bc77493728a642ff145 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Mon, 22 May 2017 18:33:04 +0800 Subject: add os.getown --- core/src/xmake/machine.c | 2 ++ core/src/xmake/makefile | 1 + core/src/xmake/os/getown.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 core/src/xmake/os/getown.c (limited to 'core/src/xmake/makefile') diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index a1ae497ec..ccfd91254 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -84,6 +84,7 @@ tb_int_t xm_os_versioninfo(lua_State* lua); #ifndef TB_CONFIG_OS_WINDOWS tb_int_t xm_os_uid(lua_State* lua); tb_int_t xm_os_gid(lua_State* lua); +tb_int_t xm_os_getown(lua_State* lua); #endif // the path functions @@ -148,6 +149,7 @@ static luaL_Reg const g_os_functions[] = #ifndef TB_CONFIG_OS_WINDOWS , { "uid", xm_os_uid } , { "gid", xm_os_gid } +, { "getown", xm_os_getown } #endif , { tb_null, tb_null } }; diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index f2be6405d..c7b1ffc29 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -39,6 +39,7 @@ xmake_C_FILES += \ os/versioninfo \ os/uid \ os/gid \ + os/getown \ path/relative \ path/absolute \ path/translate \ diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c new file mode 100644 index 000000000..aa4e2de66 --- /dev/null +++ b/core/src/xmake/os/getown.c @@ -0,0 +1,71 @@ +/*!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 - 2017, TBOOX Open Source Group. + * + * @author TitanSnow + * @file getown.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "getown" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#ifndef TB_CONFIG_OS_WINDOWS +# include +# include + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +// get owner by a given path +tb_int_t xm_os_getown(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the pathname + tb_char_t const* pathname = luaL_checkstring(lua, 1); + tb_check_return_val(pathname, 0); + + // get stat + struct stat sts; + if(stat(pathname, &sts) != 0) + return 0; + + // push + lua_newtable(lua); + lua_pushstring(lua, "uid"); + lua_pushinteger(lua, sts.st_uid); + lua_settable(lua, -3); + lua_pushstring(lua, "gid"); + lua_pushinteger(lua, sts.st_gid); + lua_settable(lua, -3); + + // ok + return 1; +} + +#endif -- cgit v1.3.1