git: 909aa6781340 - main - flua: add posix.unistd.dup2()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 12 May 2025 13:40:40 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=909aa6781340f8c0b4ae01c6366bf1556ee2d1be
commit 909aa6781340f8c0b4ae01c6366bf1556ee2d1be
Author: Isaac Freund <ifreund@freebsdfoundation.org>
AuthorDate: 2025-05-05 09:03:37 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-05-12 13:40:09 +0000
flua: add posix.unistd.dup2()
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50176
---
libexec/flua/modules/lposix.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c
index d69f1aa546c1..a706adf2c353 100644
--- a/libexec/flua/modules/lposix.c
+++ b/libexec/flua/modules/lposix.c
@@ -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),