libiproute: style fixes, and using smallint as appropriate
authorDenis Vlasenko <vda.linux@googlemail.com>
Sat, 31 May 2008 07:33:18 +0000 (07:33 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sat, 31 May 2008 07:33:18 +0000 (07:33 -0000)
function                                             old     new   delta
print_route                                         1730    1731      +1
print_addrinfo                                      1497    1498      +1
iproute_list_or_flush                               1232    1229      -3
ipaddr_list_or_flush                                2490    2484      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 2/-9)               Total: -7 bytes

networking/libiproute/ipaddress.c
networking/libiproute/iproute.c
networking/libiproute/utils.h

index 044538a..b3cbe38 100644 (file)
@@ -10,8 +10,6 @@
  *     Laszlo Valko <valko@linux.karinthy.hu> 990223: address label must be zero terminated
  */
 
-//#include <sys/socket.h>
-//#include <sys/ioctl.h>
 #include <fnmatch.h>
 #include <net/if.h>
 #include <net/if_arp.h>
 
 
 typedef struct filter_t {
-       int ifindex;
-       int family;
-       int oneline;
-       int showqueue;
-       inet_prefix pfx;
-       int scope, scopemask;
-       int flags, flagmask;
-       int up;
        char *label;
-       int flushed;
        char *flushb;
+       struct rtnl_handle *rth;
+       int scope, scopemask;
+       int flags, flagmask;
        int flushp;
        int flushe;
-       struct rtnl_handle *rth;
+       int ifindex;
+       family_t family;
+       smallint showqueue;
+       smallint oneline;
+       smallint up;
+       smallint flushed;
+       inet_prefix pfx;
 } filter_t;
 
 #define filter (*(filter_t*)&bb_common_bufsiz1)
@@ -45,7 +43,7 @@ static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown)
 {
        fprintf(fp, "<");
        flags &= ~IFF_RUNNING;
-#define _PF(f) if (flags&IFF_##f) { \
+#define _PF(f) if (flags & IFF_##f) { \
                  flags &= ~IFF_##f; \
                  fprintf(fp, #f "%s", flags ? "," : ""); }
        _PF(LOOPBACK);
@@ -112,7 +110,7 @@ static int print_linkinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
 
        if (filter.ifindex && ifi->ifi_index != filter.ifindex)
                return 0;
-       if (filter.up && !(ifi->ifi_flags&IFF_UP))
+       if (filter.up && !(ifi->ifi_flags & IFF_UP))
                return 0;
 
        memset(tb, 0, sizeof(tb));
@@ -229,9 +227,9 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
 
        if (filter.ifindex && filter.ifindex != ifa->ifa_index)
                return 0;
-       if ((filter.scope^ifa->ifa_scope)&filter.scopemask)
+       if ((filter.scope ^ ifa->ifa_scope) & filter.scopemask)
                return 0;
-       if ((filter.flags^ifa->ifa_flags)&filter.flagmask)
+       if ((filter.flags ^ ifa->ifa_flags) & filter.flagmask)
                return 0;
        if (filter.label) {
                const char *label;
@@ -265,7 +263,7 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
                fn->nlmsg_flags = NLM_F_REQUEST;
                fn->nlmsg_seq = ++filter.rth->seq;
                filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
-               filter.flushed++;
+               filter.flushed = 1;
                return 0;
        }
 
@@ -315,19 +313,19 @@ static int print_addrinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
                                    abuf, sizeof(abuf)));
        }
        fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
-       if (ifa->ifa_flags&IFA_F_SECONDARY) {
+       if (ifa->ifa_flags & IFA_F_SECONDARY) {
                ifa->ifa_flags &= ~IFA_F_SECONDARY;
                fprintf(fp, "secondary ");
        }
-       if (ifa->ifa_flags&IFA_F_TENTATIVE) {
+       if (ifa->ifa_flags & IFA_F_TENTATIVE) {
                ifa->ifa_flags &= ~IFA_F_TENTATIVE;
                fprintf(fp, "tentative ");
        }
-       if (ifa->ifa_flags&IFA_F_DEPRECATED) {
+       if (ifa->ifa_flags & IFA_F_DEPRECATED) {
                ifa->ifa_flags &= ~IFA_F_DEPRECATED;
                fprintf(fp, "deprecated ");
        }
-       if (!(ifa->ifa_flags&IFA_F_PERMANENT)) {
+       if (!(ifa->ifa_flags & IFA_F_PERMANENT)) {
                fprintf(fp, "dynamic ");
        } else
                ifa->ifa_flags &= ~IFA_F_PERMANENT;
@@ -396,7 +394,8 @@ static int store_nlmsg(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        memcpy(&h->h, n, n->nlmsg_len);
        h->next = NULL;
 
-       for (lp = linfo; *lp; lp = &(*lp)->next) /* NOTHING */;
+       for (lp = linfo; *lp; lp = &(*lp)->next)
+               continue;
        *lp = h;
 
        ll_remember_index(who, n, NULL);
index 670f188..1f64794 100644 (file)
@@ -24,7 +24,7 @@
 
 typedef struct filter_t {
        int tb;
-       int flushed;
+       smallint flushed;
        char *flushb;
        int flushp;
        int flushe;
@@ -189,7 +189,7 @@ static int print_route(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
                fn->nlmsg_flags = NLM_F_REQUEST;
                fn->nlmsg_seq = ++filter.rth->seq;
                filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
-               filter.flushed++;
+               filter.flushed = 1;
                return 0;
        }
 
index b67619d..06b1f04 100644 (file)
@@ -32,8 +32,7 @@ extern void incomplete_command(void) ATTRIBUTE_NORETURN;
 
 #define NEXT_ARG() do { if (!*++argv) incomplete_command(); } while (0)
 
-typedef struct
-{
+typedef struct {
        uint8_t family;
        uint8_t bytelen;
        int16_t bitlen;