Ignore:
Timestamp:
Dec 30, 2008, 10:07:39 PM (12 years ago)
Author:
charles
Message:

(trunk libT) have tr_bencSaveAsJSON() use an evbuffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r7549 r7552  
    13121312
    13131313char*
    1314 tr_bencSaveAsJSON( const tr_benc * top,
    1315                    int *           len )
    1316 {
    1317     char *           ret;
     1314tr_bencSaveAsJSON( const tr_benc * top, struct evbuffer * out )
     1315{
    13181316    struct WalkFuncs walkFuncs;
    13191317    struct jsonWalk  data;
    13201318
    1321     data.out = tr_getBuffer( );
     1319    evbuffer_drain( out, EVBUFFER_LENGTH( out ) );
     1320
     1321    data.out = out;
    13221322    data.parents = NULL;
    13231323
     
    13301330    bencWalk( top, &walkFuncs, &data );
    13311331
    1332     if( EVBUFFER_LENGTH( data.out ) )
    1333         evbuffer_add_printf( data.out, "\n" );
    1334     if( len )
    1335         *len = EVBUFFER_LENGTH( data.out );
    1336     ret = tr_strndup( EVBUFFER_DATA( data.out ), EVBUFFER_LENGTH( data.out ) );
    1337 
    1338     tr_releaseBuffer( data.out );
    1339     return ret;
     1332    if( EVBUFFER_LENGTH( out ) )
     1333        evbuffer_add_printf( out, "\n" );
     1334
     1335    return (char*) EVBUFFER_DATA( out );
    13401336}
    13411337
     
    14661462                     const tr_benc * b )
    14671463{
    1468     int       len;
    1469     char *    content = tr_bencSaveAsJSON( b, &len );
    1470     const int err = saveFile( filename, content, len );
    1471 
    1472     tr_free( content );
     1464    struct evbuffer * buf = tr_getBuffer( );
     1465    const char * json = tr_bencSaveAsJSON( b, buf );
     1466    const int err = saveFile( filename, json, EVBUFFER_LENGTH( buf ) );
     1467    tr_releaseBuffer( buf );
    14731468    return err;
    14741469}
Note: See TracChangeset for help on using the changeset viewer.