From ec085c955731db594926666e9bc6bdbbc1f5be9e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 25 Aug 2007 13:36:22 +0200 Subject: [PATCH] Implemented bfix_tmp_file(), which turns a temporary file fastbuf to a permanent one. --- lib/fastbuf.h | 1 + lib/fb-temp.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 4e3bc5ca..9878beeb 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -113,6 +113,7 @@ void bfilesync(struct fastbuf *b); #define TEMP_FILE_NAME_LEN 256 void temp_file_name(char *name); +void bfix_tmp_file(struct fastbuf *fb, const char *name); /* Internal functions of some file back-ends */ diff --git a/lib/fb-temp.c b/lib/fb-temp.c index 65398c15..54daad1b 100644 --- a/lib/fb-temp.c +++ b/lib/fb-temp.c @@ -48,12 +48,22 @@ bopen_tmp(uns buflen) char buf[TEMP_FILE_NAME_LEN]; struct fastbuf *f; + // FIXME: This needs cleanup and merging with other bopen functions. temp_file_name(buf); f = bopen(buf, O_RDWR | O_CREAT | O_TRUNC, buflen); bconfig(f, BCONFIG_IS_TEMP_FILE, 1); return f; } +void bfix_tmp_file(struct fastbuf *fb, const char *name) +{ + int was_temp = bconfig(fb, BCONFIG_IS_TEMP_FILE, 0); + ASSERT(was_temp == 1); + if (rename(fb->name, name)) + die("Cannot rename %s to %s: %m", fb->name, name); + bclose(fb); +} + #ifdef TEST #include "lib/getopt.h" -- 2.39.2