Ignore:
Timestamp:
Jul 3, 2010, 12:25:22 AM (12 years ago)
Author:
charles
Message:

(trunk) #3045 "make libtransmission's API byte-oriented instead of KiB-oriented." -- implemented. This is a largish commit and will break the mac build for a little while.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r10921 r10931  
    10661066
    10671067        if( length < 1 )
    1068             length = strlen( input );
     1068            length = (int)strlen( input );
    10691069
    10701070        bmem = BIO_new( BIO_s_mem( ) );
     
    14701470    if( !pageSize ) {
    14711471#ifdef HAVE_GETPAGESIZE
    1472         pageSize = getpagesize();
     1472        pageSize = (size_t) getpagesize();
    14731473#else /* guess */
    14741474        pageSize = 4096;
     
    15171517{
    15181518    char * name;
    1519     double value;
     1519    unsigned int value;
    15201520};
    15211521 
     
    15251525};
    15261526
     1527enum { TR_FMT_B, TR_FMT_KB, TR_FMT_MB, TR_FMT_GB };
     1528
    15271529static void
    15281530formatter_init( struct formatter_units * units,
    1529                 double kilo,
     1531                unsigned int kilo,
    15301532                const char * b, const char * kb,
    15311533                const char * mb, const char * gb )
     
    15381540
    15391541    units->units[TR_FMT_MB].name = tr_strdup( mb );
    1540     units->units[TR_FMT_MB].value = pow( kilo, 2 );
     1542    units->units[TR_FMT_MB].value = kilo * kilo;
    15411543
    15421544    units->units[TR_FMT_GB].name = tr_strdup( gb );
    1543     units->units[TR_FMT_GB].value = pow( kilo, 3 );
    1544 }
    1545 
    1546 static const char*
    1547 tr_formatter_units( const struct formatter_units * u, int size )
    1548 {
    1549     assert( u != NULL );
    1550     assert( 0<=size && size<4 );
    1551 
    1552     return u->units[size].name;
     1545    units->units[TR_FMT_GB].value = kilo * kilo * kilo;
    15531546}
    15541547
     
    15671560    else                                 unit = &u->units[3];
    15681561
    1569     value = bytes / unit->value;
     1562    value = (double)bytes / unit->value;
    15701563    units = unit->name;
    15711564    if( unit->value == 1 )
     
    15821575
    15831576void
    1584 tr_formatter_size_init( double kilo, const char * b, const char * kb,
    1585                                      const char * mb, const char * gb )
     1577tr_formatter_size_init( unsigned int kilo,
     1578                        const char * b, const char * kb,
     1579                        const char * mb, const char * gb )
    15861580{
    15871581    formatter_init( &size_units, kilo, b, kb, mb, gb );
     
    15941588}
    15951589
    1596 const char*
    1597 tr_formatter_size_units( int i )
    1598 {
    1599     return tr_formatter_units( &size_units, i );
    1600 }
    1601 
    16021590static struct formatter_units speed_units;
    16031591
    16041592void
    1605 tr_formatter_speed_init( double kilo, const char * b, const char * kb,
    1606                                       const char * mb, const char * gb )
     1593tr_formatter_speed_init( unsigned int kilo,
     1594                         const char * b, const char * kb,
     1595                         const char * mb, const char * gb )
    16071596{
    16081597    formatter_init( &speed_units, kilo, b, kb, mb, gb );
     
    16151604}
    16161605
    1617 const char*
    1618 tr_formatter_speed_units( int i )
    1619 {
    1620     return tr_formatter_units( &speed_units, i );
    1621 }
     1606unsigned int
     1607tr_formatter_speed_k( void )
     1608{
     1609    return speed_units.units[TR_FMT_KB].value;
     1610}
     1611
     1612static struct formatter_units mem_units;
     1613
     1614void
     1615tr_formatter_mem_init( unsigned int kilo,
     1616                       const char * b, const char * kb,
     1617                       const char * mb, const char * gb )
     1618{
     1619    formatter_init( &mem_units, kilo, b, kb, mb, gb );
     1620}
     1621
     1622char*
     1623tr_formatter_mem( char * buf, uint64_t bytes_per_second, size_t buflen )
     1624{
     1625    return formatter_get_size_str( &mem_units, buf, bytes_per_second, buflen );
     1626}
Note: See TracChangeset for help on using the changeset viewer.