diff options
| author | H. Peter Anvin <hpa@zytor.com> | 2007-03-14 19:22:07 -0700 |
|---|---|---|
| committer | H. Peter Anvin <hpa@zytor.com> | 2007-03-14 19:22:07 -0700 |
| commit | ab6acefe649751b072fd9be21ff5de7733c1370e (patch) | |
| tree | 7abe6b36fd8774cb758421bdcce6949b1782a5f7 /com32/modules/elf.c | |
| parent | 37b99c20bf10933524f3b8c1ec04215d5c94c18d (diff) | |
| download | syslinux-ab6acefe649751b072fd9be21ff5de7733c1370e.tar.gz | |
Move the loadfile() routine into the syslinux/ namespace, and use it.syslinux-3.40-pre13
- Move the loadfile() routine into <syslinux/loadfile.h>.
- Actually use the loadfile() routine.
Diffstat (limited to 'com32/modules/elf.c')
| -rw-r--r-- | com32/modules/elf.c | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/com32/modules/elf.c b/com32/modules/elf.c index 0b4aa35a..a049bc83 100644 --- a/com32/modules/elf.c +++ b/com32/modules/elf.c @@ -42,6 +42,7 @@ #include <elf.h> #include <console.h> +#include <syslinux/loadfile.h> #include <syslinux/movebits.h> /* If we don't have this much memory for the stack, signal failure */ @@ -59,60 +60,6 @@ static inline void error(const char *msg) fputs(msg, stderr); } -/* - * Load a file into memory - */ -int read_file(const char *filename, void **ptr, size_t *lenp) -{ - int fd; - size_t len; - ssize_t rv; - struct stat st; - char *data = NULL; - - dprintf("filename = \"%s\"\n", filename); - - fd = open(filename, O_RDONLY); - if (fd < 0) - return -1; - - dprintf("file open...\n"); - - if (fstat(fd, &st) < 0) - goto bail; - - len = st.st_size; - - dprintf("Allocating %zu bytes...\n", len); - - data = malloc(len); - if (!data) - goto bail; - - *ptr = data; - *lenp = len; - - while (len) { - dprintf("Reading %zu bytes... ", len); - rv = read(fd, data, len); - dprintf("%zd bytes read\n", rv); - if (rv <= 0) - goto bail; /* Syslinux doesn't EINTR */ - data += rv; - len -= rv; - } - - close(fd); - - return 0; /* All data read */ - - bail: - if (data) - free(data); - close(fd); - return -1; -} - int boot_elf(void *ptr, size_t len, char **argv) { char *cptr = ptr; @@ -328,7 +275,7 @@ int main(int argc, char *argv[]) return 1; } - if (read_file(argv[1], &data, &data_len)) { + if (loadfile(argv[1], &data, &data_len)) { error("Unable to load file\n"); return 1; } |
