Ignore:
Timestamp:
Oct 15, 2007, 8:15:34 PM (15 years ago)
Author:
charles
Message:

new utility (tr_loadFile), and reimplement metainfo's "readtorrent" to use it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r3105 r3425  
    4040#include "utils.h"
    4141
    42 #define TORRENT_MAX_SIZE (5*1024*1024)
    43 
    4442/***********************************************************************
    4543 * Local prototypes
     
    612610readtorrent( const char * path, size_t * size )
    613611{
    614     uint8_t    * buf;
    615     struct stat  sb;
    616     FILE       * file;
    617 
    618     /* try to stat the file */
    619     errno = 0;
    620     if( stat( path, &sb ) )
    621     {
    622         tr_err( "Couldn't get information for file \"%s\" %s", path, strerror(errno) );
    623         return NULL;
    624     }
    625 
    626     if( ( sb.st_mode & S_IFMT ) != S_IFREG )
    627     {
    628         tr_err( "Not a regular file (%s)", path );
    629         return NULL;
    630     }
    631     if( sb.st_size > TORRENT_MAX_SIZE )
    632     {
    633         tr_err( "Torrent file is too big (%"PRIu64" bytes)",
    634                 ( uint64_t )sb.st_size );
    635         return NULL;
    636     }
    637 
    638     /* Load the torrent file into our buffer */
    639     file = fopen( path, "rb" );
    640     if( !file )
    641     {
    642         tr_err( "Couldn't open file \"%s\" %s", path, strerror(errno) );
    643         return NULL;
    644     }
    645     buf = malloc( sb.st_size );
    646     if( NULL == buf )
    647     {
    648         tr_err( "Couldn't allocate memory (%"PRIu64" bytes)",
    649                 ( uint64_t )sb.st_size );
    650     }
    651     fseek( file, 0, SEEK_SET );
    652     if( fread( buf, sb.st_size, 1, file ) != 1 )
    653     {
    654         tr_err( "Error reading \"%s\" %s", path, strerror(errno) );
    655         free( buf );
    656         fclose( file );
    657         return NULL;
    658     }
    659     fclose( file );
    660 
    661     *size = sb.st_size;
    662 
    663     return buf;
     612    return tr_loadFile( path, size );
    664613}
    665614
Note: See TracChangeset for help on using the changeset viewer.