diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-01 14:48:53 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-01 14:48:53 +0000 |
| commit | 859193c50b1017932eda654d0a96c247fcf3b59b (patch) | |
| tree | 39a051b45cbc60915ee446780c2e44dcbcbb0b74 /src/AbstractDiskWriter.cc | |
| parent | c682371a582386b022fe3cfc0d72782356aa1841 (diff) | |
2008-10-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use seek() and SetEndOfFile() for mingw32 build instead of
ftruncate(),
because mingw32's ftruncate() cannot handle more than 2GB-size
file.
* src/AbstractDiskWriter.cc
Diffstat (limited to 'src/AbstractDiskWriter.cc')
| -rw-r--r-- | src/AbstractDiskWriter.cc | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 9ef6d696..d1ce0076 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -33,6 +33,17 @@ */ /* copyright --> */ #include "AbstractDiskWriter.h" + +#include <unistd.h> + +#include <cerrno> +#include <cstring> +#include <cassert> + +#ifdef __MINGW32__ +# include <windows.h> +#endif // __MINGW32__ + #include "File.h" #include "Util.h" #include "message.h" @@ -42,9 +53,6 @@ #include "a2io.h" #include "StringFormat.h" #include "DownloadFailureException.h" -#include <cerrno> -#include <cstring> -#include <cassert> namespace aria2 { @@ -159,7 +167,21 @@ void AbstractDiskWriter::truncate(uint64_t length) if(fd == -1) { throw DlAbortEx("File not opened."); } - ftruncate(fd, length); +#ifdef __MINGW32__ + // Since mingw32's ftruncate cannot handle over 2GB files, we use SetEndOfFile + // instead. + HANDLE handle = LongToHandle(_get_osfhandle(fd)); + seek(length); + if(SetEndOfFile(handle) == 0) { + throw DlAbortEx(StringFormat("SetEndOfFile failed. cause: %s", + GetLastError()).str()); + } +#else + if(ftruncate(fd, length) == -1) { + throw DlAbortEx(StringFormat("ftruncate failed. cause: %s", + strerror(errno)).str()); + } +#endif } // TODO the file descriptor fd must be opened before calling this function. |
