aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-11-07 13:35:19 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-11-07 13:35:19 +0530
commit06fb3b482545f11f5b3c40d80a080937afdf92e9 (patch)
treeda8862b102a697195a2ac89a3d9b4347d0fa86d8
parent4adc84d5e955c2c0b413ce47f233929dc8b7431d (diff)
Check close() error.
While here leave a TODO to write to a tmp and atomic rename to outfn.
-rw-r--r--mkelf.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/mkelf.lua b/mkelf.lua
index ddcce1d..fbd7909 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -178,12 +178,16 @@ function M.main()
end
local hopts, sgopts, scopts = loadconfig(infn)
local header, segments, sections = elf_layout(hopts, sgopts, scopts)
- local ok, binary = pcall(elf_pack, header, segments, sections)
- if not ok then die("packing failed: %s", binary) end
- local out <close>, err = io.open(outfn, "wb")
- if out == nil then die("failed to open: %s", err) end
- local wok, werr = out:write(binary)
- if not wok then die("write failed: %s", werr) end
+ local ok, res
+ ok, res = pcall(elf_pack, header, segments, sections)
+ if not ok then die("packing failed: %s", res) end
+ -- TODO write to tmp and atomic rename?
+ local out, err = io.open(outfn, "wb")
+ if not out then die("failed to open: %s", err) end
+ ok, res = out:write(res)
+ if not ok then die("write failed: %s", res) end
+ ok, res = out:close()
+ if not ok then die("failed to close %s:, res") end
end
return M