summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/fileio.c29
-rw-r--r--src/shared/fileio.h2
2 files changed, 31 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;
+}
diff --git a/src/shared/fileio.h b/src/shared/fileio.h
index 0ca6878ea4..a0aae28bae 100644
--- a/src/shared/fileio.h
+++ b/src/shared/fileio.h
@@ -35,3 +35,5 @@ int read_full_file(const char *fn, char **contents, size_t *size);
int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
int load_env_file(const char *fname, const char *separator, char ***l);
int write_env_file(const char *fname, char **l);
+
+int executable_is_script(const char *path, char **interpreter);