From: Martin Mares Date: Sat, 25 Aug 2007 11:36:22 +0000 (+0200) Subject: Implemented bfix_tmp_file(), which turns a temporary file fastbuf X-Git-Tag: holmes-import~506^2~13^2~86 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ec085c955731db594926666e9bc6bdbbc1f5be9e;p=libucw.git Implemented bfix_tmp_file(), which turns a temporary file fastbuf to a permanent one. --- 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"