]> granicus.if.org Git - libnl/commitdiff
"%llu" replaced with "%" PRIu64
authorКоренберг Марк (дома) <socketpair@gmail.com>
Wed, 29 Aug 2012 17:59:17 +0000 (23:59 +0600)
committerКоренберг Марк (дома) <socketpair@gmail.com>
Wed, 29 Aug 2012 21:19:04 +0000 (03:19 +0600)
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
lib/route/cls/u32.c
lib/route/link.c
lib/route/link/inet6.c
lib/route/neightbl.c
src/nl-list-sockets.c

index 70a814f58976c68d6ae2b90b5464fb70500ba448..f57b15e1777c699fcf82c31d52249c03fca62d3a 100644 (file)
@@ -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);
        }
 }
 
index d3e326dcd84aa2b3a68caf3ea35bb3700f685ed6..aa9eb77d04183cd9750216d9b497b801b8249102 100644 (file)
@@ -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);
        }
 }
index aea43b9852ec9eebbc6d0d2921dda1bfdcd0f598..0e8ac07c523160344fde8c71f6b5e0af0909dc58 100644 (file)
@@ -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,
index 5f7534250104f1c74dd971929183f1d051755227..9ee82261df80b05533f969365e26ada191298f52 100644 (file)
@@ -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],
index 9599faaed36e64d3b96f29af1f7453c8e49cb3c9..7725482302d9f95ca5d23ef3b6d841a7cc3c749c 100644 (file)
@@ -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);
 }
index 868006eba7e05df11f03538c03329a6e69549c9d..c2fa1cdba21b84efb0a14b5e672e3d0b406f435d 100644 (file)
@@ -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,