From dbe948ca3ebdad97f4f2096f6074623fc2a8e3c8 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 5 Oct 2007 00:16:26 +0000 Subject: Pull the file writing code for the wallet client into a separate file so that the srvtab and keytab management can share it. Write atomically to a new file and then link and rename to do an atomic update. Leave a backup copy of any file that's replaced. --- client/wallet.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'client/wallet.c') diff --git a/client/wallet.c b/client/wallet.c index e3ca4dd..998ec30 100644 --- a/client/wallet.c +++ b/client/wallet.c @@ -140,16 +140,7 @@ main(int argc, char *argv[]) fprintf(stderr, "wallet: "); fwrite(result->stderr_buf, 1, result->stderr_len, stderr); } else if (file != NULL && strcmp(command[1], "get") == 0) { - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (fd < 0) - sysdie("open of %s failed", file); - status = write(fd, result->stdout_buf, result->stdout_len); - if (status < 0) - sysdie("write to %s failed", file); - else if (status != (ssize_t) result->stdout_len) - die("write to %s truncated", file); - if (close(fd) < 0) - sysdie("close of %s failed (file probably truncated)", file); + write_file(file, result->stdout_buf, result->stdout_len); if (srvtab != NULL) write_srvtab(srvtab, command[3], file); } else { -- cgit v1.2.3