Recent Posts
None | 52 sec ago
None | 1 min ago
None | 1 min ago
Java | 1 min ago
Java | 1 min ago
Java | 2 min ago
None | 2 min ago
None | 2 min ago
Python | 3 min ago
None | 3 min ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 9th of Feb 2010 11:23:13 PM Download | Raw | Embed | Report
  1. local alien = require 'alien'
  2. local structs = require 'structs'
  3. local struct = require 'alien.struct'
  4.  
  5. local function listdir(path)
  6.   local result = {}
  7.   local libc = alien.default
  8.   libc.strerror:types("string", "int")
  9.   libc.opendir:types("pointer", "string")
  10.   libc.readdir:types("pointer", "pointer")
  11.   libc.closedir:types("int", "pointer")
  12.  
  13.   local dirh = libc.opendir(path)
  14.   if (dirh == nil) then
  15.     err = alien.errno()
  16.     merr = libc.strerror(err)
  17.     log.crit("opendir('%s') returned: errno=(%d) %s", tostring(path), err, merr)
  18.     error("Failed to open: ".. path)
  19.   end
  20.  
  21.   while true do
  22.     dp = libc.readdir(dirh)
  23.     if dp == nil then
  24.       break
  25.     end
  26.    
  27.     local s = struct.unpack("s", dp, structs.dirent.__size, structs.dirent.d_name + 1)
  28.     log.crit("str: %d: %s", structs.dirent.d_name, s)
  29.     table.insert(result, s)
  30.   end
  31.  
  32.   return result
  33. end
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: