fileio: Add fileio_write_file

Add a convenience function for writing a single buffer to a file.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
diff --git a/fileio.c b/fileio.c
index ff829f1..f55d3a4 100644
--- a/fileio.c
+++ b/fileio.c
@@ -135,3 +135,23 @@
 	return rc;
 
 }
+
+int fileio_write_file(const char *filename, uint8_t *buf, size_t len)
+{
+	int fd;
+
+	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+	if (fd < 0) {
+		perror("open");
+		return -1;
+	}
+
+	if (!write_all(fd, buf, len)) {
+		perror("write_all");
+		close(fd);
+		return -1;
+	}
+
+	close(fd);
+	return 0;
+}
diff --git a/fileio.h b/fileio.h
index 3d6e505..1673a06 100644
--- a/fileio.h
+++ b/fileio.h
@@ -42,6 +42,7 @@
 
 int fileio_read_file(void *ctx, const char *filename,
 		uint8_t **out_buf, size_t *out_len);
+int fileio_write_file(const char *filename, uint8_t *buf, size_t len);
 
 #endif /* FILEIO_H */