diff options
author | 2016-02-21 11:48:45 +0100 | |
---|---|---|
committer | 2016-02-21 11:48:45 +0100 | |
commit | cc24a339d8c0517259084b5c178d784626ba965c (patch) | |
tree | 9868e9687b5802ae0a3733712a3bbeb3bc75c953 /3rdparty/luv/examples/uvbook/uvcat.lua | |
parent | b5daabda5495dea5c50e17961ecfed2ea8619d76 (diff) |
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Second attempt
Diffstat (limited to '3rdparty/luv/examples/uvbook/uvcat.lua')
-rw-r--r-- | 3rdparty/luv/examples/uvbook/uvcat.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/3rdparty/luv/examples/uvbook/uvcat.lua b/3rdparty/luv/examples/uvbook/uvcat.lua new file mode 100644 index 00000000000..99fdd68000b --- /dev/null +++ b/3rdparty/luv/examples/uvbook/uvcat.lua @@ -0,0 +1,37 @@ +local uv = require('luv') + + +local fname = arg[1] and arg[1] or arg[0] + +uv.fs_open(fname, 'r', tonumber('644', 8), function(err,fd) + if err then + print("error opening file:"..err) + else + local stat = uv.fs_fstat(fd) + local off = 0 + local block = 10 + + local function on_read(err,chunk) + if(err) then + print("Read error: "..err); + elseif #chunk==0 then + uv.fs_close(fd) + else + off = block + off + uv.fs_write(1,chunk,-1,function(err,chunk) + if err then + print("Write error: "..err) + else + uv.fs_read(fd, block, off, on_read) + end + end) + end + end + uv.fs_read(fd, block, off, on_read) + end +end) + + + +uv.run('default') +uv.loop_close() |