From ab6acefe649751b072fd9be21ff5de7733c1370e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 14 Mar 2007 19:22:07 -0700 Subject: [PATCH] Move the loadfile() routine into the syslinux/ namespace, and use it. - Move the loadfile() routine into . - Actually use the loadfile() routine. --- com32/libutil/Makefile | 2 +- com32/libutil/include/{ => syslinux}/loadfile.h | 0 com32/libutil/{ => syslinux}/loadfile.c | 2 +- com32/modules/elf.c | 57 +------------------------ 4 files changed, 4 insertions(+), 57 deletions(-) rename com32/libutil/include/{ => syslinux}/loadfile.h (100%) rename com32/libutil/{ => syslinux}/loadfile.c (97%) diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile index 3656fb3..eaae415 100644 --- a/com32/libutil/Makefile +++ b/com32/libutil/Makefile @@ -47,7 +47,7 @@ LNXSFLAGS = -g LNXLDFLAGS = -g OBJCOPY = objcopy LIBOBJS = ansiline.o ansiraw.o get_key.o idle.o sha1hash.o unbase64.o \ - movebits.o loadfile.o + syslinux/loadfile.o LNXLIBOBJS = $(patsubst %.o,%.lo,$(LIBOBJS)) .SUFFIXES: .lss .c .lo .o .elf .c32 .lnx diff --git a/com32/libutil/include/loadfile.h b/com32/libutil/include/syslinux/loadfile.h similarity index 100% rename from com32/libutil/include/loadfile.h rename to com32/libutil/include/syslinux/loadfile.h diff --git a/com32/libutil/loadfile.c b/com32/libutil/syslinux/loadfile.c similarity index 97% rename from com32/libutil/loadfile.c rename to com32/libutil/syslinux/loadfile.c index d9cfb3b..9a4e3ca 100644 --- a/com32/libutil/loadfile.c +++ b/com32/libutil/syslinux/loadfile.c @@ -23,7 +23,7 @@ #include #include -#include "loadfile.h" +#include int loadfile(const char *filename, void **ptr, size_t *len) { diff --git a/com32/modules/elf.c b/com32/modules/elf.c index 0b4aa35..a049bc8 100644 --- a/com32/modules/elf.c +++ b/com32/modules/elf.c @@ -42,6 +42,7 @@ #include #include +#include #include /* 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; } -- 2.7.4