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>
This commit is contained in:
parent
ce1689436e
commit
0ca483d5d0
2 changed files with 21 additions and 0 deletions
20
fileio.c
20
fileio.c
|
@ -135,3 +135,23 @@ out:
|
||||||
return rc;
|
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;
|
||||||
|
}
|
||||||
|
|
1
fileio.h
1
fileio.h
|
@ -42,6 +42,7 @@ X509 *fileio_read_cert(const char *filename);
|
||||||
|
|
||||||
int fileio_read_file(void *ctx, const char *filename,
|
int fileio_read_file(void *ctx, const char *filename,
|
||||||
uint8_t **out_buf, size_t *out_len);
|
uint8_t **out_buf, size_t *out_len);
|
||||||
|
int fileio_write_file(const char *filename, uint8_t *buf, size_t len);
|
||||||
|
|
||||||
#endif /* FILEIO_H */
|
#endif /* FILEIO_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue