From ded9f6ca751bcd8098af9a3fd6dfba8052b7880f Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Thu, 21 Nov 2024 19:49:20 +0100 Subject: [PATCH] ffi/util: implement `isExecutable` To test if a path is an executable file. --- ffi/util.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ffi/util.lua b/ffi/util.lua index d85663809..71fb5a1bc 100644 --- a/ffi/util.lua +++ b/ffi/util.lua @@ -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