Ignore:
Timestamp:
Aug 21, 2008, 2:57:59 PM (13 years ago)
Author:
charles
Message:

bencode cleanup: remove unused functions and unnecessary #includes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r6600 r6612  
    1414#include <ctype.h> /* isdigit, isprint, isspace */
    1515#include <errno.h>
    16 #include <stdarg.h>
    1716#include <stdio.h>
    1817#include <stdlib.h>
     18#include <string.h>
    1919
    2020#include <event.h> /* evbuffer */
     
    294294            }
    295295
    296             tr_bencInitStr( node, str, str_len, 0 );
     296            tr_bencInitStr( node, str, str_len );
    297297            buf = end;
    298298
     
    388388}
    389389
    390 tr_benc *
    391 tr_bencDictFindFirst( tr_benc * val, ... )
    392 {
    393     const char * key;
    394     tr_benc * ret;
    395     va_list      ap;
    396 
    397     ret = NULL;
    398     va_start( ap, val );
    399     while(( key = va_arg( ap, const char * )))
    400         if(( ret = tr_bencDictFind( val, key )))
    401             break;
    402     va_end( ap );
    403 
    404     return ret;
    405 }
    406 
    407390int
    408391tr_bencListSize( const tr_benc * list )
     
    516499
    517500void
    518 _tr_bencInitStr( tr_benc * val, char * str, int len, int nofree )
    519 {
    520     tr_bencInit( val, TYPE_STR );
    521     val->val.s.s      = str;
    522     val->val.s.nofree = nofree;
    523     if( 0 >= len )
    524     {
    525         len = ( NULL == str ? 0 : strlen( str ) );
    526     }
    527     val->val.s.i = len;
    528 }
    529 
    530 void
    531501tr_bencInitRaw( tr_benc * val, const void * src, size_t byteCount )
    532502{
     
    534504    val->val.s.i = byteCount;
    535505    val->val.s.s = tr_memdup( src, byteCount );
    536     val->val.s.nofree = 0;
    537 }
    538 
    539 int
    540 tr_bencInitStrDup( tr_benc * val, const char * str )
    541 {
    542     char * newStr = tr_strdup( str );
    543     if( newStr == NULL )
    544         return 1;
    545 
    546     _tr_bencInitStr( val, newStr, 0, 0 );
    547     return 0;
     506}
     507
     508void
     509tr_bencInitStr( tr_benc * val, const void * str, int len )
     510{
     511    tr_bencInit( val, TYPE_STR );
     512    val->val.s.s = tr_strndup( str, len );
     513    val->val.s.i = val->val.s.s ? strlen( val->val.s.s ) : 0;
    548514}
    549515
     
    612578{
    613579    tr_benc * node = tr_bencListAdd( list );
    614     tr_bencInitStrDup( node, val );
     580    tr_bencInitStr( node, val, -1 );
    615581    return node;
    616582}
     
    641607
    642608    keyval = dict->val.l.vals + dict->val.l.count++;
    643     tr_bencInitStrDup( keyval, key );
     609    tr_bencInitStr( keyval, key, -1 );
    644610
    645611    itemval = dict->val.l.vals + dict->val.l.count++;
     
    659625{
    660626    tr_benc * child = tr_bencDictAdd( dict, key );
    661     tr_bencInitStrDup( child, val );
     627    tr_bencInitStr( child, val, -1 );
    662628    return child;
    663629}
     
    963929freeStringFunc( const tr_benc * val, void * freeme )
    964930{
    965     if( !val->val.s.nofree )
    966         tr_ptrArrayAppend( freeme, val->val.s.s );
     931    tr_ptrArrayAppend( freeme, val->val.s.s );
    967932}
    968933static void
     
    994959***/
    995960
     961#if 0
    996962struct WalkPrint
    997963{
     
    10701036    bencWalk( val, &walkFuncs, &walkPrint );
    10711037}
     1038#endif
    10721039
    10731040/***
     
    13021269
    13031270int
     1271tr_bencSaveJSONFile( const char * filename, const tr_benc * b )
     1272{
     1273    int len;
     1274    char * content = tr_bencSaveAsJSON( b, &len );
     1275    const int err = saveFile( filename, content, len );
     1276    tr_free( content );
     1277    return err;
     1278}
     1279
     1280/***
     1281****
     1282***/
     1283
     1284int
    13041285tr_bencLoadFile( const char * filename, tr_benc * b )
    13051286{
     
    13141295
    13151296int
    1316 tr_bencSaveJSONFile( const char * filename, const tr_benc * b )
    1317 {
    1318     int len;
    1319     char * content = tr_bencSaveAsJSON( b, &len );
    1320     const int err = saveFile( filename, content, len );
    1321     tr_free( content );
    1322     return err;
    1323 }
    1324 
    1325 int
    13261297tr_bencLoadJSONFile( const char * filename, tr_benc * b )
    13271298{
Note: See TracChangeset for help on using the changeset viewer.