diff options
Diffstat (limited to 'src/shared/fileio.c')
-rw-r--r-- | src/shared/fileio.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/fileio.c b/src/shared/fileio.c index dc13c9ee63..2b1dab8053 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -593,3 +593,32 @@ int write_env_file(const char *fname, char **l) { return r; } + +int executable_is_script(const char *path, char **interpreter) { + int r; + char _cleanup_free_ *line = NULL; + int len; + char *ans; + + assert(path); + + r = read_one_line_file(path, &line); + if (r < 0) + return r; + + if (!startswith(line, "#!")) + return 0; + + ans = strstrip(line + 2); + len = strcspn(ans, " \t"); + + if (len == 0) + return 0; + + ans = strndup(ans, len); + if (!ans) + return -ENOMEM; + + *interpreter = ans; + return 1; +} |