Ignore:
Timestamp:
Feb 12, 2010, 7:59:30 PM (12 years ago)
Author:
charles
Message:

(trunk libT) use valloc() and st.st_blksize when verifying local data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/verify.c

    r9868 r10186  
    2020 #include <fcntl.h> /* posix_fadvise() / fcntl() */
    2121#endif
     22#if defined(SYS_DARWIN)
     23 #define HAVE_VALLOC
     24#endif
    2225
    2326#include <openssl/sha.h>
     
    5861    tr_file_index_t fileIndex = 0;
    5962    tr_piece_index_t pieceIndex = 0;
    60     const int64_t buflen = tor->info.pieceSize;
    61     uint8_t * buffer = tr_new( uint8_t, buflen );
     63    uint8_t * buffer = NULL;
     64    int64_t buflen = 0;
    6265    const time_t begin = tr_time( );
    6366    time_t end;
     
    8588            fd = filename == NULL ? -1 : tr_open_file_for_scanning( filename );
    8689            /* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */
     90            if( ( fd >= 0 ) && ( buffer == NULL ) )
     91            {
     92                struct stat st;
     93                buflen = fstat( fd, &st ) ? 4096 : st.st_blksize;
     94#ifdef HAVE_VALLOC
     95                buffer = valloc( buflen );
     96#else
     97                buffer = malloc( buflen );
     98#endif
     99            }
    87100            tr_free( filename );
    88101        }
     
    165178    if( fd >= 0 )
    166179        tr_close_file( fd );
    167     tr_free( buffer );
     180    free( buffer );
    168181
    169182    /* stopwatch */
Note: See TracChangeset for help on using the changeset viewer.