Changeset 8017 for trunk/daemon/remote.c


Ignore:
Timestamp:
Mar 4, 2009, 4:16:02 PM (13 years ago)
Author:
charles
Message:

(trunk) #1881: promote tr_strratio() to libtransmission, so that its code doesn't have to be repeated in all the clients

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r8016 r8017  
    659659#define GIGABYTE_FACTOR ( 1024.0 * 1024.0 * 1024.0 )
    660660
    661 static void
    662 printf_double_without_rounding( char * buf, int buflen, double d, int places )
    663 {
    664     char * pch;
    665     char tmp[128];
    666     int len;
    667     tr_snprintf( tmp, sizeof( tmp ), "%'.64f", d );
    668     pch = strchr( tmp, '.' );
    669     pch += places + 1;
    670     len = MIN( buflen - 1, pch - tmp );
    671     memcpy( buf, tmp, len );
    672     buf[len] = '\0';
    673 }
    674 
    675661static char*
    676662strlratio2( char * buf, double ratio, size_t buflen )
    677663{
    678     if( (int)ratio == TR_RATIO_NA )
    679         tr_strlcpy( buf, "None", buflen );
    680     else if( (int)ratio == TR_RATIO_INF )
    681         tr_strlcpy( buf, "Inf", buflen );
    682     else if( ratio < 10.0 )
    683         printf_double_without_rounding( buf, buflen, ratio, 2 );
    684     else if( ratio < 100.0 )
    685         printf_double_without_rounding( buf, buflen, ratio, 1 );
    686     else
    687         tr_snprintf( buf, buflen, "%'.0f", ratio );
    688     return buf;
     664    return tr_strratio( buf, buflen, ratio, "Inf" );
    689665}
    690666
Note: See TracChangeset for help on using the changeset viewer.