mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
flua: add posix.unistd.dup2()
Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50176
This commit is contained in:
parent
4bc53dc71c
commit
909aa67813
1 changed files with 34 additions and 0 deletions
|
|
@ -165,6 +165,39 @@ err:
|
|||
|
||||
}
|
||||
|
||||
static int
|
||||
lua_dup2(lua_State *L)
|
||||
{
|
||||
int error, oldd, newd;
|
||||
|
||||
enforce_max_args(L, 2);
|
||||
|
||||
oldd = luaL_checkinteger(L, 1);
|
||||
if (oldd < 0) {
|
||||
error = EBADF;
|
||||
goto err;
|
||||
}
|
||||
|
||||
newd = luaL_checkinteger(L, 2);
|
||||
if (newd < 0) {
|
||||
error = EBADF;
|
||||
goto err;
|
||||
}
|
||||
|
||||
error = dup2(oldd, newd);
|
||||
if (error >= 0) {
|
||||
lua_pushinteger(L, error);
|
||||
return (1);
|
||||
}
|
||||
|
||||
error = errno;
|
||||
err:
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, strerror(error));
|
||||
lua_pushinteger(L, error);
|
||||
return (3);
|
||||
}
|
||||
|
||||
static int
|
||||
lua_fnmatch(lua_State *L)
|
||||
{
|
||||
|
|
@ -479,6 +512,7 @@ static const struct luaL_Reg unistdlib[] = {
|
|||
REG_SIMPLE(_exit),
|
||||
REG_SIMPLE(chown),
|
||||
REG_DEF(close, lua_pclose),
|
||||
REG_SIMPLE(dup2),
|
||||
REG_SIMPLE(fork),
|
||||
REG_SIMPLE(getpid),
|
||||
REG_SIMPLE(pipe),
|
||||
|
|
|
|||
Loading…
Reference in a new issue