From 5b8ce7f6a0bf30d138acb4a9224ae6c9c9c02558 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 16 Sep 2007 00:48:21 +0000 Subject: [PATCH] changed to use ftruncate to allocate files --- src/file.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 3d568d1f7..72876d528 100755 --- a/src/file.cpp +++ b/src/file.cpp @@ -247,19 +247,16 @@ namespace libtorrent void set_size(size_type s) { - size_type pos = tell(); - // Only set size if current file size not equals s. - // 2 as "m" argument is to be sure seek() sets SEEK_END on - // all compilers. - if(s != seek(0, 2)) +#ifdef _WIN32 +#error file.cpp is for posix systems only. use file_win.cpp on windows +#else + if (ftruncate(m_fd, s) < 0) { - seek(s - 1); - char dummy = 0; - read(&dummy, 1); - seek(s - 1); - write(&dummy, 1); + std::stringstream msg; + msg << "ftruncate failed: '" << strerror(errno); + throw file_error(msg.str()); } - seek(pos); +#endif } size_type seek(size_type offset, int m = 1)