summaryrefslogtreecommitdiff
path: root/src/libc
diff options
context:
space:
mode:
authordzwdz2024-05-18 22:09:03 +0200
committerdzwdz2024-05-18 22:09:20 +0200
commit04b176caef6e3f4bc626b1174d096c70afc16dd0 (patch)
treebb233c8f06730fb42fe6bf05780722dc099bd226 /src/libc
parent15e02a470652a5d4ef87485b5ae12afc06dc53f8 (diff)
libc/execvpe: ENOENT on missing interpreter
Diffstat (limited to 'src/libc')
-rw-r--r--src/libc/unistd/unistd.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libc/unistd/unistd.c b/src/libc/unistd/unistd.c
index 9735df0..99899ce 100644
--- a/src/libc/unistd/unistd.c
+++ b/src/libc/unistd/unistd.c
@@ -46,8 +46,9 @@ int execvpe(const char *path, char *const argv[], char *const envp[]) {
int execve(const char *path, char *const argv[], char *const envp[]) {
FILE *file = fopen(path, "e");
char hdr[4] = {0};
- if (!file)
- return -1;
+ if (!file) {
+ return errno = ENOENT, -1;
+ }
fread(hdr, 1, 4, file);
fseek(file, 0, SEEK_SET);
@@ -55,6 +56,7 @@ int execve(const char *path, char *const argv[], char *const envp[]) {
if (!memcmp("\x7f""ELF", hdr, 4)) {
elf_execf(file, (void*)argv, (void*)envp);
fclose(file);
+ errno = EINVAL;
} else if (!memcmp("#!", hdr, 2)) {
char buf[256];
fseek(file, 2, SEEK_SET);
@@ -64,9 +66,10 @@ int execve(const char *path, char *const argv[], char *const envp[]) {
if (endl) *endl = '\0';
execve(buf, (void*)argv, envp);
}
+ } else {
+ errno = EINVAL;
}
- errno = EINVAL;
return -1;
}