shithub: lu9-p9

Download patch

ref: 4ca6bbbb60081fdb40b442ae6bd3cd3f86ceed64
parent: 577fc541f5931b74c34b7c6d10bebd7aece5a952
author: kvik <kvik@a-b.xyz>
date: Sun Apr 18 17:24:30 EDT 2021

fs: implement p9.pipe()

--- a/fs.c
+++ b/fs.c
@@ -313,3 +313,15 @@
 	lua_pushstring(L, buf);
 	return 1;
 }
+
+static int
+p9_pipe(lua_State *L)
+{
+	int fd[2];
+	
+	if(pipe(fd) == -1)
+		return error(L, "pipe: %r");
+	filenew(L, fd[0]);
+	filenew(L, fd[1]);
+	return 2;
+}
--- a/p9.c
+++ b/p9.c
@@ -154,11 +154,10 @@
 	{"open", p9_open},
 	{"create", p9_create},
 	{"file", p9_file},
+	{"pipe", p9_pipe},
 	
 	{"remove", p9_remove},
 	{"fd2path", p9_fd2path},
-	{"getenv", p9_getenv},
-	{"setenv", p9_setenv},
 	
 	{"stat", p9_stat},
 	{"walk", p9_walk},
@@ -166,6 +165,9 @@
 	{"bind", p9_bind},
 	{"mount", p9_mount},
 	{"unmount", p9_unmount},
+	
+	{"getenv", p9_getenv},
+	{"setenv", p9_setenv},
 	
 	{"rfork", p9_rfork},
 	
--- a/test.lua
+++ b/test.lua
@@ -74,6 +74,13 @@
 	assert(p9.fd2path(fd.fd) == "/tmp/fd2path")
 end
 
+-- pipe
+do
+	local p₀, p₁ = assert(p9.pipe())
+	p₀:write("ABCD")
+	assert(p₁:read() == "ABCD")
+end
+
 -- Filesystem
 do
 	-- Create a test tree