diff --git a/libifupdown/execute.c b/libifupdown/execute.c index 04d29e6..b1242d5 100644 --- a/libifupdown/execute.c +++ b/libifupdown/execute.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -58,3 +59,17 @@ lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const c return WIFEXITED(status) && WEXITSTATUS(status) == 0; } + +bool +lif_file_is_executable(const char *path) +{ + struct stat st; + + if (stat(path, &st)) + return false; + + if (!S_ISREG(st.st_mode)) + return false; + + return access(path, X_OK); +} diff --git a/libifupdown/execute.h b/libifupdown/execute.h index b1f2eb5..3fce6ff 100644 --- a/libifupdown/execute.h +++ b/libifupdown/execute.h @@ -25,5 +25,6 @@ struct lif_execute_opts { }; extern bool lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const char *fmt, ...); +extern bool lif_file_is_executable(const char *path); #endif