diff options
| author | ruki <[email protected]> | 2022-04-05 23:43:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-05 23:43:18 +0800 |
| commit | c7e96adbab7d833ca63ac4fb73061f9949a46de0 (patch) | |
| tree | bc4d9695f18c0d1525e4f8029013b5d5921faa8a /core/src | |
| parent | 4724bc52df2b22357103d6569f9664c5651a3ebe (diff) | |
add os.getpid
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/engine.c | 6 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/os/getpid.c | 54 |
3 files changed, 59 insertions, 2 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 7183140e0..e91e5ac3e 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -112,6 +112,7 @@ tb_int_t xm_os_emptydir(lua_State* lua); 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); +tb_int_t xm_os_getpid(lua_State* lua); #ifndef TB_CONFIG_OS_WINDOWS tb_int_t xm_os_getuid(lua_State* lua); tb_int_t xm_os_getgid(lua_State* lua); @@ -289,9 +290,10 @@ static luaL_Reg const g_os_functions[] = , { "syserror", xm_os_syserror } , { "filesize", xm_os_filesize } , { "getwinsize", xm_os_getwinsize} +, { "getpid", xm_os_getpid } #ifndef TB_CONFIG_OS_WINDOWS -, { "uid", xm_os_getuid } -, { "gid", xm_os_getgid } +, { "getuid", xm_os_getuid } +, { "getgid", 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 c07ba7153..d82ff51f9 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -46,6 +46,7 @@ xmake_C_FILES += \ os/getwinsize \ os/getuid \ os/getgid \ + os/getpid \ os/getown \ io/stdfile \ io/file_size \ diff --git a/core/src/xmake/os/getpid.c b/core/src/xmake/os/getpid.c new file mode 100644 index 000000000..7738652d0 --- /dev/null +++ b/core/src/xmake/os/getpid.c @@ -0,0 +1,54 @@ +/*!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 getpid.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "getpid" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#ifdef TB_CONFIG_OS_WINDOWS +# include <windows.h> +#else +# include <unistd.h> +# include <errno.h> +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_getpid(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + +#ifdef TB_CONFIG_OS_WINDOWS + lua_pushinteger(lua, (tb_int_t)GetCurrentProcessId()); +#else + lua_pushinteger(lua, (tb_int_t)getpid()); +#endif + return 1; +} + |
