9
0
Fork 0

pass file size from read_file

This commit is contained in:
Sascha Hauer 2007-09-27 16:33:35 +02:00
parent 9e13a384c0
commit 79ed00ba92
4 changed files with 10 additions and 5 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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