pass file size from read_file
This commit is contained in:
parent
9e13a384c0
commit
79ed00ba92
|
@ -189,7 +189,7 @@ static int edit_read_file(const char *path)
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
if (!stat(path, &s)) {
|
if (!stat(path, &s)) {
|
||||||
filebuffer = read_file(path);
|
filebuffer = read_file(path, NULL);
|
||||||
if (!filebuffer) {
|
if (!filebuffer) {
|
||||||
printf("could not read %s: %s\n", path, errno_str());
|
printf("could not read %s: %s\n", path, errno_str());
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1462,7 +1462,7 @@ static int source_script(const char *path, int argc, char *argv[])
|
||||||
ctx.global_argc = argc;
|
ctx.global_argc = argc;
|
||||||
ctx.global_argv = argv;
|
ctx.global_argv = argv;
|
||||||
|
|
||||||
script = read_file(path);
|
script = read_file(path, NULL);
|
||||||
if (!script)
|
if (!script)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
6
fs/fs.c
6
fs/fs.c
|
@ -30,7 +30,7 @@
|
||||||
#include <xfuncs.h>
|
#include <xfuncs.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
|
|
||||||
void *read_file(const char *filename)
|
void *read_file(const char *filename, size_t *size)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
@ -49,6 +49,10 @@ void *read_file(const char *filename)
|
||||||
goto err_out1;
|
goto err_out1;
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
*size = s.st_size;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
err_out1:
|
err_out1:
|
||||||
|
|
|
@ -148,9 +148,10 @@ struct mtab_entry {
|
||||||
* Read a file into memory. Memory is allocated with malloc and must
|
* Read a file into memory. Memory is allocated with malloc and must
|
||||||
* be freed with free() afterwards. This function allocates one
|
* be freed with free() afterwards. This function allocates one
|
||||||
* byte more than actually needed and sets this to zero, so that
|
* 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
|
* This function turn 'path' into an absolute path and removes all occurrences
|
||||||
|
|
Loading…
Reference in New Issue