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:
parent
555dc6cc60
commit
a886dac94e
19
fs/fs.c
19
fs/fs.c
|
@ -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";
|
||||
|
|
|
@ -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().
|
||||
|
|
Loading…
Reference in New Issue