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/fdlimit.c

    r8298 r8299  
    202202}
    203203
    204 FILE*
     204int
    205205tr_open_file_for_scanning( const char * filename )
    206206{
     
    225225    /* open the file */
    226226    fd = open( filename, flags, 0666 );
    227     if( fd < 0 )
    228         return NULL;
    229 
     227    if( fd >= 0 )
     228    {
    230229#ifdef HAVE_POSIX_FADVISE
    231     posix_fadvise( fd, 0, 0, POSIX_FADV_SEQUENTIAL );
     230        posix_fadvise( fd, 0, 0, POSIX_FADV_SEQUENTIAL );
    232231#endif
    233232#ifdef SYS_DARWIN
    234     fcntl( fd, F_NOCACHE, 1 );
    235     fcntl( fd, F_RDAHEAD, 1 );
    236 #endif
    237 
    238     return fdopen( fd, "r" );
    239 }
    240 
    241 static void
    242 flush_before_closing( int fd )
     233        fcntl( fd, F_NOCACHE, 1 );
     234        fcntl( fd, F_RDAHEAD, 1 );
     235#endif
     236    }
     237
     238    return fd;
     239}
     240
     241void
     242tr_close_file( int fd )
    243243{
    244244#if defined(HAVE_POSIX_FADVISE)
    245245    posix_fadvise( fd, 0, 0, POSIX_FADV_DONTNEED );
    246246#endif
    247 }
    248 
    249 void
    250 tr_close_file( FILE * fp )
    251 {
    252     flush_before_closing( fileno( fp ) );
    253     fclose( fp );
     247    close( fd );
    254248}
    255249
     
    347341    assert( fileIsOpen( o ) );
    348342
    349     flush_before_closing( o->fd );
     343    tr_close_file( o->fd );
    350344    close( o->fd );
    351345    o->fd = -1;
Note: See TracChangeset for help on using the changeset viewer.