X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Ffileio.c;h=2b1dab805347c572ed386f52691dea203aa5a840;hp=dc13c9ee636f0ce8312f40ae152a038131fa8c36;hb=68fee104e630eb19f04b8196a83c14c2c9c469e7;hpb=cba38758b4d49c6fe7c2f0eea255e11ee9df23eb diff --git a/src/shared/fileio.c b/src/shared/fileio.c index dc13c9ee6..2b1dab805 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; +}