Changeset 7131


Ignore:
Timestamp:
Nov 20, 2008, 5:19:59 PM (12 years ago)
Author:
charles
Message:

(libT) #1486: Large file support broken on Windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r7061 r7131  
    3636
    3737#ifdef WIN32
    38  #define lseek _lseeki64
    3938 #if defined(read)
    40     #undef read
     39  #undef read
    4140 #endif
    4241 #define read  _read
    4342 
    4443 #if defined(write)
    45     #undef write
     44  #undef write
    4645 #endif
    4746 #define write _write
     
    4948
    5049enum { TR_IO_READ, TR_IO_WRITE };
     50
     51static int64_t
     52tr_lseek( int fd, int64_t offset, int whence )
     53{
     54#if defined(_LARGEFILE_SOURCE)
     55    return lseek64( fd, (off64_t)offset, whence );
     56#elif defined(WIN32)
     57    return _lseeki64( fd, offset, whence );
     58#else
     59    return lseek( fd, (off_t)offset, whence );
     60#endif
     61}
    5162
    5263/* returns 0 on success, or an errno on failure */
     
    8697    else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, !file->dnd, file->length ) ) < 0 )
    8798        err = errno;
    88     else if( lseek( fd, (off_t)fileOffset, SEEK_SET ) == ( (off_t)-1 ) )
     99    else if( tr_lseek( fd, (int64_t)fileOffset, SEEK_SET ) == -1 )
    89100        err = errno;
    90101    else if( func( fd, buf, buflen ) != buflen )
     
    118129                       tr_piece_index_t   pieceIndex,
    119130                       uint32_t           pieceOffset,
    120                        tr_file_index_t *  fileIndex,
    121                        uint64_t *         fileOffset )
    122 {
    123     const uint64_t  offset = tr_pieceOffset( tor, pieceIndex, pieceOffset,
    124                                              0 );
     131                       tr_file_index_t  * fileIndex,
     132                       uint64_t         * fileOffset )
     133{
     134    const uint64_t  offset = tr_pieceOffset( tor, pieceIndex, pieceOffset, 0 );
    125135    const tr_file * file;
    126136
     
    136146    assert( tor->info.files[*fileIndex].offset + *fileOffset == offset );
    137147}
    138 
    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( !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
    175148
    176149/* returns 0 on success, or an errno on failure */
     
    202175                                             file->length - fileOffset );
    203176
    204 #ifdef WIN32
    205         if( ioMode == TR_IO_WRITE )
    206             err = ensureMinimumFileSize( tor, fileIndex,
    207                                          fileOffset + bytesThisPass );
    208         if( !err )
    209 #endif
    210177        err = readOrWriteBytes( tor, ioMode,
    211178                                fileIndex, fileOffset, buf, bytesThisPass );
Note: See TracChangeset for help on using the changeset viewer.