diff --git a/fs/fs.c b/fs/fs.c index 04331fc..f840516 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -67,6 +67,25 @@ 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"; diff --git a/include/fs.h b/include/fs.h index 8ff7300..919daab 100644 --- a/include/fs.h +++ b/include/fs.h @@ -167,6 +167,11 @@ 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(). */