summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-03-14 19:22:07 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-03-14 19:22:07 -0700
commitab6acefe649751b072fd9be21ff5de7733c1370e (patch)
tree7abe6b36fd8774cb758421bdcce6949b1782a5f7
parent37b99c20bf10933524f3b8c1ec04215d5c94c18d (diff)
downloadsyslinux-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.
-rw-r--r--com32/libutil/Makefile2
-rw-r--r--com32/libutil/include/syslinux/loadfile.h (renamed from com32/libutil/include/loadfile.h)0
-rw-r--r--com32/libutil/syslinux/loadfile.c (renamed from com32/libutil/loadfile.c)2
-rw-r--r--com32/modules/elf.c57
4 files changed, 4 insertions, 57 deletions
diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile
index 3656fb3f..eaae4156 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
index fbda589d..fbda589d 100644
--- a/com32/libutil/include/loadfile.h
+++ b/com32/libutil/include/syslinux/loadfile.h
diff --git a/com32/libutil/loadfile.c b/com32/libutil/syslinux/loadfile.c
index d9cfb3b7..9a4e3ca5 100644
--- a/com32/libutil/loadfile.c
+++ b/com32/libutil/syslinux/loadfile.c
@@ -23,7 +23,7 @@
#include <fcntl.h>
#include <sys/stat.h>
-#include "loadfile.h"
+#include <syslinux/loadfile.h>
int loadfile(const char *filename, void **ptr, size_t *len)
{
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;
}