summaryrefslogtreecommitdiff
path: root/src/user/lib/elfload.c
diff options
context:
space:
mode:
authordzwdz2022-07-26 22:04:19 +0200
committerdzwdz2022-07-26 22:04:19 +0200
commit137dcb3e207b264c467f4b2b13df2316b8b0a67c (patch)
tree29f01a9c4eca62ec6b0f443d8a48eeda563df452 /src/user/lib/elfload.c
parent4d19346cf0d2a93eed9afe22e5c2a5d9a30fb37c (diff)
user/libc: fread, fwrite, fclose
Diffstat (limited to 'src/user/lib/elfload.c')
-rw-r--r--src/user/lib/elfload.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c
index 75c1162..b73dfe5 100644
--- a/src/user/lib/elfload.c
+++ b/src/user/lib/elfload.c
@@ -11,17 +11,9 @@ void elf_execf(FILE *f) {
const size_t cap = 0x60000;
size_t pos = 0;
void *buf = malloc(cap); // TODO a way to get file size
- if (!buf) goto fail;
+ if (buf && fread(buf, 1, cap - pos, f))
+ elf_exec(buf);
- while (!f->eof) {
- long ret = file_read(f, buf, cap - pos);
- if (ret < 0) goto fail;
- pos += ret;
- if (pos >= cap) goto fail;
- }
- elf_exec(buf);
-
-fail:
free(buf);
}