9
0
Fork 0

svn_rev_605

make read_file global
This commit is contained in:
Sascha Hauer 2007-07-05 18:02:09 +02:00 committed by Sascha Hauer
parent 9d0f3063a7
commit e2f1a28306
3 changed files with 30 additions and 34 deletions

View File

@ -11,39 +11,6 @@
#include <hush.h>
#endif
static void *read_file(const char *file)
{
struct stat s;
void *buf = NULL;
int fd = 0;
if (stat(file, &s)) {
perror("stat");
return NULL;
}
fd = open(file, O_RDONLY);
if (fd < 0) {
perror("open");
return NULL;
}
buf = xzalloc(s.st_size + 1);
if (read(fd, buf, s.st_size) < s.st_size) {
perror("read");
goto out;
}
close(fd);
return buf;
out:
free(buf);
close(fd);
return NULL;
}
static int do_exec(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int i;

30
fs/fs.c
View File

@ -8,6 +8,34 @@
#include <xfuncs.h>
#include <init.h>
void *read_file(const char *filename)
{
int fd;
struct stat s;
void *buf = NULL;
if (stat(filename, &s))
return NULL;
buf = xzalloc(s.st_size + 1);
fd = open(filename, O_RDONLY);
if (fd < 0)
goto err_out;
if (read(fd, buf, s.st_size) < s.st_size)
goto err_out1;
close(fd);
return buf;
err_out1:
close(fd);
err_out:
free(buf);
return NULL;
}
char *mkmodestr(unsigned long mode, char *str)
{
static const char *l = "xwr";
@ -490,7 +518,7 @@ int mount(const char *device, const char *fsname, const char *path)
int ret;
errno = 0;
printf("mount: %s on %s type %s\n", device, path, fsname);
drv = get_driver_by_name(fsname);
if (!drv) {
errno = -ENODEV;

View File

@ -118,6 +118,7 @@ struct mtab_entry {
struct device_d *parent_device;
};
void *read_file(const char *filename);
char *normalise_path(const char *path);
#endif /* __FS_H */