summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luxio/simple.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/luxio/simple.lua b/luxio/simple.lua
index 1f81d30..bb654e0 100644
--- a/luxio/simple.lua
+++ b/luxio/simple.lua
@@ -814,6 +814,23 @@ local function open(filename, flags, mode)
return sio_wrap_mt(r, false, filename)
end
+--- Open a file from a file descriptor.
+--- @tparam number fd file descriptor to open from
+--- @treturn file|nil File handle, or nil if error
+--- @treturn string|nil Error string if error
+--- @treturn errno|nil Error number if error
+--- @function fdopen
+local function fdopen(fd)
+ -- Ensure the fd is valid before returning a file handle for it
+ local flags, errno = l_fcntl(fd, l.F_GETFL)
+
+ if flags == -1 then
+ return err("fdopen", errno)
+ end
+
+ return sio_wrap_mt(fd, false, nil)
+end
+
local pipe_count = 0
--- Create an anonymous pipe.
@@ -1461,6 +1478,7 @@ end
return {
open = open,
+ fdopen = fdopen,
pipe = pipe,
socketpair = socketpair,
inet = inet,