ref: a9a2e3aab41d483985e568343ffdd78d900cc6ab
parent: 4ca6bbbb60081fdb40b442ae6bd3cd3f86ceed64
author: kvik <kvik@a-b.xyz>
date: Sun Apr 18 17:37:26 EDT 2021
fs: add file:iounit() method
--- a/fs.c
+++ b/fs.c
@@ -315,6 +315,16 @@
}
static int
+p9_iounit(lua_State *L)
+{
+ int fd;
+
+ fd = filefd(L, 1);
+ lua_pushinteger(L, iounit(fd));
+ return 1;
+}
+
+static int
p9_pipe(lua_State *L)
{
int fd[2];
--- a/p9.c
+++ b/p9.c
@@ -191,6 +191,7 @@
{"slurp", p9_slurp},
{"write", p9_write},
{"seek", p9_seek},
+ {"iounit", p9_iounit},
{nil, nil},
};
luaL_newmetatable(L, "p9-File");
--- a/test.lua
+++ b/test.lua
@@ -72,6 +72,7 @@
do
local fd = p9.create("/tmp/fd2path")
assert(p9.fd2path(fd.fd) == "/tmp/fd2path")
+ fd:close()
end
-- pipe
@@ -79,6 +80,14 @@
local p₀, p₁ = assert(p9.pipe())
p₀:write("ABCD")
assert(p₁:read() == "ABCD")
+ p₀:close(); p₁:close()
+end
+
+-- iounit
+do
+ local f = assert(p9.open("/srv/slashmnt"))
+ assert(f:iounit() != 0)
+ f:close()
end
-- Filesystem