libifupdown: add utility function to determine if a path is executable
This commit is contained in:
parent
b35d985ea4
commit
eb8f1938dc
2 changed files with 16 additions and 0 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -58,3 +59,17 @@ lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const c
|
||||||
|
|
||||||
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -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_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const char *fmt, ...);
|
||||||
|
extern bool lif_file_is_executable(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue