Skip to content

Commit

Permalink
[FileSystem]: Added specific 64 bit readdir call for Linux. Added cre…
Browse files Browse the repository at this point in the history
…dits for FFI code used for retrieving directory entries.
  • Loading branch information
coding-jackalope committed Mar 29, 2020
1 parent 8b1331b commit 405c902
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
33 changes: 28 additions & 5 deletions Internal/Core/FileSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ end

local GetDirectoryItems = nil

--[[
The following code is based on the following sources:
LoveFS v1.1
Pure Lua FileSystem Access
Under the MIT license.
copyright(c) 2016 Caldas Lopes aka linux-man
luapower/fs_posix
portable filesystem API for LuaJIT / Linux & OSX backend
Written by Cosmin Apreutesei. Public Domain.
--]]

if FFI.os == "Windows" then
FFI.cdef[[
#pragma pack(push)
Expand Down Expand Up @@ -130,10 +143,19 @@ else
typedef struct DIR DIR;

DIR* opendir(const char* name);
struct dirent* readdir(DIR* dirp) asm("readdir$INODE64");
int closedir(DIR* dirp);
]]

if FFI.os == "OSX" then
FFI.cdef[[
struct dirent* readdir(DIR* dirp) asm("readdir$INODE64");
]]
else
FFI.cdef[[
struct dirent* readdir(DIR* dirp) asm("readdir64");
]]
end

GetDirectoryItems = function(Directory, Options)
local Result = {}

Expand All @@ -146,10 +168,11 @@ else
local Name = FFI.string(Entry.d_name)

if Name ~= "." and Name ~= ".." and string.sub(Name, 1, 1) ~= "." then
if (Entry.d_type == 4 and Options.Directories) or (Entry.d_type == 8 and Options.Files) then
if not ShouldFilter(Name, Options.Filter) then
table.insert(Result, Name)
end
local AddDirectory = Entry.d_type == 4 and Options.Directories
local AddFile = Entry.d_type == 8 and Options.Files

if (AddDirectory or AddFile) and not ShouldFilter(Name, Options.Filter) then
table.insert(Result, Name)
end
end

Expand Down
4 changes: 0 additions & 4 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
v0.6.2 RELEASE
==========
[License]: Add mention for LuaPower/fs and lovefs for FileSystem help.

v0.7.0 RELEASE
==========
[API]: Update version number.
Expand Down

0 comments on commit 405c902

Please sign in to comment.