Skip to content

Commit 90c5d1e

Browse files
committed
Fixed freeze when loading INFLATE.LUA from UNZIP.LUA on 16-bit systems.
1 parent 14b400e commit 90c5d1e

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

arch/UNZIP.LUA

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ function unzip(z, d, l, x)
106106
return c
107107
end
108108

109+
---Load a Lua Module if it exists
110+
---@param m string The module name to look for
111+
---@return boolean true if the module file is found and loaded, nil otherwise
112+
function LLM(m)
113+
114+
-- p = Path
115+
for p in package.path:gmatch("[^;]+") do
116+
117+
-- n = File name
118+
-- o = Opened file
119+
local n, o = p:gsub("%?", m):gsub("[\\/]", S)
120+
o = io.open(n, "r")
121+
if o then o:close() return require(m) end
122+
end
123+
end
124+
109125
-- Setup output file
110126
fn = d .. fn -- Prepend target directory
111127
M(fn) -- Create directory
@@ -126,8 +142,7 @@ function unzip(z, d, l, x)
126142
local c = R()
127143
if c then W(c) else break end
128144
end
129-
--TODO: Fix pcall hang on 16-bit builds
130-
elseif (cm == 8 or cm == 9) and pcall(require, "INFLATE") then -- deflated file
145+
elseif (cm == 8 or cm == 9) and LLM("INFLATE") then -- deflated file
131146
inflate(R, W, of)
132147
else
133148
print("!CM" .. cm)

0 commit comments

Comments
 (0)