diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-07-30 10:43:51 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-08-07 06:13:51 +0200 |
commit | 3cfa4bc00c61eca4c0986c793dd21b8b5271fd8f (patch) | |
tree | 01b10c6fa35134394d170696c5c14c67b20b87b3 /fs/fs.c | |
parent | 2fd4f0fbe93ec7e6e10b3475257521dd8418f8e7 (diff) | |
download | barebox-3cfa4bc00c61eca4c0986c793dd21b8b5271fd8f.tar.gz barebox-3cfa4bc00c61eca4c0986c793dd21b8b5271fd8f.tar.xz |
move file helper functions to separate file
We have our file helper functions in several places. Move them
all to lib/libfile.c.
With this we no longer have file helpers in fs/fs.c which contains
the core fs functions and no functions in lib/libbb.c which are
not from busybox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs/fs.c')
-rw-r--r-- | fs/fs.c | 72 |
1 files changed, 0 insertions, 72 deletions
@@ -34,78 +34,6 @@ #include <libgen.h> #include <block.h> -void *read_file(const char *filename, size_t *size) -{ - int fd; - struct stat s; - void *buf = NULL; - const char *tmpfile = "/.read_file_tmp"; - int ret; - -again: - if (stat(filename, &s)) - return NULL; - - if (s.st_size == FILESIZE_MAX) { - ret = copy_file(filename, tmpfile, 0); - if (ret) - return NULL; - filename = tmpfile; - goto again; - } - - buf = xzalloc(s.st_size + 1); - - fd = open(filename, O_RDONLY); - if (fd < 0) - goto err_out; - - ret = read_full(fd, buf, s.st_size); - if (ret < 0) - goto err_out1; - - close(fd); - - if (size) - *size = s.st_size; - - if (filename == tmpfile) - unlink(tmpfile); - - return buf; - -err_out1: - close(fd); -err_out: - free(buf); - - if (filename == tmpfile) - unlink(tmpfile); - - return NULL; -} - -EXPORT_SYMBOL(read_file); - -int write_file(const char *filename, void *buf, size_t size) -{ - int fd, ret; - - fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT); - if (fd < 0) - return fd; - - ret = write_full(fd, buf, size); - - close(fd); - - if (ret < 0) - return ret; - - return 0; -} -EXPORT_SYMBOL(write_file); - char *mkmodestr(unsigned long mode, char *str) { static const char *l = "xwr"; |