Ignore:
Timestamp:
Apr 23, 2006, 5:03:12 PM (16 years ago)
Author:
titer
Message:

Use file descriptors instead of streams (preliminary cleanup for fixes
to come in fdlimit*)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r104 r238  
    2323#include "transmission.h"
    2424
    25 #ifdef SYS_BEOS
    26 # define fseeko _fseek
    27 #endif
    28 
    2925struct tr_io_s
    3026{
     
    203199    char        * path, * p;
    204200    struct stat   sb;
    205     FILE        * file;
     201    int          file;
    206202
    207203    tr_dbg( "Creating files..." );
     
    235231        {
    236232            /* File doesn't exist yet */
    237             if( !( file = fopen( path, "w" ) ) )
     233            if( ( file = open( path, O_WRONLY|O_CREAT|O_TRUNC ) ) < 0 )
    238234            {
    239235                tr_err( "Could not create `%s' (%s)", path,
     
    242238                return 1;
    243239            }
    244             fclose( file );
     240            close( file );
    245241        }
    246242        else if( ( sb.st_mode & S_IFMT ) != S_IFREG )
     
    358354 *
    359355 **********************************************************************/
    360 typedef size_t (* iofunc) ( void *, size_t, size_t, FILE * );
     356typedef size_t (* iofunc) ( int, void *, size_t );
    361357static int readOrWriteBytes( tr_io_t * io, uint64_t offset, int size,
    362                              uint8_t * buf, int write )
     358                             uint8_t * buf, int isWrite )
    363359{
    364360    tr_torrent_t * tor = io->tor;
     
    367363    int    piece = offset / inf->pieceSize;
    368364    int    begin = offset % inf->pieceSize;
    369     int    i, cur;
     365    int    i;
     366    size_t cur;
    370367    char * path;
    371     FILE * file;
    372     iofunc readOrWrite = write ? (iofunc) fwrite : (iofunc) fread;
     368    int    file;
     369    iofunc readOrWrite = isWrite ? (iofunc) write : (iofunc) read;
    373370
    374371    /* Release the torrent lock so the UI can still update itself if
     
    416413        asprintf( &path, "%s/%s", tor->destination, inf->files[i].name );
    417414        file = tr_fdFileOpen( tor->fdlimit, path );
    418         if( !file )
     415        if( file < 0 )
    419416        {
    420417            tr_err( "readOrWriteBytes: could not open file '%s'", path );
     
    425422
    426423        /* seek to the right offset... */
    427         if( fseeko( file, offset, SEEK_SET ) )
     424        if( lseek( file, offset, SEEK_SET ) < 0 )
    428425        {
    429426            goto fail;
     
    431428
    432429        /* do what we are here to do... */
    433         if( readOrWrite( buf, cur, 1, file ) != 1 )
     430        if( readOrWrite( file, buf, cur ) != cur )
    434431        {
    435432            goto fail;
Note: See TracChangeset for help on using the changeset viewer.