fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosUse our own custom filesystem module for getDirectoryItems.2c3d0c1

master
994 B44 linesraw
1local ffi = require("ffi")
2local libc = ffi.C
3local errno = ffi.errno
4
5ffi.cdef[[
6typedef struct {
7	ino_t          d_ino;       /* Inode number */
8	off_t          d_off;       /* Not an offset; see below */
9	unsigned short d_reclen;    /* Length of this record */
10	unsigned char  d_type;      /* Type of file; not supported
11								  by all filesystem types */
12	char           name[256];   /* Null-terminated filename */
13} dirent;
14typedef struct __dirstream DIR;
15
16char *strerror(int errnum);
17DIR *opendir(const char *name);
18int closedir(DIR *dirp);
19dirent *readdir(DIR *dirp);
20]]
21
22local linux = {}
23
24function linux.getItems(path)
25	local dir = libc.opendir(path)
26	local entries = {}
27
28	if dir ~= nil then
29		local entry
30		while true do
31			entry = libc.readdir(dir)
32			if entry == nil then break end -- end of list
33			local name = ffi.string(entry.name)
34			if name ~= "." and name ~= ".." then
35				table.insert(entries, name)
36			end
37		end
38		libc.closedir(dir)
39	end
40
41	return entries
42end
43
44return linux