Ignore:
Timestamp:
Apr 26, 2009, 8:44:18 PM (13 years ago)
Author:
charles
Message:

(trunk libT) convert tr_open_file_for_scanning() and tr_close_file() to use file descriptors instead of file pointers so that we don't have to mix and match between them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/verify.c

    r8296 r8299  
    4343{
    4444    SHA_CTX sha;
    45     FILE * fp = NULL;
     45    int fd = -1;
    4646    int64_t filePos = 0;
    4747    tr_bool changed = 0;
     
    7373
    7474        /* if we're starting a new file... */
    75         if( !filePos && !fp )
     75        if( !filePos && (fd<0) )
    7676        {
    7777            char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
    78             fp = tr_open_file_for_scanning( filename );
    79             /* fprintf( stderr, "opening file #%d (%s) -- %p\n", fileIndex, filename, fp ); */
     78            fd = tr_open_file_for_scanning( filename );
     79            /* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */
    8080            tr_free( filename );
    8181        }
     
    8989
    9090        /* read a bit */
    91         if( fp && tr_lseek( fileno(fp), filePos, SEEK_SET ) != -1 ) {
    92             const int64_t numRead = fread( buffer, 1, bytesThisPass, fp );
     91        if( (fd>=0) && tr_lseek( fd, filePos, SEEK_SET ) != -1 ) {
     92            const int64_t numRead = read( fd, buffer, bytesThisPass );
    9393            if( numRead == bytesThisPass )
    9494                SHA1_Update( &sha, buffer, numRead );
     
    130130        {
    131131            /* fprintf( stderr, "closing file\n" ); */
    132             if( fp != NULL ) { tr_close_file( fp ); fp = NULL; }
     132            if( fd >= 0 ) { tr_close_file( fd ); fd = -1; }
    133133            ++fileIndex;
    134134            filePos = 0;
     
    137137
    138138    /* cleanup */
    139     if( fp != NULL )
    140         tr_close_file( fp );
     139    if( fd >= 0 )
     140        tr_close_file( fd );
    141141    tr_free( buffer );
    142142
Note: See TracChangeset for help on using the changeset viewer.