diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 6950c9a3c..798bc83a0 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -294,39 +294,25 @@ getFileInfo( const char * topFile, tr_benc * uninitialized_length, tr_benc * uninitialized_path ) { - const char * pch, *prev; - size_t topLen; - int n; + size_t offset; /* get the file size */ tr_bencInitInt( uninitialized_length, file->size ); /* how much of file->filename to walk past */ - topLen = strlen( topFile ); - if( topLen>0 && topFile[topLen-1]!=TR_PATH_DELIMITER ) - ++topLen; /* +1 for the path delimiter */ + offset = strlen( topFile ); + if( offset>0 && topFile[offset-1]!=TR_PATH_DELIMITER ) + ++offset; /* +1 for the path delimiter */ /* build the path list */ - n = 1; - for( pch = file->filename + topLen; *pch; ++pch ) - if( *pch == TR_PATH_DELIMITER ) - ++n; - tr_bencInitList( uninitialized_path, n ); - for( prev = pch = file->filename + topLen; ; ++pch ) - { - char buf[TR_PATH_MAX]; - - if( *pch && *pch != TR_PATH_DELIMITER ) - continue; - - memcpy( buf, prev, pch - prev ); - buf[pch - prev] = '\0'; - - tr_bencListAddStr( uninitialized_path, buf ); - - prev = pch + 1; - if( !*pch ) - break; + tr_bencInitList( uninitialized_path, 0 ); + if( strlen(file->filename) > offset ) { + char * filename = tr_strdup( file->filename + offset ); + char * walk = filename; + const char * token; + while(( token = strsep( &walk, TR_PATH_DELIMITER_STR ))) + tr_bencListAddStr( uninitialized_path, token ); + tr_free( filename ); } }