add a portability wrapper ``tr_snprintf()'' around snprintf()
This commit is contained in:
parent
2705db2b6a
commit
2f239319b0
28
cli/cli.c
28
cli/cli.c
|
@ -73,11 +73,11 @@ tr_strlratio( char * buf, double ratio, size_t buflen )
|
|||
else if( (int)ratio == TR_RATIO_INF )
|
||||
tr_strlcpy( buf, "Inf", buflen );
|
||||
else if( ratio < 10.0 )
|
||||
snprintf( buf, buflen, "%'.2f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.2f", ratio );
|
||||
else if( ratio < 100.0 )
|
||||
snprintf( buf, buflen, "%'.1f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.1f", ratio );
|
||||
else
|
||||
snprintf( buf, buflen, "%'.0f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.0f", ratio );
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ escape( char * out, const uint8_t * in, int in_len ) /* rfc2396 */
|
|||
if( is_rfc2396_alnum(*in) )
|
||||
*out++ = (char) *in++;
|
||||
else
|
||||
out += snprintf( out, 4, "%%%02X", (unsigned int)*in++ );
|
||||
out += tr_snprintf( out, 4, "%%%02X", (unsigned int)*in++ );
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
|
@ -183,20 +183,20 @@ getStatusStr( const tr_stat * st, char * buf, size_t buflen )
|
|||
{
|
||||
if( st->status & TR_STATUS_CHECK_WAIT )
|
||||
{
|
||||
snprintf( buf, buflen, "Waiting to verify local files" );
|
||||
tr_snprintf( buf, buflen, "Waiting to verify local files" );
|
||||
}
|
||||
else if( st->status & TR_STATUS_CHECK )
|
||||
{
|
||||
snprintf( buf, buflen, "Verifying local files (%.2f%%, %.2f%% valid)",
|
||||
100 * st->recheckProgress, 100.0 * st->percentDone );
|
||||
tr_snprintf( buf, buflen, "Verifying local files (%.2f%%, %.2f%% valid)",
|
||||
100 * st->recheckProgress, 100.0 * st->percentDone );
|
||||
}
|
||||
else if( st->status & TR_STATUS_DOWNLOAD )
|
||||
{
|
||||
char ratioStr[80];
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
snprintf( buf, buflen,
|
||||
"Progress: %.1f%%, dl from %d of %d peers (%.0f KB/s), "
|
||||
"ul to %d (%.0f KB/s) [%s]",
|
||||
tr_snprintf( buf, buflen,
|
||||
"Progress: %.1f%%, dl from %d of %d peers (%.0f KB/s), "
|
||||
"ul to %d (%.0f KB/s) [%s]",
|
||||
st->percentDone * 100.0,
|
||||
st->peersSendingToUs,
|
||||
st->peersConnected,
|
||||
|
@ -209,10 +209,10 @@ getStatusStr( const tr_stat * st, char * buf, size_t buflen )
|
|||
{
|
||||
char ratioStr[80];
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
snprintf( buf, buflen,
|
||||
"Seeding, uploading to %d of %d peer(s), %.0f KB/s [%s]",
|
||||
st->peersGettingFromUs, st->peersConnected,
|
||||
st->rateUpload, ratioStr );
|
||||
tr_snprintf( buf, buflen,
|
||||
"Seeding, uploading to %d of %d peer(s), %.0f KB/s [%s]",
|
||||
st->peersGettingFromUs, st->peersConnected,
|
||||
st->rateUpload, ratioStr );
|
||||
}
|
||||
else *buf = '\0';
|
||||
}
|
||||
|
|
|
@ -367,11 +367,11 @@ writeFunc( void * ptr, size_t size, size_t nmemb, void * buf )
|
|||
static void
|
||||
etaToString( char * buf, size_t buflen, int64_t eta )
|
||||
{
|
||||
if( eta < 0 ) snprintf( buf, buflen, "Unknown" );
|
||||
else if( eta < 60 ) snprintf( buf, buflen, "%"PRId64"sec", eta );
|
||||
else if( eta < (60*60) ) snprintf( buf, buflen, "%"PRId64" min", eta/60 );
|
||||
else if( eta < (60*60*24) ) snprintf( buf, buflen, "%"PRId64" hrs", eta/(60*60) );
|
||||
else snprintf( buf, buflen, "%"PRId64" days", eta/(60*60*24) );
|
||||
if( eta < 0 ) tr_snprintf( buf, buflen, "Unknown" );
|
||||
else if( eta < 60 ) tr_snprintf( buf, buflen, "%"PRId64"sec", eta );
|
||||
else if( eta < (60*60) ) tr_snprintf( buf, buflen, "%"PRId64" min", eta/60 );
|
||||
else if( eta < (60*60*24) ) tr_snprintf( buf, buflen, "%"PRId64" hrs", eta/(60*60) );
|
||||
else tr_snprintf( buf, buflen, "%"PRId64" days", eta/(60*60*24) );
|
||||
}
|
||||
|
||||
#define KILOBYTE_FACTOR 1024.0
|
||||
|
@ -385,11 +385,11 @@ strlratio( char * buf, double numerator, double denominator, size_t buflen )
|
|||
{
|
||||
const double ratio = numerator / denominator;
|
||||
if( ratio < 10.0 )
|
||||
snprintf( buf, buflen, "%'.2f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.2f", ratio );
|
||||
else if( ratio < 100.0 )
|
||||
snprintf( buf, buflen, "%'.1f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.1f", ratio );
|
||||
else
|
||||
snprintf( buf, buflen, "%'.0f", ratio );
|
||||
tr_snprintf( buf, buflen, "%'.0f", ratio );
|
||||
}
|
||||
else if( numerator )
|
||||
tr_strlcpy( buf, "Infinity", buflen );
|
||||
|
@ -404,18 +404,18 @@ strlsize( char * buf, int64_t size, size_t buflen )
|
|||
if( !size )
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else if( size < (int64_t)KILOBYTE_FACTOR )
|
||||
snprintf( buf, buflen, "%'"PRId64" bytes", (int64_t)size );
|
||||
tr_snprintf( buf, buflen, "%'"PRId64" bytes", (int64_t)size );
|
||||
else {
|
||||
double displayed_size;
|
||||
if (size < (int64_t)MEGABYTE_FACTOR) {
|
||||
displayed_size = (double) size / KILOBYTE_FACTOR;
|
||||
snprintf( buf, buflen, "%'.1f KB", displayed_size );
|
||||
tr_snprintf( buf, buflen, "%'.1f KB", displayed_size );
|
||||
} else if (size < (int64_t)GIGABYTE_FACTOR) {
|
||||
displayed_size = (double) size / MEGABYTE_FACTOR;
|
||||
snprintf( buf, buflen, "%'.1f MB", displayed_size );
|
||||
tr_snprintf( buf, buflen, "%'.1f MB", displayed_size );
|
||||
} else {
|
||||
displayed_size = (double) size / GIGABYTE_FACTOR;
|
||||
snprintf( buf, buflen, "%'.1f GB", displayed_size );
|
||||
tr_snprintf( buf, buflen, "%'.1f GB", displayed_size );
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
|
@ -472,7 +472,7 @@ printDetails( tr_benc * top )
|
|||
if( tr_bencDictFindInt( t, "status", &i ) )
|
||||
{
|
||||
if( isVerifying( i ) && tr_bencDictFindStr( t, "recheckProgress", &str ) )
|
||||
snprintf( buf, sizeof( buf ), " (%.0f%% Done)", 100.0*atof(str) );
|
||||
tr_snprintf( buf, sizeof( buf ), " (%.0f%% Done)", 100.0*atof(str) );
|
||||
else
|
||||
*buf = '\0';
|
||||
printf( " State: %s%s\n", torrentStatusToString( i ), buf );
|
||||
|
@ -677,7 +677,7 @@ printTorrentList( tr_benc * top )
|
|||
if( leftUntilDone )
|
||||
etaToString( etaStr, sizeof( etaStr ), eta );
|
||||
else
|
||||
snprintf( etaStr, sizeof( etaStr ), "Done" );
|
||||
tr_snprintf( etaStr, sizeof( etaStr ), "Done" );
|
||||
printf( "%3d %3d%% %-8s %5.1f %5.1f %5.1f %-11s %s\n",
|
||||
(int)id,
|
||||
(int)(100.0*(sizeWhenDone-leftUntilDone)/sizeWhenDone),
|
||||
|
|
|
@ -261,7 +261,7 @@ testing_port_begin( gpointer gdata )
|
|||
tr_handle * handle = g_object_get_data( G_OBJECT( data->label ), "handle" );
|
||||
const int port = gtk_spin_button_get_value_as_int( spin );
|
||||
char url[256];
|
||||
snprintf( url, sizeof(url), "http://portcheck.transmissionbt.com/%d", port );
|
||||
g_snprintf( url, sizeof(url), "http://portcheck.transmissionbt.com/%d", port );
|
||||
tr_webRun( handle, url, NULL, testing_port_done, data );
|
||||
}
|
||||
return FALSE;
|
||||
|
|
|
@ -30,7 +30,7 @@ testInt( void )
|
|||
const uint8_t * end;
|
||||
|
||||
/* good int string */
|
||||
snprintf( (char*)buf, sizeof( buf ), "i64e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i64e" );
|
||||
err = tr_bencParseInt( buf, buf+4, &end, &val );
|
||||
check( err == 0 );
|
||||
check( val == 64 );
|
||||
|
@ -51,21 +51,21 @@ testInt( void )
|
|||
check( end == NULL );
|
||||
|
||||
/* bad number */
|
||||
snprintf( (char*)buf, sizeof( buf ), "i6z4e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i6z4e" );
|
||||
err = tr_bencParseInt( buf, buf+5, &end, &val );
|
||||
check( err == TR_ERROR );
|
||||
check( val == 888 );
|
||||
check( end == NULL );
|
||||
|
||||
/* negative number */
|
||||
snprintf( (char*)buf, sizeof( buf ), "i-3e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i-3e" );
|
||||
err = tr_bencParseInt( buf, buf+4, &end, &val );
|
||||
check( err == TR_OK );
|
||||
check( val == -3 );
|
||||
check( end == buf + 4 );
|
||||
|
||||
/* zero */
|
||||
snprintf( (char*)buf, sizeof( buf ), "i0e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i0e" );
|
||||
err = tr_bencParseInt( buf, buf+4, &end, &val );
|
||||
check( err == TR_OK );
|
||||
check( val == 0 );
|
||||
|
@ -74,7 +74,7 @@ testInt( void )
|
|||
/* no leading zeroes allowed */
|
||||
val = 0;
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "i04e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i04e" );
|
||||
err = tr_bencParseInt( buf, buf+4, &end, &val );
|
||||
check( err == TR_ERROR );
|
||||
check( val == 0 );
|
||||
|
@ -93,7 +93,7 @@ testStr( void )
|
|||
size_t len;
|
||||
|
||||
/* good string */
|
||||
snprintf( (char*)buf, sizeof( buf ), "4:boat" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "4:boat" );
|
||||
err = tr_bencParseStr( buf, buf+6, &end, &str, &len );
|
||||
check( err == TR_OK );
|
||||
check( !strcmp( (char*)str, "boat" ) );
|
||||
|
@ -112,7 +112,7 @@ testStr( void )
|
|||
check( !len );
|
||||
|
||||
/* empty string */
|
||||
snprintf( (char*)buf, sizeof( buf ), "0:" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "0:" );
|
||||
err = tr_bencParseStr( buf, buf+2, &end, &str, &len );
|
||||
check( err == TR_OK );
|
||||
check( !*str );
|
||||
|
@ -124,7 +124,7 @@ testStr( void )
|
|||
len = 0;
|
||||
|
||||
/* short string */
|
||||
snprintf( (char*)buf, sizeof( buf ), "3:boat" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "3:boat" );
|
||||
err = tr_bencParseStr( buf, buf+6, &end, &str, &len );
|
||||
check( err == TR_OK );
|
||||
check( !strcmp( (char*)str, "boa" ) );
|
||||
|
@ -178,7 +178,7 @@ testParse( void )
|
|||
int64_t i;
|
||||
char * saved;
|
||||
|
||||
snprintf( (char*)buf, sizeof( buf ), "i64e" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "i64e" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
|
||||
check( !err );
|
||||
check( tr_bencGetInt( &val, &i ) );
|
||||
|
@ -186,7 +186,7 @@ testParse( void )
|
|||
check( end == buf + 4 );
|
||||
tr_bencFree( &val );
|
||||
|
||||
snprintf( (char*)buf, sizeof( buf ), "li64ei32ei16ee" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "li64ei32ei16ee" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
|
||||
check( !err );
|
||||
check( end == buf + strlen( (char*)buf ) );
|
||||
|
@ -203,13 +203,13 @@ testParse( void )
|
|||
tr_bencFree( &val );
|
||||
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "lllee" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "lllee" );
|
||||
err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val , &end );
|
||||
check( err );
|
||||
check( end == NULL );
|
||||
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "le" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "le" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val , &end );
|
||||
check( !err );
|
||||
check( end == buf + 2 );
|
||||
|
@ -241,7 +241,7 @@ testParse( void )
|
|||
* parse an unsorted dict
|
||||
* save as a sorted dict */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "lld1:bi32e1:ai64eeee" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "lld1:bi32e1:ai64eeee" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
|
||||
check( !err );
|
||||
check( end == buf + strlen( (const char*)buf ) );
|
||||
|
@ -254,7 +254,7 @@ testParse( void )
|
|||
|
||||
/* too many endings */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "leee" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "leee" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
|
||||
check( !err );
|
||||
check( end == buf + 2 );
|
||||
|
@ -265,13 +265,13 @@ testParse( void )
|
|||
|
||||
/* no ending */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "l1:a1:b1:c" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "l1:a1:b1:c" );
|
||||
err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
|
||||
check( err );
|
||||
|
||||
/* incomplete string */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "1:" );
|
||||
tr_snprintf( (char*)buf, sizeof( buf ), "1:" );
|
||||
err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
|
||||
check( err );
|
||||
|
||||
|
|
|
@ -636,7 +636,7 @@ tr_benc*
|
|||
tr_bencDictAddDouble( tr_benc * dict, const char * key, double d )
|
||||
{
|
||||
char buf[128];
|
||||
snprintf( buf, sizeof( buf ), "%f", d );
|
||||
tr_snprintf( buf, sizeof( buf ), "%f", d );
|
||||
return tr_bencDictAddStr( dict, key, buf );
|
||||
}
|
||||
tr_benc*
|
||||
|
|
|
@ -65,26 +65,26 @@ getMnemonicEnd( char ch )
|
|||
static void
|
||||
three_digits( char * buf, size_t buflen, const char * name, const uint8_t * digits )
|
||||
{
|
||||
snprintf( buf, buflen, "%s %d.%d.%d", name,
|
||||
charint( digits[0] ),
|
||||
charint( digits[1] ),
|
||||
charint( digits[2] ) );
|
||||
tr_snprintf( buf, buflen, "%s %d.%d.%d", name,
|
||||
charint( digits[0] ),
|
||||
charint( digits[1] ),
|
||||
charint( digits[2] ) );
|
||||
}
|
||||
static void
|
||||
four_digits( char * buf, size_t buflen, const char * name, const uint8_t * digits )
|
||||
{
|
||||
snprintf( buf, buflen, "%s %d.%d.%d.%d", name,
|
||||
charint( digits[0] ),
|
||||
charint( digits[1] ),
|
||||
charint( digits[2] ),
|
||||
charint( digits[3] ) );
|
||||
tr_snprintf( buf, buflen, "%s %d.%d.%d.%d", name,
|
||||
charint( digits[0] ),
|
||||
charint( digits[1] ),
|
||||
charint( digits[2] ),
|
||||
charint( digits[3] ) );
|
||||
}
|
||||
static void
|
||||
two_major_two_minor( char * buf, size_t buflen, const char * name, const uint8_t * digits )
|
||||
{
|
||||
snprintf( buf, buflen, "%s %d.%02d", name,
|
||||
strint( digits, 2 ),
|
||||
strint( digits+2, 2 ) );
|
||||
tr_snprintf( buf, buflen, "%s %d.%02d", name,
|
||||
strint( digits, 2 ),
|
||||
strint( digits+2, 2 ) );
|
||||
}
|
||||
static void
|
||||
no_version( char * buf, size_t buflen, const char * name )
|
||||
|
@ -96,9 +96,9 @@ static void
|
|||
mainline_style( char * buf, size_t buflen, const char * name, const uint8_t * id )
|
||||
{
|
||||
if( id[4] == '-' && id[6] == '-' )
|
||||
snprintf( buf, buflen, "%s %c.%c.%c", name, id[1], id[3], id[5] );
|
||||
tr_snprintf( buf, buflen, "%s %c.%c.%c", name, id[1], id[3], id[5] );
|
||||
else if( id[5] == '-' )
|
||||
snprintf( buf, buflen, "%s %c.%c%c.%c", name, id[1], id[3], id[4], id[6] );
|
||||
tr_snprintf( buf, buflen, "%s %c.%c%c.%c", name, id[1], id[3], id[4], id[6] );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -137,9 +137,9 @@ decodeBitCometClient( char * buf, size_t buflen, const uint8_t * id )
|
|||
* Bitcoment 1.0 and onwards are of the form x.y.
|
||||
*/
|
||||
if( is_bitlord && major>0 )
|
||||
snprintf( buf, buflen, "%s%s%d.%d", name, mod, major, minor );
|
||||
tr_snprintf( buf, buflen, "%s%s%d.%d", name, mod, major, minor );
|
||||
else
|
||||
snprintf( buf, buflen, "%s%s%d.%02d", name, mod, major, minor );
|
||||
tr_snprintf( buf, buflen, "%s%s%d.%02d", name, mod, major, minor );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -159,18 +159,18 @@ tr_clientForId( char * buf, size_t buflen, const void * id_in )
|
|||
{
|
||||
if( !memcmp( id+1, "UT", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s",
|
||||
strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) );
|
||||
tr_snprintf( buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s",
|
||||
strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) );
|
||||
}
|
||||
|
||||
else if( !memcmp( id+1, "TR", 2 ) )
|
||||
{
|
||||
if( !memcmp( id+3, "000", 3 ) ) /* very old client style: -TR0006- is 0.6 */
|
||||
snprintf( buf, buflen, "Transmission 0.%c", id[6] );
|
||||
tr_snprintf( buf, buflen, "Transmission 0.%c", id[6] );
|
||||
else if( !memcmp( id+3, "00", 2) ) /* previous client style: -TR0072- is 0.72 */
|
||||
snprintf( buf, buflen, "Transmission 0.%02d", strint(id+5,2) );
|
||||
tr_snprintf( buf, buflen, "Transmission 0.%02d", strint(id+5,2) );
|
||||
else /* current client style: -TR111Z- is 1.11+ */
|
||||
snprintf( buf, buflen, "Transmission %d.%02d%s", strint(id+3,1), strint(id+4,2),
|
||||
tr_snprintf( buf, buflen, "Transmission %d.%02d%s", strint(id+3,1), strint(id+4,2),
|
||||
id[6]=='Z' || id[6]=='X' ? "+" : "" );
|
||||
}
|
||||
|
||||
|
@ -185,9 +185,9 @@ tr_clientForId( char * buf, size_t buflen, const void * id_in )
|
|||
else if( !memcmp( id+1, "KT", 2 ) )
|
||||
{
|
||||
if( id[5] == 'D' )
|
||||
snprintf( buf, buflen, "KTorrent %d.%d Dev %d", charint(id[3]), charint(id[4]), charint(id[6]) );
|
||||
tr_snprintf( buf, buflen, "KTorrent %d.%d Dev %d", charint(id[3]), charint(id[4]), charint(id[6]) );
|
||||
else if( id[5] == 'R' )
|
||||
snprintf( buf, buflen, "KTorrent %d.%d RC %d", charint(id[3]), charint(id[4]), charint(id[6]) );
|
||||
tr_snprintf( buf, buflen, "KTorrent %d.%d RC %d", charint(id[3]), charint(id[4]), charint(id[6]) );
|
||||
else
|
||||
three_digits( buf, buflen, "KTorrent", id+3 );
|
||||
}
|
||||
|
@ -250,25 +250,25 @@ tr_clientForId( char * buf, size_t buflen, const void * id_in )
|
|||
|
||||
else if( !memcmp( id+1, "BB", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "BitBuddy %c.%c%c%c", id[3], id[4], id[5], id[6] );
|
||||
tr_snprintf( buf, buflen, "BitBuddy %c.%c%c%c", id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( id+1, "BR", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "BitRocket %c.%c (%c%c)", id[3], id[4], id[5], id[6] );
|
||||
tr_snprintf( buf, buflen, "BitRocket %c.%c (%c%c)", id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( id+1, "CT", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "CTorrent %d.%d.%02d", charint(id[3]), charint(id[4]), strint(id+5,2) );
|
||||
tr_snprintf( buf, buflen, "CTorrent %d.%d.%02d", charint(id[3]), charint(id[4]), strint(id+5,2) );
|
||||
}
|
||||
else if( !memcmp( id+1, "XX", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "Xtorrent %d.%d (%d)", charint(id[3]), charint(id[4]), strint(id+5,2) );
|
||||
tr_snprintf( buf, buflen, "Xtorrent %d.%d (%d)", charint(id[3]), charint(id[4]), strint(id+5,2) );
|
||||
}
|
||||
else if( !memcmp( id+1, "BOW", 3 ) )
|
||||
{
|
||||
if( !memcmp( &id[4], "A0B", 3 ) ) snprintf( buf, buflen, "Bits on Wheels 1.0.5" );
|
||||
else if( !memcmp( &id[4], "A0C", 3 ) ) snprintf( buf, buflen, "Bits on Wheels 1.0.6" );
|
||||
else snprintf( buf, buflen, "Bits on Wheels %c.%c.%c", id[4], id[5], id[5] );
|
||||
if( !memcmp( &id[4], "A0B", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.5" );
|
||||
else if( !memcmp( &id[4], "A0C", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.6" );
|
||||
else tr_snprintf( buf, buflen, "Bits on Wheels %c.%c.%c", id[4], id[5], id[5] );
|
||||
}
|
||||
|
||||
if( *buf )
|
||||
|
@ -317,45 +317,45 @@ tr_clientForId( char * buf, size_t buflen, const void * id_in )
|
|||
/* Everything else */
|
||||
else if( !memcmp( id, "S3", 2 ) && id[2] == '-' && id[4] == '-' && id[6] == '-' )
|
||||
{
|
||||
snprintf( buf, buflen, "Amazon S3 %c.%c.%c", id[3], id[5], id[7] );
|
||||
tr_snprintf( buf, buflen, "Amazon S3 %c.%c.%c", id[3], id[5], id[7] );
|
||||
}
|
||||
else if( !memcmp( id, "OP", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "Opera (Build %c%c%c%c)", id[2], id[3], id[4], id[5] );
|
||||
tr_snprintf( buf, buflen, "Opera (Build %c%c%c%c)", id[2], id[3], id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( id, "-ML", 3 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "MLDonkey %c%c%c%c%c", id[3], id[4], id[5], id[6], id[7] );
|
||||
tr_snprintf( buf, buflen, "MLDonkey %c%c%c%c%c", id[3], id[4], id[5], id[6], id[7] );
|
||||
}
|
||||
else if( !memcmp( id, "DNA", 3 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "BitTorrent DNA %d.%d.%d", strint(id+3,2),
|
||||
strint(id+5,2),
|
||||
strint(id+7,2) );
|
||||
tr_snprintf( buf, buflen, "BitTorrent DNA %d.%d.%d", strint(id+3,2),
|
||||
strint(id+5,2),
|
||||
strint(id+7,2) );
|
||||
}
|
||||
else if( !memcmp( id, "Plus", 4 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
|
||||
tr_snprintf( buf, buflen, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( id, "XBT", 3 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "XBT Client %c.%c.%c%s", id[3], id[4], id[5], getMnemonicEnd(id[6]) );
|
||||
tr_snprintf( buf, buflen, "XBT Client %c.%c.%c%s", id[3], id[4], id[5], getMnemonicEnd(id[6]) );
|
||||
}
|
||||
else if( !memcmp( id, "Mbrst", 5 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "burst! %c.%c.%c", id[5], id[7], id[9] );
|
||||
tr_snprintf( buf, buflen, "burst! %c.%c.%c", id[5], id[7], id[9] );
|
||||
}
|
||||
else if( !memcmp( id, "btpd", 4 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
|
||||
tr_snprintf( buf, buflen, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
|
||||
}
|
||||
else if( !memcmp( id, "BLZ", 3 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "Blizzard Downloader %d.%d", id[3]+1, id[4] );
|
||||
tr_snprintf( buf, buflen, "Blizzard Downloader %d.%d", id[3]+1, id[4] );
|
||||
}
|
||||
else if( '\0' == id[0] && !memcmp( &id[1], "BS", 2 ) )
|
||||
{
|
||||
snprintf( buf, buflen, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) );
|
||||
tr_snprintf( buf, buflen, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) );
|
||||
}
|
||||
|
||||
/* No match */
|
||||
|
@ -364,10 +364,10 @@ tr_clientForId( char * buf, size_t buflen, const void * id_in )
|
|||
if( isprint( id[0] ) && isprint( id[1] ) && isprint( id[2] ) &&
|
||||
isprint( id[3] ) && isprint( id[4] ) && isprint( id[5] ) &&
|
||||
isprint( id[6] ) && isprint( id[7] ) )
|
||||
snprintf( buf, buflen, "%c%c%c%c%c%c%c%c",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
tr_snprintf( buf, buflen, "%c%c%c%c%c%c%c%c",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
else
|
||||
snprintf( buf, buflen, "0x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
tr_snprintf( buf, buflen, "0x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ fastResumeFileName( char * buf, size_t buflen, const tr_torrent * tor, int tag )
|
|||
else
|
||||
{
|
||||
char base[1024];
|
||||
snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_buildPath( buf, buflen, cacheDir, base, NULL );
|
||||
}
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ loadResumeFile( const tr_torrent * tor, size_t * len )
|
|||
if( !ret && tor->handle->tag )
|
||||
{
|
||||
char base[1024];
|
||||
snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_buildPath( path, sizeof(path), cacheDir, base, NULL );
|
||||
ret = tr_loadFile( path, len );
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ tr_fastResumeRemove( const tr_torrent * tor )
|
|||
if( tor->handle->tag )
|
||||
{
|
||||
char base[1024];
|
||||
snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_snprintf( base, sizeof(base), "%s-%s", hash, tor->handle->tag );
|
||||
tr_buildPath( path, sizeof(path), cacheDir, base, NULL );
|
||||
unlink( path );
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ callback( void * vdata, int type, const JSON_value * value )
|
|||
|
||||
case JSON_T_FLOAT: {
|
||||
char buf[128];
|
||||
snprintf( buf, sizeof( buf ), "%f", (double)value->vu.float_value );
|
||||
tr_snprintf( buf, sizeof( buf ), "%f", (double)value->vu.float_value );
|
||||
tr_bencInitStrDup( getNode( data ), buf );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h> /* FILE, snprintf, stderr */
|
||||
#include <stdio.h> /* FILE, stderr */
|
||||
#include <stdlib.h> /* qsort */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -207,7 +207,7 @@ getHashInfo ( tr_metainfo_builder * b )
|
|||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
||||
if( !fp ) {
|
||||
b->my_errno = errno;
|
||||
snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
|
||||
tr_snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
|
||||
b->result = TR_MAKEMETA_IO_READ;
|
||||
tr_free( ret );
|
||||
return NULL;
|
||||
|
@ -237,7 +237,7 @@ getHashInfo ( tr_metainfo_builder * b )
|
|||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
||||
if( !fp ) {
|
||||
b->my_errno = errno;
|
||||
snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
|
||||
tr_snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
|
||||
b->result = TR_MAKEMETA_IO_READ;
|
||||
tr_free( ret );
|
||||
return NULL;
|
||||
|
@ -480,7 +480,7 @@ tr_makeMetaInfo( tr_metainfo_builder * builder,
|
|||
builder->outputFile = tr_strdup( outputFile );
|
||||
else {
|
||||
char out[MAX_PATH_LENGTH];
|
||||
snprintf( out, sizeof(out), "%s.torrent", builder->top);
|
||||
tr_snprintf( out, sizeof(out), "%s.torrent", builder->top);
|
||||
builder->outputFile = tr_strdup( out );
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ getTorrentFilename( const tr_handle * handle,
|
|||
{
|
||||
const char * dir = tr_getTorrentDir( handle );
|
||||
char base[MAX_PATH_LENGTH];
|
||||
snprintf( base, sizeof( base ), "%s.%16.16s.torrent", inf->name, inf->hashString );
|
||||
tr_snprintf( base, sizeof( base ), "%s.%16.16s.torrent", inf->name, inf->hashString );
|
||||
tr_buildPath( buf, buflen, dir, base, NULL );
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ getTorrentOldFilename( const tr_handle * handle,
|
|||
else
|
||||
{
|
||||
char base[1024];
|
||||
snprintf( base, sizeof(base), "%s-%s", info->hashString, handle->tag );
|
||||
tr_snprintf( base, sizeof(base), "%s-%s", info->hashString, handle->tag );
|
||||
tr_buildPath( name, len, torDir, base, NULL );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,6 @@ tr_netNtop( const struct in_addr * addr, char * buf, int len )
|
|||
const uint8_t * cast;
|
||||
|
||||
cast = (const uint8_t *)addr;
|
||||
snprintf( buf, len, "%hhu.%hhu.%hhu.%hhu",
|
||||
cast[0], cast[1], cast[2], cast[3] );
|
||||
tr_snprintf( buf, len, "%hhu.%hhu.%hhu.%hhu",
|
||||
cast[0], cast[1], cast[2], cast[3] );
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ const char*
|
|||
tr_peerIoAddrStr( const struct in_addr * addr, uint16_t port )
|
||||
{
|
||||
static char buf[512];
|
||||
snprintf( buf, sizeof(buf), "%s:%u", inet_ntoa( *addr ), ntohs( port ) );
|
||||
tr_snprintf( buf, sizeof(buf), "%s:%u", inet_ntoa( *addr ), ntohs( port ) );
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -477,7 +477,7 @@ tr_getDefaultConfigDir( void )
|
|||
|
||||
if(( s = getenv( "TRANSMISSION_HOME" )))
|
||||
{
|
||||
snprintf( path, sizeof( path ), s );
|
||||
tr_snprintf( path, sizeof( path ), s );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -531,11 +531,11 @@ tr_getClutchDir( const tr_session * session UNUSED )
|
|||
|
||||
if(( s = getenv( "CLUTCH_HOME" )))
|
||||
{
|
||||
snprintf( path, sizeof( path ), s );
|
||||
tr_snprintf( path, sizeof( path ), s );
|
||||
}
|
||||
else if(( s = getenv( "TRANSMISSION_WEB_HOME" )))
|
||||
{
|
||||
snprintf( path, sizeof( path ), s );
|
||||
tr_snprintf( path, sizeof( path ), s );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -52,9 +52,9 @@ getResumeFilename( char * buf, size_t buflen, const tr_torrent * tor )
|
|||
{
|
||||
const char * dir = tr_getResumeDir( tor->handle );
|
||||
char base[MAX_PATH_LENGTH];
|
||||
snprintf( base, sizeof( base ), "%s.%16.16s.resume",
|
||||
tor->info.name,
|
||||
tor->info.hashString );
|
||||
tr_snprintf( base, sizeof( base ), "%s.%16.16s.resume",
|
||||
tor->info.name,
|
||||
tor->info.hashString );
|
||||
tr_buildPath( buf, buflen, dir, base, NULL );
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ startServer( tr_rpc_server * server )
|
|||
edit_passwords( passwd, MY_REALM, server->username, server->password );
|
||||
|
||||
server->ctx = shttpd_init( );
|
||||
snprintf( ports, sizeof( ports ), "%d", server->port );
|
||||
tr_snprintf( ports, sizeof( ports ), "%d", server->port );
|
||||
shttpd_register_uri( server->ctx, "/transmission/rpc", handle_rpc, server );
|
||||
shttpd_register_uri( server->ctx, "/transmission/upload", handle_upload, server );
|
||||
|
||||
|
|
|
@ -157,8 +157,8 @@ loadBlocklists( tr_session * session )
|
|||
const char * dot = strrchr( d->d_name, '.' );
|
||||
const int len = dot ? dot - d->d_name : (int)strlen( d->d_name );
|
||||
char tmp[MAX_PATH_LENGTH];
|
||||
snprintf( tmp, sizeof( tmp ),
|
||||
"%s%c%*.*s.bin", dirname, TR_PATH_DELIMITER, len, len, d->d_name );
|
||||
tr_snprintf( tmp, sizeof( tmp ),
|
||||
"%s%c%*.*s.bin", dirname, TR_PATH_DELIMITER, len, len, d->d_name );
|
||||
b = _tr_blocklistNew( tmp, isEnabled );
|
||||
_tr_blocklistSetContent( b, filename );
|
||||
tr_list_append( &list, b );
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h> /* snprintf */
|
||||
#include <stdlib.h>
|
||||
#include <string.h> /* strcmp, strchr */
|
||||
|
||||
|
@ -849,7 +848,7 @@ escape( char * out, const uint8_t * in, int in_len ) /* rfc2396 */
|
|||
if( is_rfc2396_alnum(*in) )
|
||||
*out++ = (char) *in++;
|
||||
else
|
||||
out += snprintf( out, 4, "%%%02X", (unsigned int)*in++ );
|
||||
out += tr_snprintf( out, 4, "%%%02X", (unsigned int)*in++ );
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
|
@ -1021,18 +1020,18 @@ tr_trackerStat( const tr_tracker * t,
|
|||
if( t->lastScrapeResponse == -1 ) /* never been scraped */
|
||||
*setme->scrapeResponse = '\0';
|
||||
else
|
||||
snprintf( setme->scrapeResponse,
|
||||
sizeof( setme->scrapeResponse ),
|
||||
"%s (%ld)",
|
||||
tr_webGetResponseStr( t->lastScrapeResponse ),
|
||||
t->lastScrapeResponse );
|
||||
tr_snprintf( setme->scrapeResponse,
|
||||
sizeof( setme->scrapeResponse ),
|
||||
"%s (%ld)",
|
||||
tr_webGetResponseStr( t->lastScrapeResponse ),
|
||||
t->lastScrapeResponse );
|
||||
|
||||
if( t->lastAnnounceResponse == -1 ) /* never been announced */
|
||||
*setme->announceResponse = '\0';
|
||||
else
|
||||
snprintf( setme->announceResponse,
|
||||
sizeof( setme->announceResponse ),
|
||||
"%s (%ld)",
|
||||
tr_webGetResponseStr( t->lastAnnounceResponse ),
|
||||
t->lastAnnounceResponse );
|
||||
tr_snprintf( setme->announceResponse,
|
||||
sizeof( setme->announceResponse ),
|
||||
"%s (%ld)",
|
||||
tr_webGetResponseStr( t->lastAnnounceResponse ),
|
||||
t->lastAnnounceResponse );
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h> /* snprintf */
|
||||
|
||||
#include <miniupnp/miniupnpc.h>
|
||||
#include <miniupnp/upnpcommands.h>
|
||||
|
@ -112,7 +111,7 @@ tr_upnpPulse( tr_upnp * handle, int port, int isEnabled )
|
|||
if( handle->state == TR_UPNP_UNMAP )
|
||||
{
|
||||
char portStr[16];
|
||||
snprintf( portStr, sizeof(portStr), "%d", handle->port );
|
||||
tr_snprintf( portStr, sizeof(portStr), "%d", handle->port );
|
||||
UPNP_DeletePortMapping( handle->urls.controlURL,
|
||||
handle->data.servicetype,
|
||||
portStr, "TCP" );
|
||||
|
@ -133,7 +132,7 @@ tr_upnpPulse( tr_upnp * handle, int port, int isEnabled )
|
|||
{
|
||||
int err = -1;
|
||||
char portStr[16];
|
||||
snprintf( portStr, sizeof(portStr), "%d", port );
|
||||
tr_snprintf( portStr, sizeof(portStr), "%d", port );
|
||||
errno = 0;
|
||||
|
||||
if( !handle->urls.controlURL || !handle->data.servicetype )
|
||||
|
|
|
@ -167,7 +167,7 @@ tr_getLogTimeStr( char * buf, int buflen )
|
|||
#endif
|
||||
strftime( tmp, sizeof(tmp), "%H:%M:%S", &now_tm );
|
||||
milliseconds = (int)(tv.tv_usec / 1000);
|
||||
snprintf( buf, buflen, "%s.%03d", tmp, milliseconds );
|
||||
tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -521,7 +521,7 @@ tr_mkdirp( const char * path_in, int permissions )
|
|||
{
|
||||
/* Node exists but isn't a folder */
|
||||
char buf[MAX_PATH_LENGTH];
|
||||
snprintf( buf, sizeof( buf ), _( "File \"%s\" is in the way" ), path );
|
||||
tr_snprintf( buf, sizeof( buf ), _( "File \"%s\" is in the way" ), path );
|
||||
tr_err( _( "Couldn't create \"%1$s\": %2$s" ), path_in, buf );
|
||||
tr_free( path );
|
||||
errno = ENOTDIR;
|
||||
|
@ -970,6 +970,19 @@ tr_stringEndsWith( const char * str, const char * end )
|
|||
return slen>=elen && !memcmp( &str[slen-elen], end, elen );
|
||||
}
|
||||
|
||||
int
|
||||
tr_snprintf( char * buf, size_t buflen, const char * fmt, ... )
|
||||
{
|
||||
int len;
|
||||
va_list args;
|
||||
va_start( args, fmt );
|
||||
len = evutil_vsnprintf( buf, buflen, fmt, args );
|
||||
va_end( args );
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
|
|
|
@ -197,6 +197,7 @@ char* tr_base64_encode( const void * input, int inlen, int *outlen ) TR_GNUC_MAL
|
|||
char* tr_base64_decode( const void * input, int inlen, int *outlen ) TR_GNUC_MALLOC;
|
||||
|
||||
size_t tr_strlcpy( char * dst, const char * src, size_t siz );
|
||||
int tr_snprintf( char * buf, size_t buflen, const char * fmt, ... );
|
||||
|
||||
int tr_stringEndsWith( const char * string, const char * end );
|
||||
|
||||
|
|
Loading…
Reference in New Issue