diff options
author | Chris Wilson <chris+github@qwirx.com> | 2006-09-01 07:49:31 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2006-09-01 07:49:31 +0000 |
commit | 9d1c5b2aa1adceffbb21e6fc93d477d5874af9a4 (patch) | |
tree | 3ef5b7d5e881fbfca3189d2faa8690e39af7a084 /test | |
parent | ebd3eab50bef24078e9e6c3e4dabcc7b55b7c4b2 (diff) |
(refs #3)
Use truncation/sparse files to quickly create files with 200MB of zeroes
Diffstat (limited to 'test')
-rw-r--r-- | test/backupdiff/testbackupdiff.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/test/backupdiff/testbackupdiff.cpp b/test/backupdiff/testbackupdiff.cpp index d532d8a6..6520907e 100644 --- a/test/backupdiff/testbackupdiff.cpp +++ b/test/backupdiff/testbackupdiff.cpp @@ -66,22 +66,20 @@ bool files_identical(const char *file1, const char *file2) 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"); - - // 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); + #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 TEST_THAT((size_t)TestGetFileSize(filename) == size); } |