summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-27 16:33:35 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-27 16:33:35 +0200
commit79ed00ba92a0c2dd209d94e0550d582897ca176e (patch)
treeaf5684bf31b6e7ae5f5ca1fc9aa26ba9919d6185
parent9e13a384c005d26411b53d4c4f643700957c8345 (diff)
downloadbarebox-79ed00ba92a0c2dd209d94e0550d582897ca176e.tar.gz
barebox-79ed00ba92a0c2dd209d94e0550d582897ca176e.tar.xz
pass file size from read_file
-rw-r--r--commands/edit.c2
-rw-r--r--common/hush.c2
-rw-r--r--fs/fs.c6
-rw-r--r--include/fs.h5
4 files changed, 10 insertions, 5 deletions
diff --git a/commands/edit.c b/commands/edit.c
index 4578c7ad88..5f04ff5ed0 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -189,7 +189,7 @@ static int edit_read_file(const char *path)
struct stat s;
if (!stat(path, &s)) {
- filebuffer = read_file(path);
+ filebuffer = read_file(path, NULL);
if (!filebuffer) {
printf("could not read %s: %s\n", path, errno_str());
return -1;
diff --git a/common/hush.c b/common/hush.c
index 8552ecea26..c7c9ced8ec 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1462,7 +1462,7 @@ static int source_script(const char *path, int argc, char *argv[])
ctx.global_argc = argc;
ctx.global_argv = argv;
- script = read_file(path);
+ script = read_file(path, NULL);
if (!script)
return 1;
diff --git a/fs/fs.c b/fs/fs.c
index 98bde06548..cd694b609d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -30,7 +30,7 @@
#include <xfuncs.h>
#include <init.h>
-void *read_file(const char *filename)
+void *read_file(const char *filename, size_t *size)
{
int fd;
struct stat s;
@@ -49,6 +49,10 @@ void *read_file(const char *filename)
goto err_out1;
close(fd);
+
+ if (size)
+ *size = s.st_size;
+
return buf;
err_out1:
diff --git a/include/fs.h b/include/fs.h
index c17df207ed..fcc04f4158 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -148,9 +148,10 @@ struct mtab_entry {
* Read a file into memory. Memory is allocated with malloc and must
* be freed with free() afterwards. This function allocates one
* byte more than actually needed and sets this to zero, so that
- * it cn be used for text files.
+ * it can be used for text files.
+ * If size is nonzero it s set to the file size.
*/
-void *read_file(const char *filename);
+void *read_file(const char *filename, size_t *size);
/*
* This function turn 'path' into an absolute path and removes all occurrences