From ab15d06d13484df246eb0fbd9ab6a6012ed81153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Wed, 29 Aug 2012 23:59:17 +0600 Subject: "%llu" replaced with "%" PRIu64 On some architectures, uint64_t is defined as: typedef unsigned long long int __u64; on another architectures as: typedef unsigned long int __u64; So, according to man 3 printf, uint64_t should be printed as "%llu" on some architectures, and as "%lu" on another. The same for scanf. To eliminate that challenge, there is inttypes.h, in which appropriate constants are defined for current architecture. 32-bit types (and even 16 and 8 bit types) should be printed using such constants if printed variable defined as uint_XXXt or intXXXt type. But in reality 32-bit and less types does not gain run-time error (except in scanf), because they pushed to stack as 32-bit values at least. So, I decide not to fix that. --- lib/netfilter/ct_obj.c | 2 +- lib/route/cls/u32.c | 2 +- lib/route/link.c | 4 ++-- lib/route/link/inet6.c | 38 +++++++++++++++++++------------------- lib/route/neightbl.c | 21 ++++++++++++++++----- src/nl-list-sockets.c | 2 +- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/lib/netfilter/ct_obj.c b/lib/netfilter/ct_obj.c index 70a814f..f57b15e 100644 --- a/lib/netfilter/ct_obj.c +++ b/lib/netfilter/ct_obj.c @@ -277,7 +277,7 @@ static void ct_dump_stats(struct nl_object *a, struct nl_dump_params *p) for (i=0; i<=1; i++) { res = nl_cancel_down_bytes(nfnl_ct_get_bytes(ct, i), &unit); packets = nfnl_ct_get_packets(ct, i); - nl_dump_line(p, " %s %10llu %7.2f %s\n", names[i], packets, res, unit); + nl_dump_line(p, " %s %10" PRIu64 " %7.2f %s\n", names[i], packets, res, unit); } } diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c index d3e326d..aa9eb77 100644 --- a/lib/route/cls/u32.c +++ b/lib/route/cls/u32.c @@ -306,7 +306,7 @@ static void u32_dump_stats(struct rtnl_tc *tc, void *data, if (u->cu_mask & U32_ATTR_PCNT) { struct tc_u32_pcnt *pc = u->cu_pcnt->d_data; nl_dump(p, "\n"); - nl_dump_line(p, " hit %8llu count %8llu\n", + nl_dump_line(p, " hit %8" PRIu64 " count %8" PRIu64 "\n", pc->rhit, pc->rcnt); } } diff --git a/lib/route/link.c b/lib/route/link.c index aea43b9..0e8ac07 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -662,7 +662,7 @@ static void link_dump_stats(struct nl_object *obj, struct nl_dump_params *p) res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_RX_BYTES], &unit); - strcpy(fmt, " RX %X.2f %s %10llu %10llu %10llu %10llu %10llu\n"); + strcpy(fmt, " RX %X.2f %s %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 "\n"); fmt[9] = *unit == 'B' ? '9' : '7'; nl_dump_line(p, fmt, res, unit, @@ -674,7 +674,7 @@ static void link_dump_stats(struct nl_object *obj, struct nl_dump_params *p) res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_TX_BYTES], &unit); - strcpy(fmt, " TX %X.2f %s %10llu %10llu %10llu %10llu %10llu\n"); + strcpy(fmt, " TX %X.2f %s %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 "\n"); fmt[9] = *unit == 'B' ? '9' : '7'; nl_dump_line(p, fmt, res, unit, diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c index 5f75342..9ee8226 100644 --- a/lib/route/link/inet6.c +++ b/lib/route/link/inet6.c @@ -242,78 +242,78 @@ static void inet6_dump_stats(struct rtnl_link *link, nl_dump(p, " IPv6: InPkts InOctets " " InDiscards InDelivers\n"); - nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_INPKTS]); + nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s ", octets, octetsUnit); else - nl_dump(p, "%16llu B ", 0); + nl_dump(p, "%16" PRIu64 " B ", 0); - nl_dump(p, "%18llu %18llu\n", + nl_dump(p, "%18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_INDISCARDS], link->l_stats[RTNL_LINK_IP6_INDELIVERS]); nl_dump(p, " OutPkts OutOctets " " OutDiscards OutForwards\n"); - nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_OUTPKTS]); + nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s ", octets, octetsUnit); else - nl_dump(p, "%16llu B ", 0); + nl_dump(p, "%16" PRIu64 " B ", 0); - nl_dump(p, "%18llu %18llu\n", + nl_dump(p, "%18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_OUTDISCARDS], link->l_stats[RTNL_LINK_IP6_OUTFORWDATAGRAMS]); nl_dump(p, " InMcastPkts InMcastOctets " " InBcastPkts InBcastOctests\n"); - nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_INMCASTPKTS]); + nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INMCASTPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INMCASTOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s ", octets, octetsUnit); else - nl_dump(p, "%16llu B ", 0); + nl_dump(p, "%16" PRIu64 " B ", 0); - nl_dump(p, "%18llu ", link->l_stats[RTNL_LINK_IP6_INBCASTPKTS]); + nl_dump(p, "%18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INBCASTPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INBCASTOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s\n", octets, octetsUnit); else - nl_dump(p, "%16llu B\n", 0); + nl_dump(p, "%16" PRIu64 " B\n", 0); nl_dump(p, " OutMcastPkts OutMcastOctets " " OutBcastPkts OutBcastOctests\n"); - nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_OUTMCASTPKTS]); + nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTMCASTPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTMCASTOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s ", octets, octetsUnit); else - nl_dump(p, "%16llu B ", 0); + nl_dump(p, "%16" PRIu64 " B ", 0); - nl_dump(p, "%18llu ", link->l_stats[RTNL_LINK_IP6_OUTBCASTPKTS]); + nl_dump(p, "%18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTBCASTPKTS]); octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTBCASTOCTETS], &octetsUnit); if (octets) nl_dump(p, "%14.2f %3s\n", octets, octetsUnit); else - nl_dump(p, "%16llu B\n", 0); + nl_dump(p, "%16" PRIu64 " B\n", 0); nl_dump(p, " ReasmOKs ReasmFails " " ReasmReqds ReasmTimeout\n"); - nl_dump(p, " %18llu %18llu %18llu %18llu\n", + nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_REASMOKS], link->l_stats[RTNL_LINK_IP6_REASMFAILS], link->l_stats[RTNL_LINK_IP6_REASMREQDS], @@ -321,14 +321,14 @@ static void inet6_dump_stats(struct rtnl_link *link, nl_dump(p, " FragOKs FragFails " " FragCreates\n"); - nl_dump(p, " %18llu %18llu %18llu\n", + nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_FRAGOKS], link->l_stats[RTNL_LINK_IP6_FRAGFAILS], link->l_stats[RTNL_LINK_IP6_FRAGCREATES]); nl_dump(p, " InHdrErrors InTooBigErrors " " InNoRoutes InAddrErrors\n"); - nl_dump(p, " %18llu %18llu %18llu %18llu\n", + nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_INHDRERRORS], link->l_stats[RTNL_LINK_IP6_INTOOBIGERRORS], link->l_stats[RTNL_LINK_IP6_INNOROUTES], @@ -336,14 +336,14 @@ static void inet6_dump_stats(struct rtnl_link *link, nl_dump(p, " InUnknownProtos InTruncatedPkts " " OutNoRoutes\n"); - nl_dump(p, " %18llu %18llu %18llu\n", + nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_IP6_INUNKNOWNPROTOS], link->l_stats[RTNL_LINK_IP6_INTRUNCATEDPKTS], link->l_stats[RTNL_LINK_IP6_OUTNOROUTES]); nl_dump(p, " ICMPv6: InMsgs InErrors " " OutMsgs OutErrors\n"); - nl_dump(p, " %18llu %18llu %18llu %18llu\n", + nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n", link->l_stats[RTNL_LINK_ICMP6_INMSGS], link->l_stats[RTNL_LINK_ICMP6_INERRORS], link->l_stats[RTNL_LINK_ICMP6_OUTMSGS], diff --git a/lib/route/neightbl.c b/lib/route/neightbl.c index 9599faa..7725482 100644 --- a/lib/route/neightbl.c +++ b/lib/route/neightbl.c @@ -332,21 +332,32 @@ static void neightbl_dump_stats(struct nl_object *arg, struct nl_dump_params *p) if (!(ntbl->ce_mask & NEIGHTBL_ATTR_STATS)) return; - nl_dump_line(p, " lookups %lld hits %lld failed %lld " \ - "allocations %lld destroys %lld\n", + nl_dump_line(p, " " \ + " lookups %" PRIu64 \ + " hits %" PRIu64 \ + " failed %" PRIu64 \ + " allocations %" PRIu64 \ + " destroys %" PRIu64 \ + "\n", ntbl->nt_stats.ndts_lookups, ntbl->nt_stats.ndts_hits, ntbl->nt_stats.ndts_res_failed, ntbl->nt_stats.ndts_allocs, ntbl->nt_stats.ndts_destroys); - nl_dump_line(p, " hash-grows %lld forced-gc-runs %lld " \ - "periodic-gc-runs %lld\n", + nl_dump_line(p, " " \ + " hash-grows %" PRIu64 \ + " forced-gc-runs %" PRIu64 \ + " periodic-gc-runs %" PRIu64 \ + "\n", ntbl->nt_stats.ndts_hash_grows, ntbl->nt_stats.ndts_forced_gc_runs, ntbl->nt_stats.ndts_periodic_gc_runs); - nl_dump_line(p, " rcv-unicast-probes %lld rcv-multicast-probes %lld\n", + nl_dump_line(p, " " \ + " rcv-unicast-probes %" PRIu64 \ + " rcv-multicast-probes %" PRIu64 \ + "\n", ntbl->nt_stats.ndts_rcv_probes_ucast, ntbl->nt_stats.ndts_rcv_probes_mcast); } diff --git a/src/nl-list-sockets.c b/src/nl-list-sockets.c index 868006e..c2fa1cd 100644 --- a/src/nl-list-sockets.c +++ b/src/nl-list-sockets.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) while (fgets(buf, sizeof(buf), fd)) { unsigned long sk, cb; int ret, proto, pid, rmem, wmem, refcnt; - uint32_t groups; + unsigned int groups; ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n", &sk, &proto, &pid, &groups, &rmem, &wmem, -- cgit v1.2.1