summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-05 23:37:32 +0800
committerruki <[email protected]>2022-04-05 23:37:32 +0800
commit4724bc52df2b22357103d6569f9664c5651a3ebe (patch)
treecd184820e9d10c707e18a5ed15d0594e54306f6f
parent0125ddfe80f8d8fee5ea55fe1ed2f45acf188997 (diff)
improve get uid
-rw-r--r--core/src/xmake/engine.c8
-rw-r--r--core/src/xmake/makefile4
-rw-r--r--core/src/xmake/os/getgid.c (renamed from core/src/xmake/os/gid.c)24
-rw-r--r--core/src/xmake/os/getuid.c (renamed from core/src/xmake/os/uid.c)24
-rw-r--r--xmake/core/base/os.lua20
5 files changed, 40 insertions, 40 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 005d2eebe..7183140e0 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -113,8 +113,8 @@ tb_int_t xm_os_syserror(lua_State* lua);
tb_int_t xm_os_strerror(lua_State* lua);
tb_int_t xm_os_getwinsize(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_getuid(lua_State* lua);
+tb_int_t xm_os_getgid(lua_State* lua);
tb_int_t xm_os_getown(lua_State* lua);
#endif
@@ -290,8 +290,8 @@ static luaL_Reg const g_os_functions[] =
, { "filesize", xm_os_filesize }
, { "getwinsize", xm_os_getwinsize}
#ifndef TB_CONFIG_OS_WINDOWS
-, { "uid", xm_os_uid }
-, { "gid", xm_os_gid }
+, { "uid", xm_os_getuid }
+, { "gid", xm_os_getgid }
, { "getown", xm_os_getown }
#endif
, { tb_null, tb_null }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 2203b81b7..c07ba7153 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -44,8 +44,8 @@ xmake_C_FILES += \
os/strerror \
os/filesize \
os/getwinsize \
- os/uid \
- os/gid \
+ os/getuid \
+ os/getgid \
os/getown \
io/stdfile \
io/file_size \
diff --git a/core/src/xmake/os/gid.c b/core/src/xmake/os/getgid.c
index 8a05cd145..a089f855e 100644
--- a/core/src/xmake/os/gid.c
+++ b/core/src/xmake/os/getgid.c
@@ -15,14 +15,14 @@
* Copyright (C) 2015-present, TBOOX Open Source Group.
*
* @author TitanSnow
- * @file gid.c
+ * @file getgid.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "gid"
+#define TB_TRACE_MODULE_NAME "getgid"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -40,7 +40,7 @@
#ifndef TB_CONFIG_OS_WINDOWS
// get & set gid
-tb_int_t xm_os_gid(lua_State* lua)
+tb_int_t xm_os_getgid(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
@@ -52,14 +52,14 @@ tb_int_t xm_os_gid(lua_State* lua)
{
if (lua_istable(lua, 1))
{
- // os.gid({["rgid"] = rgid, ["egid"] = egid})
+ // os.getgid({["rgid"] = rgid, ["egid"] = egid})
lua_getfield(lua, 1, "rgid");
lua_getfield(lua, 1, "egid");
if (!lua_isnil(lua, -1))
{
if (!lua_isnumber(lua, -1))
{
- lua_pushfstring(lua, "invalid field type(%s) in `egid` for os.gid", luaL_typename(lua, -1));
+ lua_pushfstring(lua, "invalid field type(%s) in `egid` for os.getgid", luaL_typename(lua, -1));
lua_error(lua);
return 0;
}
@@ -70,7 +70,7 @@ tb_int_t xm_os_gid(lua_State* lua)
{
if (!lua_isnumber(lua, -1))
{
- lua_pushfstring(lua, "invalid field type(%s) in `rgid` for os.gid", luaL_typename(lua, -1));
+ lua_pushfstring(lua, "invalid field type(%s) in `rgid` for os.getgid", luaL_typename(lua, -1));
lua_error(lua);
return 0;
}
@@ -80,24 +80,24 @@ tb_int_t xm_os_gid(lua_State* lua)
}
else if (lua_isnumber(lua, 1))
{
- // os.gid(gid)
+ // os.getgid(gid)
rgidset = egidset = (tb_int_t)lua_tonumber(lua, 1);
}
else
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 1));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getgid", luaL_typename(lua, 1));
lua_error(lua);
return 0;
}
}
else if (argc == 2)
{
- // os.gid(rgid, egid)
+ // os.getgid(rgid, egid)
if (!lua_isnil(lua, 1))
{
if (!lua_isnumber(lua, 1))
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 1));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getgid", luaL_typename(lua, 1));
lua_error(lua);
return 0;
}
@@ -107,7 +107,7 @@ tb_int_t xm_os_gid(lua_State* lua)
{
if (!lua_isnumber(lua, 2))
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 2));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getgid", luaL_typename(lua, 2));
lua_error(lua);
return 0;
}
@@ -116,7 +116,7 @@ tb_int_t xm_os_gid(lua_State* lua)
}
else if (argc != 0)
{
- lua_pushstring(lua, "invalid argument count for os.gid");
+ lua_pushstring(lua, "invalid argument count for os.getgid");
lua_error(lua);
return 0;
}
diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/getuid.c
index bdaee036f..9c2c2fa2c 100644
--- a/core/src/xmake/os/uid.c
+++ b/core/src/xmake/os/getuid.c
@@ -15,14 +15,14 @@
* Copyright (C) 2015-present, TBOOX Open Source Group.
*
* @author TitanSnow
- * @file uid.c
+ * @file getuid.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "uid"
+#define TB_TRACE_MODULE_NAME "getuid"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -40,7 +40,7 @@
#ifndef TB_CONFIG_OS_WINDOWS
// get & set uid
-tb_int_t xm_os_uid(lua_State* lua)
+tb_int_t xm_os_getuid(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
@@ -52,14 +52,14 @@ tb_int_t xm_os_uid(lua_State* lua)
{
if (lua_istable(lua, 1))
{
- // os.uid({["ruid"] = ruid, ["euid"] = euid})
+ // os.getuid({["ruid"] = ruid, ["euid"] = euid})
lua_getfield(lua, 1, "ruid");
lua_getfield(lua, 1, "euid");
if (!lua_isnil(lua, -1))
{
if (!lua_isnumber(lua, -1))
{
- lua_pushfstring(lua, "invalid field type(%s) in `euid` for os.uid", luaL_typename(lua, -1));
+ lua_pushfstring(lua, "invalid field type(%s) in `euid` for os.getuid", luaL_typename(lua, -1));
lua_error(lua);
return 0;
}
@@ -70,7 +70,7 @@ tb_int_t xm_os_uid(lua_State* lua)
{
if (!lua_isnumber(lua, -1))
{
- lua_pushfstring(lua, "invalid field type(%s) in `ruid` for os.uid", luaL_typename(lua, -1));
+ lua_pushfstring(lua, "invalid field type(%s) in `ruid` for os.getuid", luaL_typename(lua, -1));
lua_error(lua);
return 0;
}
@@ -80,24 +80,24 @@ tb_int_t xm_os_uid(lua_State* lua)
}
else if (lua_isnumber(lua, 1))
{
- // os.uid(uid)
+ // os.getuid(uid)
ruidset = euidset = (tb_int_t)lua_tonumber(lua, 1);
}
else
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 1));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getuid", luaL_typename(lua, 1));
lua_error(lua);
return 0;
}
}
else if (argc == 2)
{
- // os.uid(ruid, euid)
+ // os.getuid(ruid, euid)
if (!lua_isnil(lua, 1))
{
if (!lua_isnumber(lua, 1))
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 1));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getuid", luaL_typename(lua, 1));
lua_error(lua);
return 0;
}
@@ -107,7 +107,7 @@ tb_int_t xm_os_uid(lua_State* lua)
{
if (!lua_isnumber(lua, 2))
{
- lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 2));
+ lua_pushfstring(lua, "invalid argument type(%s) for os.getuid", luaL_typename(lua, 2));
lua_error(lua);
return 0;
}
@@ -116,7 +116,7 @@ tb_int_t xm_os_uid(lua_State* lua)
}
else if (argc != 0)
{
- lua_pushstring(lua, "invalid argument count for os.uid");
+ lua_pushstring(lua, "invalid argument count for os.getuid");
lua_error(lua);
return 0;
}
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 823d3d009..39530eb0f 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -31,8 +31,8 @@ local string = require("base/string")
local process = require("base/process")
-- save original interfaces
-os._uid = os._uid or os.uid
-os._gid = os._gid or os.gid
+os._getuid = os._getuid or os.getuid or os.uid -- for old core
+os._getgid = os._getgid or os.getgid or os.gid
os._exit = os._exit or os.exit
os._mkdir = os._mkdir or os.mkdir
os._rmdir = os._rmdir or os.rmdir
@@ -609,7 +609,7 @@ function os.tmpdir(opt)
local subdir = os._TMPSUBDIR
if not subdir then
local name = "." .. xmake._NAME
- subdir = path.join((os._FAKEROOT and (name .. "fake") or name) .. (os.uid().euid or ""), os.date("%y%m%d"))
+ subdir = path.join((os._FAKEROOT and (name .. "fake") or name) .. (os.getuid().euid or ""), os.date("%y%m%d"))
os._TMPSUBDIR = subdir
end
@@ -974,26 +974,26 @@ function os.nuldev(input)
end
-- get uid
-function os.uid(...)
+function os.getuid(...)
os._UID = {}
- if os._uid then
- os._UID = os._uid(...) or {}
+ if os._getuid then
+ os._UID = os._getuid(...) or {}
end
return os._UID
end
-- get gid
-function os.gid(...)
+function os.getgid(...)
os._GID = {}
- if os._gid then
- os._GID = os._gid(...) or {}
+ if os._getgid then
+ os._GID = os._getgid(...) or {}
end
return os._GID
end
-- check the current command is running as root
function os.isroot()
- return os.uid().euid == 0
+ return os.getuid().euid == 0
end
-- is case-insensitive filesystem?