9
0
Fork 0

Add write_file function

write_file() will write a buffer to a file. The file is created
if necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2013-01-11 17:38:52 +01:00
parent 555dc6cc60
commit a886dac94e
2 changed files with 24 additions and 0 deletions

19
fs/fs.c
View File

@ -67,6 +67,25 @@ err_out:
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";

View File

@ -166,6 +166,11 @@ char *mkmodestr(unsigned long mode, char *str);
*/
void *read_file(const char *filename, size_t *size);
/*
* Write a buffer to a file. This file is newly created.
*/
int write_file(const char *filename, void *buf, size_t size);
/*
* This function turns 'path' into an absolute path and removes all occurrences
* of "..", "." and double slashes. The returned string must be freed wit free().