Untitled
By: a guest | Feb 9th, 2010 | Syntax:
None | Size: 0.89 KB | Hits: 59 | Expires: Never
local alien = require 'alien'
local structs = require 'structs'
local struct = require 'alien.struct'
local function listdir(path)
local result = {}
local libc = alien.default
libc.strerror:types("string", "int")
libc.opendir:types("pointer", "string")
libc.readdir:types("pointer", "pointer")
libc.closedir:types("int", "pointer")
local dirh = libc.opendir(path)
if (dirh == nil) then
err = alien.errno()
merr = libc.strerror(err)
log.crit("opendir('%s') returned: errno=(%d) %s", tostring(path), err, merr)
error("Failed to open: ".. path)
end
while true do
dp = libc.readdir(dirh)
if dp == nil then
break
end
local s = struct.unpack("s", dp, structs.dirent.__size, structs.dirent.d_name + 1)
log.crit("str: %d: %s", structs.dirent.d_name, s)
table.insert(result, s)
end
return result
end