Changeset 4842
- Timestamp:
- Jan 27, 2008, 5:03:58 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/inout.c
r4777 r4842 18 18 #include <sys/stat.h> 19 19 #include <unistd.h> 20 21 #include <openssl/sha.h> 20 22 21 23 #include "transmission.h" … … 225 227 uint8_t * setme ) 226 228 { 227 int n;228 int ret;229 uint8_t * buf;229 int offset; 230 int bytesLeft; 231 uint8_t buf[4096]; 230 232 const tr_info * info; 233 SHA_CTX sha; 231 234 232 235 assert( tor != NULL ); … … 235 238 236 239 info = &tor->info; 237 n = tr_torPieceCountBytes( tor, pieceIndex ); 238 239 buf = tr_new( uint8_t, n ); 240 ret = tr_ioRead( tor, pieceIndex, 0, n, buf ); 241 if( !ret ) 242 tr_sha1( setme, buf, n, NULL ); 243 tr_free( buf ); 244 245 return ret; 240 offset = 0; 241 bytesLeft = tr_torPieceCountBytes( tor, pieceIndex ); 242 SHA1_Init( &sha ); 243 244 while( bytesLeft > 0 ) 245 { 246 const int bytesThisPass = MIN( bytesLeft, (int)sizeof(buf) ); 247 int ret = tr_ioRead( tor, pieceIndex, offset, bytesThisPass, buf ); 248 if( ret ) 249 return ret; 250 SHA1_Update( &sha, buf, bytesThisPass ); 251 bytesLeft -= bytesThisPass; 252 offset += bytesThisPass; 253 } 254 255 SHA1_Final( setme, &sha ); 256 return 0; 246 257 } 247 258
Note: See TracChangeset
for help on using the changeset viewer.