Changeset 5772
- Timestamp:
- May 8, 2008, 3:25:21 AM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bencode-test.c
r5608 r5772 238 238 check( !err ); 239 239 check( end == buf + strlen( (const char*)buf ) ); 240 check(( child = tr_bencList GetNthChild( &val, 0 )));241 check(( child2 = tr_bencList GetNthChild( child, 0 )));240 check(( child = tr_bencListChild( &val, 0 ))); 241 check(( child2 = tr_bencListChild( child, 0 ))); 242 242 saved = tr_bencSave( &val, &len ); 243 243 check( !strcmp( saved, "lld1:ai64e1:bi32eeee" ) ); -
trunk/libtransmission/bencode.c
r5667 r5772 377 377 } 378 378 379 int 380 tr_bencListSize( const tr_benc * list ) 381 { 382 return tr_bencIsList( list ) ? list->val.l.count : 0; 383 } 384 379 385 tr_benc* 380 tr_bencList GetNthChild( tr_benc * val, int i )386 tr_bencListChild( tr_benc * val, int i ) 381 387 { 382 388 tr_benc * ret = NULL; … … 389 395 tr_bencGetInt ( const tr_benc * val, int64_t * setme ) 390 396 { 391 int success = FALSE;392 if( tr_bencIsInt( val )) {397 const int success = tr_bencIsInt( val ); 398 if( success ) 393 399 *setme = val->val.i ; 394 success = TRUE; 395 } 400 return success; 401 } 402 403 int 404 tr_bencGetStr( const tr_benc * val, const char ** setme ) 405 { 406 const int success = tr_bencIsString( val ); 407 if( success ) 408 *setme = val->val.s.s; 396 409 return success; 397 410 } … … 405 418 found = tr_bencGetInt( child, setme ); 406 419 return found; 420 } 421 422 int 423 tr_bencDictFindDouble( tr_benc * dict, const char * key, double * setme ) 424 { 425 const char * str; 426 const int success = tr_bencDictFindStr( dict, key, &str ); 427 if( success ) 428 *setme = strtod( str, NULL ); 429 return success; 407 430 } 408 431 … … 592 615 tr_bencInitStrDup( child, val ); 593 616 return child; 617 } 618 tr_benc* 619 tr_bencDictAddDouble( tr_benc * dict, const char * key, double d ) 620 { 621 char buf[128]; 622 snprintf( buf, sizeof( buf ), "%f", d ); 623 return tr_bencDictAddStr( dict, key, buf ); 594 624 } 595 625 tr_benc* -
trunk/libtransmission/bencode.h
r5667 r5772 70 70 void tr_bencFree( tr_benc * ); 71 71 int tr_bencDictFindInt( tr_benc * dict, const char * key, int64_t * setme ); 72 int tr_bencDictFindDouble( tr_benc * dict, const char * key, double * setme ); 72 73 int tr_bencDictFindStr( tr_benc * dict, const char * key, const char ** setme ); 73 74 int tr_bencDictFindList( tr_benc * dict, const char * key, tr_benc ** setme ); … … 104 105 /* note: key must not be freed or modified while val is in use */ 105 106 tr_benc * tr_bencDictAdd( tr_benc * dict, const char * key ); 107 tr_benc * tr_bencDictAddDouble( tr_benc * dict, const char * key, double d ); 106 108 tr_benc * tr_bencDictAddInt( tr_benc * dict, const char * key, int64_t val ); 107 109 tr_benc * tr_bencDictAddStr( tr_benc * dict, const char * key, const char * val ); … … 116 118 117 119 int tr_bencGetInt( const tr_benc * val, int64_t * setme ); 120 int tr_bencGetStr( const tr_benc * val, const char ** setme ); 118 121 119 122 int tr_bencIsType( const tr_benc *, int type ); … … 143 146 **/ 144 147 145 tr_benc * tr_bencListGetNthChild( tr_benc * list, int n ); 148 int tr_bencListSize( const tr_benc * list ); 149 tr_benc * tr_bencListChild( tr_benc * list, int n ); 146 150 147 151
Note: See TracChangeset
for help on using the changeset viewer.