use C99 string formatting macros for platform independence

This commit is contained in:
Arvid Norberg 2009-05-15 15:52:15 +00:00
parent 6e39f24dcf
commit 53f890608d
4 changed files with 19 additions and 6 deletions

View File

@ -1262,7 +1262,7 @@ int main(int argc, char* argv[])
if (s.num_incomplete >= 0) downloaders = s.num_incomplete; if (s.num_incomplete >= 0) downloaders = s.num_incomplete;
else downloaders = s.list_peers - s.list_seeds; else downloaders = s.list_peers - s.list_seeds;
snprintf(str, sizeof(str), "%-13s download: (%s%s%s) upload: %s%s%s (%s%s%s) swarm: %4d:%4d" snprintf(str, sizeof(str), "%-13s down: (%s%s%s) up: %s%s%s (%s%s%s) swarm: %4d:%4d"
" bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x%s\n" " bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x%s\n"
, (paused && !auto_managed)?"paused":(paused && auto_managed)?"queued":state_str[s.state] , (paused && !auto_managed)?"paused":(paused && auto_managed)?"queued":state_str[s.state]
, esc("32"), add_suffix(s.total_download).c_str(), term , esc("32"), add_suffix(s.total_download).c_str(), term
@ -1291,7 +1291,7 @@ int main(int argc, char* argv[])
progress_bar_color = "32"; // green progress_bar_color = "32"; // green
} }
snprintf(str, sizeof(str), " %-10s: %s%-10lld%s Bytes %6.2f%% %s\n" snprintf(str, sizeof(str), " %-10s: %s%-10"PRId64"%s Bytes %6.2f%% %s\n"
, sequential_download?"sequential":"progress" , sequential_download?"sequential":"progress"
, esc("32"), s.total_done, esc("0") , esc("32"), s.total_done, esc("0")
, s.progress*100.f , s.progress*100.f
@ -1344,7 +1344,7 @@ int main(int argc, char* argv[])
out += str; out += str;
snprintf(str, sizeof(str), "==== waste: %s fail: %s unchoked: %d / %d " snprintf(str, sizeof(str), "==== waste: %s fail: %s unchoked: %d / %d "
"bw queues: %8d (%d) | %8d (%d) cache: w: %lld%% r: %lld%% size: %s (%s) / %s ===\n" "bw queues: %8d (%d) | %8d (%d) cache: w: %"PRId64"%% r: %lld%% size: %s (%s) / %s ===\n"
, add_suffix(sess_stat.total_redundant_bytes).c_str() , add_suffix(sess_stat.total_redundant_bytes).c_str()
, add_suffix(sess_stat.total_failed_bytes).c_str() , add_suffix(sess_stat.total_failed_bytes).c_str()
, sess_stat.num_unchoked, sess_stat.allowed_upload_slots , sess_stat.num_unchoked, sess_stat.allowed_upload_slots
@ -1365,7 +1365,7 @@ int main(int argc, char* argv[])
if (show_dht_status) if (show_dht_status)
{ {
snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d total DHT size: %lld\n" snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d total DHT size: %"PRId64"\n"
, sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes); , sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes);
out += str; out += str;

View File

@ -104,7 +104,7 @@ namespace libtorrent
: torrent_alert(h) : torrent_alert(h)
, buffer(d) , buffer(d)
, piece(p) , piece(p)
, size(s) , size(s)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const

View File

@ -36,6 +36,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/version.hpp> #include <boost/version.hpp>
#ifndef WIN32
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#endif
#ifndef PRId64
#ifdef _WIN32
#define PRId64 "I64d"
#else
#define PRId64 "lld"
#endif
#endif
#if defined(__GNUC__) && __GNUC__ >= 4 #if defined(__GNUC__) && __GNUC__ >= 4
#define TORRENT_DEPRECATED __attribute__ ((deprecated)) #define TORRENT_DEPRECATED __attribute__ ((deprecated))

View File

@ -381,7 +381,7 @@ namespace libtorrent
case lazy_entry::int_t: case lazy_entry::int_t:
{ {
char str[100]; char str[100];
snprintf(str, sizeof(str), "%lld", e.int_value()); snprintf(str, sizeof(str), "%"PRId64, e.int_value());
return str; return str;
} }
case lazy_entry::string_t: case lazy_entry::string_t: