summaryrefslogtreecommitdiff
path: root/luxio
diff options
context:
space:
mode:
authorRob Kendrick (humdrum) <rjek@rjek.com>2013-11-06 11:03:47 +0000
committerRob Kendrick (humdrum) <rjek@rjek.com>2013-11-06 11:03:47 +0000
commit783952fa4ea3b8144bb7c11ec08a891f756330f9 (patch)
tree0c62d05c5546f3a75ee9bad08646b30a3208fd24 /luxio
parent9d4daca7830c0de62404c62b05592409c7a2636b (diff)
downloadluxio-783952fa4ea3b8144bb7c11ec08a891f756330f9.tar.gz
Simple read can now return nil to show end of file
Diffstat (limited to 'luxio')
-rw-r--r--luxio/simple.lua24
1 files changed, 17 insertions, 7 deletions
diff --git a/luxio/simple.lua b/luxio/simple.lua
index f8cb1ad..0d6937d 100644
--- a/luxio/simple.lua
+++ b/luxio/simple.lua
@@ -522,7 +522,9 @@ local function read(o, ...)
end
c[#c + 1] = r
until #r == 0
- res[#res + 1] = table.concat(c)
+ if #c ~= 0 then
+ res[#res + 1] = table.concat(c)
+ end
elseif patt == "*l" then
local c = { }
repeat
@@ -530,25 +532,33 @@ local function read(o, ...)
if r == -1 then
return err("read", errno)
end
- if r == '\n' then
- break
- else
+ if r ~= '\n' and #r ~= 0 then
c[#c + 1] = r
+ else
+ break
end
until #r == 0
- res[#res + 1] = table.concat(c)
+ if #c ~= 0 then
+ res[#res + 1] = table.concat(c)
+ end
elseif type(patt) == "number" then
local r, errno = l_read(o.fd, patt)
if r == -1 then
return err("read", errno)
end
- res[#res + 1] = r
+ if #r ~= 0 then
+ res[#res + 1] = r
+ end
else
error(("unknown pattern specification '%s' at #%d"):format(patt, idx))
end
end
- return unpack(res)
+ if #res == 0 then
+ return nil
+ else
+ return unpack(res)
+ end
end
local function stat(p)