| 88 | #if defined(WIN32) |
| 89 | |
| 90 | // Means we are compiling from MSVS |
| 91 | # if defined(_MSC_VER) |
| 92 | // _lseeki64 declaration is |
| 93 | // __int64 __cdecl _lseeki64(__in int _FileHandle, __in __int64 _Offset, __in int _Origin) |
| 94 | // So result should be compared long |
| 95 | else if( lseek( fd, fileOffset, SEEK_SET ) == ( -1L ) ) |
| 96 | # else |
| 97 | // |
| 98 | // As lseek is redefined above to _lseeki64, casting to off_t (1) cannot be |
| 99 | // performed on MinGW because large file support is not supported and (2) is |
| 100 | // not necessary on MSVC because the function accepts __int64 anyway. |
| 101 | // |
| 102 | else if( lseek( fd, fileOffset, SEEK_SET ) == ( -1 ) ) |
| 103 | # endif |
| 104 | #else |
139 | | #ifdef WIN32 |
140 | | /* return 0 on success, or an errno on failure */ |
141 | | static int |
142 | | ensureMinimumFileSize( const tr_torrent * tor, |
143 | | tr_file_index_t fileIndex, |
144 | | uint64_t minBytes ) |
145 | | { |
146 | | int fd; |
147 | | int err; |
148 | | struct stat sb; |
149 | | const tr_file * file = &tor->info.files[fileIndex]; |
150 | | |
151 | | assert( 0 <= fileIndex && fileIndex < tor->info.fileCount ); |
152 | | assert( minBytes <= file->length ); |
153 | | |
154 | | fd = tr_fdFileCheckout( tor->downloadDir, |
155 | | file->name, TRUE, !file->dnd, file->length ); |
156 | | |
157 | | if( fd < 0 ) /* bad fd */ |
158 | | err = errno; |
159 | | else if( fstat ( fd, &sb ) ) /* how big is the file? */ |
160 | | err = errno; |
161 | | else if( sb.st_size >= (off_t)minBytes ) /* already big enough */ |
162 | | err = 0; |
163 | | else if( !tr_ftruncate( fd, minBytes ) ) /* grow it */ |
164 | | err = 0; |
165 | | else /* couldn't grow it */ |
166 | | err = errno; |
167 | | |
168 | | if( fd >= 0 ) |
169 | | tr_fdFileReturn( fd ); |
170 | | |
171 | | return err; |
172 | | } |
173 | | |
174 | | #endif |
175 | | |