diff options
author | Russ Allbery <rra@stanford.edu> | 2010-08-25 18:01:37 -0700 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2010-08-25 18:01:37 -0700 |
commit | e91c0b93355b28617f7c0d756026856762ece242 (patch) | |
tree | 35c4fb8ab35ec5b8d140a0b7e869848a1fac39a9 /client/file.c | |
parent | 602ff7584d3668c36b1bf5fd43988e6f45eceb48 (diff) |
Imported Upstream version 0.12
Diffstat (limited to 'client/file.c')
-rw-r--r-- | client/file.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/client/file.c b/client/file.c index 66d5f63..861da6a 100644 --- a/client/file.c +++ b/client/file.c @@ -48,6 +48,31 @@ overwrite_file(const char *name, const void *data, size_t length) /* + * Given a filename, some data, and a length, append that data to an existing + * file. Dies on any failure. + */ +void +append_file(const char *name, const void *data, size_t length) +{ + int fd; + ssize_t status; + + fd = open(name, O_WRONLY | O_APPEND); + if (fd < 0) + sysdie("open of %s failed", name); + if (length > 0) { + status = write(fd, data, length); + if (status < 0) + sysdie("write to %s failed", name); + else if (status != (ssize_t) length) + die("write to %s truncated", name); + } + if (close(fd) < 0) + sysdie("close of %s failed (file probably truncated)", name); +} + + +/* * Given a filename, some data, and a length, write that data to the given * file safely and atomically by creating file.new, writing the data, linking * file to file.bak, and then renaming file.new to file. |