Skip to content

Commit 7852250

Browse files
committed
Add full_write() function
The upcoming commands import_hw_wrapped_key, generate_hw_wrapped_key, and prepare_hw_wrapped_key will write the wrapped keys they produce to standard output. Add a full_write() helper function for them to use.
1 parent d8e1d50 commit 7852250

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

fscryptctl.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ static size_t read_key(uint8_t *raw_key, size_t max_size) {
363363
return ret;
364364
}
365365

366+
static bool full_write(int fd, const uint8_t *buf, size_t size) {
367+
while (size) {
368+
ssize_t ret = write(fd, buf, size);
369+
if (ret < 0) {
370+
fprintf(stderr, "error: writing output: %s\n", strerror(errno));
371+
return false;
372+
}
373+
buf += ret;
374+
size -= ret;
375+
}
376+
return true;
377+
}
378+
366379
static bool get_policy(const char *path,
367380
struct fscrypt_get_policy_ex_arg *arg) {
368381
int fd = open(path, O_RDONLY | O_CLOEXEC);

0 commit comments

Comments
 (0)