Skip to content

Commit

Permalink
ffi/util: implement isExecutable
Browse files Browse the repository at this point in the history
To test if a path is an executable file.
  • Loading branch information
benoit-pierre authored and Frenzie committed Nov 21, 2024
1 parent 3de16ea commit 6cfdb25
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ffi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,13 @@ function util.template(str, ...)
return result
end

-- Check if `path` is an executable file.
function util.isExecutable(path)
local attributes, err = lfs.attributes(path)
if not attributes or err ~= nil then
return false, err
end
return attributes.mode == "file" and C.access(path, C.X_OK + C.R_OK) == 0
end

return util

0 comments on commit 6cfdb25

Please sign in to comment.