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)
|
void set_size(size_type s)
|
||||||
{
|
{
|
||||||
size_type pos = tell();
|
#ifdef _WIN32
|
||||||
// Only set size if current file size not equals s.
|
#error file.cpp is for posix systems only. use file_win.cpp on windows
|
||||||
// 2 as "m" argument is to be sure seek() sets SEEK_END on
|
#else
|
||||||
// all compilers.
|
if (ftruncate(m_fd, s) < 0)
|
||||||
if(s != seek(0, 2))
|
|
||||||
{
|
{
|
||||||
seek(s - 1);
|
std::stringstream msg;
|
||||||
char dummy = 0;
|
msg << "ftruncate failed: '" << strerror(errno);
|
||||||
read(&dummy, 1);
|
throw file_error(msg.str());
|
||||||
seek(s - 1);
|
|
||||||
write(&dummy, 1);
|
|
||||||
}
|
}
|
||||||
seek(pos);
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type seek(size_type offset, int m = 1)
|
size_type seek(size_type offset, int m = 1)
|
||||||
|
|
Loading…
Reference in New Issue