[Box Backup-dev] COMMIT r912 - box/chris/merge/test/backupdiff
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Fri Sep 1 08:49:31 BST 2006
Author: chris
Date: 2006-09-01 08:49:31 +0100 (Fri, 01 Sep 2006)
New Revision: 912
Modified:
box/chris/merge/test/backupdiff/testbackupdiff.cpp
Log:
(refs #3)
Use truncation/sparse files to quickly create files with 200MB of zeroes
Modified: box/chris/merge/test/backupdiff/testbackupdiff.cpp
===================================================================
--- box/chris/merge/test/backupdiff/testbackupdiff.cpp 2006-09-01 07:48:12 UTC (rev 911)
+++ box/chris/merge/test/backupdiff/testbackupdiff.cpp 2006-09-01 07:49:31 UTC (rev 912)
@@ -66,23 +66,21 @@
void make_file_of_zeros(const char *filename, size_t size)
{
- static const size_t bs = 0x10000;
- size_t remSize = size;
- void *b = malloc(bs);
- memset(b, 0, bs);
- FILE *f = fopen(filename, "wb");
+ #ifdef WIN32
+ HANDLE handle = openfile(filename, O_WRONLY | O_CREAT | O_EXCL, 0);
+ TEST_THAT(handle != INVALID_HANDLE_VALUE);
+ SetFilePointer(handle, size, NULL, FILE_BEGIN);
+ TEST_THAT(GetLastError() == NO_ERROR);
+ TEST_THAT(SetEndOfFile(handle) == true);
+ TEST_THAT(CloseHandle(handle) == true);
+ #else
+ int fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
+ if (fd < 0) perror(filename);
+ TEST_THAT(fd >= 0);
+ TEST_THAT(ftruncate(fd, size) == 0);
+ TEST_THAT(close(fd) == 0);
+ #endif
- // Using largish blocks like this is much faster, while not consuming too much RAM
- while(remSize > bs)
- {
- fwrite(b, bs, 1, f);
- remSize -= bs;
- }
- fwrite(b, remSize, 1, f);
-
- fclose(f);
- free(b);
-
TEST_THAT((size_t)TestGetFileSize(filename) == size);
}
More information about the Boxbackup-dev
mailing list