mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
(trunk libT) use valloc() and st.st_blksize when verifying local data
This commit is contained in:
parent
6958386ecd
commit
d3ae2cf696
2 changed files with 17 additions and 4 deletions
|
@ -108,7 +108,7 @@ fi
|
|||
AC_HEADER_STDC
|
||||
AC_HEADER_TIME
|
||||
|
||||
AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog])
|
||||
AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog valloc])
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
ACX_PTHREAD
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#if defined(HAVE_POSIX_FADVISE) || defined(SYS_DARWIN)
|
||||
#include <fcntl.h> /* posix_fadvise() / fcntl() */
|
||||
#endif
|
||||
#if defined(SYS_DARWIN)
|
||||
#define HAVE_VALLOC
|
||||
#endif
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
@ -57,8 +60,8 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
uint32_t pieceBytesRead = 0;
|
||||
tr_file_index_t fileIndex = 0;
|
||||
tr_piece_index_t pieceIndex = 0;
|
||||
const int64_t buflen = tor->info.pieceSize;
|
||||
uint8_t * buffer = tr_new( uint8_t, buflen );
|
||||
uint8_t * buffer = NULL;
|
||||
int64_t buflen = 0;
|
||||
const time_t begin = tr_time( );
|
||||
time_t end;
|
||||
|
||||
|
@ -84,6 +87,16 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
char * filename = tr_torrentFindFile( tor, fileIndex );
|
||||
fd = filename == NULL ? -1 : tr_open_file_for_scanning( filename );
|
||||
/* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */
|
||||
if( ( fd >= 0 ) && ( buffer == NULL ) )
|
||||
{
|
||||
struct stat st;
|
||||
buflen = fstat( fd, &st ) ? 4096 : st.st_blksize;
|
||||
#ifdef HAVE_VALLOC
|
||||
buffer = valloc( buflen );
|
||||
#else
|
||||
buffer = malloc( buflen );
|
||||
#endif
|
||||
}
|
||||
tr_free( filename );
|
||||
}
|
||||
|
||||
|
@ -164,7 +177,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
|
|||
/* cleanup */
|
||||
if( fd >= 0 )
|
||||
tr_close_file( fd );
|
||||
tr_free( buffer );
|
||||
free( buffer );
|
||||
|
||||
/* stopwatch */
|
||||
end = tr_time( );
|
||||
|
|
Loading…
Reference in a new issue