Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Sep 2025 18:50:21 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 7f6da651e23f - stable/14 - flua: add posix.unistd.dup2()
Message-ID:  <202509111850.58BIoLLE092864@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=7f6da651e23f4fbafac04ad77f1bdf74deec5882

commit 7f6da651e23f4fbafac04ad77f1bdf74deec5882
Author:     Isaac Freund <ifreund@freebsdfoundation.org>
AuthorDate: 2025-05-05 09:03:37 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-09-11 15:09:58 +0000

    flua: add posix.unistd.dup2()
    
    Reviewed by:    emaste
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D50176
    
    (cherry picked from commit 909aa6781340f8c0b4ae01c6366bf1556ee2d1be)
---
 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 47a1354aede9..43b9ee83673c 100644
--- a/libexec/flua/modules/lposix.c
+++ b/libexec/flua/modules/lposix.c
@@ -174,6 +174,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)
 {
@@ -488,6 +521,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),



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509111850.58BIoLLE092864>