changed to use ftruncate to allocate files
This commit is contained in:
parent
b1f10e5825
commit
5b8ce7f6a0
19
src/file.cpp
19
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)
|
||||
|
|
Loading…
Reference in New Issue