diff src/lib/file-set-size.c @ 222:cf4d065f2f85 HEAD

lots of cleanups. also index/datafile is now capable of staying in memory, as long as it's noticed while opening the index.
author Timo Sirainen <tss@iki.fi>
date Sat, 14 Sep 2002 14:09:42 +0300
parents ed0d5b17c7a4
children 14bad0a48eb4
line wrap: on
line diff
--- a/src/lib/file-set-size.c	Fri Sep 13 03:01:23 2002 +0300
+++ b/src/lib/file-set-size.c	Sat Sep 14 14:09:42 2002 +0300
@@ -25,6 +25,7 @@
 
 #include "lib.h"
 #include "write-full.h"
+#include "file-set-size.h"
 
 #include <unistd.h>
 
@@ -36,15 +37,18 @@
 
 	i_assert(size >= 0);
 
+	/* FIXME: this may not be good idea, since mmap()ing and writing
+	   to it creates fragmentation. */
+
 	/* try truncating it to the size we want. if this succeeds, the written
 	   area is full of zeros - exactly what we want. however, this may not
 	   work at all, in which case we fallback to write()ing the zeros. */
-	ret = ftruncate(fd, size);
+	ret = -1;/*ftruncate(fd, size)*/;
 	old_errno = errno;
 
 	pos = lseek(fd, 0, SEEK_END);
 	if (ret != -1 && pos == size)
-		return lseek(fd, 0, SEEK_SET) < 0 ? -1 : 0;
+		return 0;
 
 	if (pos < 0)
 		return -1;
@@ -55,8 +59,9 @@
 		return -1;
 	}
 
+	size -= pos;
+
 	/* start growing the file */
-	size -= pos;
 	memset(block, 0, sizeof(block));
 
 	while ((uoff_t)size > sizeof(block)) {