diff options
author | Richard Ipsum <richardipsum@vx21.xyz> | 2019-10-04 23:28:48 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-10-06 09:22:07 +0100 |
commit | edeef019e8ad8b60f0547a854dc7763f98ff4c40 (patch) | |
tree | e2c404af240119d6910e258083ef67aa2df8ed35 | |
parent | fcf64b34f3332350937608ab6fcb134d5bfac0e3 (diff) | |
download | luxio-edeef019e8ad8b60f0547a854dc7763f98ff4c40.tar.gz |
simple: Add fdopen
-rw-r--r-- | luxio/simple.lua | 18 |
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, |