diff options
author | Stephen Hemminger <shemming@brocade.com> | 2015-11-29 11:41:23 -0800 |
---|---|---|
committer | Stephen Hemminger <shemming@brocade.com> | 2015-11-29 11:41:23 -0800 |
commit | 68ef50724914e17ef47871e432618d73cce0c6c9 (patch) | |
tree | 0364c992999af6ea1ccde0982d84549aa8880167 | |
parent | 13ada95da4f05df5993ca332358fa3f2f3a21047 (diff) | |
download | android_external_iproute2-68ef50724914e17ef47871e432618d73cce0c6c9.tar.gz android_external_iproute2-68ef50724914e17ef47871e432618d73cce0c6c9.tar.bz2 android_external_iproute2-68ef50724914e17ef47871e432618d73cce0c6c9.zip |
rt_names: style cleanup
Cleanup all checkpatch complaints about whitespace in rt_names.
-rw-r--r-- | lib/rt_names.c | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/lib/rt_names.c b/lib/rt_names.c index f68e91d..1071a93 100644 --- a/lib/rt_names.c +++ b/lib/rt_names.c @@ -31,8 +31,8 @@ #define NAME_MAX_LEN 512 struct rtnl_hash_entry { - struct rtnl_hash_entry *next; - const char * name; + struct rtnl_hash_entry *next; + const char *name; unsigned int id; }; @@ -82,7 +82,7 @@ rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size) return; } - if (id<0) + if (id < 0) continue; entry = malloc(sizeof(*entry)); @@ -112,7 +112,7 @@ static void rtnl_tab_initialize(const char *file, char **tab, int size) fclose(fp); return; } - if (id<0 || id>size) + if (id < 0 || id > size) continue; tab[id] = strdup(namebuf); @@ -120,23 +120,23 @@ static void rtnl_tab_initialize(const char *file, char **tab, int size) fclose(fp); } -static char * rtnl_rtprot_tab[256] = { - [RTPROT_UNSPEC] = "none", - [RTPROT_REDIRECT] ="redirect", - [RTPROT_KERNEL] = "kernel", - [RTPROT_BOOT] = "boot", - [RTPROT_STATIC] = "static", - - [RTPROT_GATED] = "gated", - [RTPROT_RA] = "ra", - [RTPROT_MRT] = "mrt", - [RTPROT_ZEBRA] ="zebra", - [RTPROT_BIRD] = "bird", - [RTPROT_BABEL] = "babel", +static char *rtnl_rtprot_tab[256] = { + [RTPROT_UNSPEC] = "none", + [RTPROT_REDIRECT] = "redirect", + [RTPROT_KERNEL] = "kernel", + [RTPROT_BOOT] = "boot", + [RTPROT_STATIC] = "static", + + [RTPROT_GATED] = "gated", + [RTPROT_RA] = "ra", + [RTPROT_MRT] = "mrt", + [RTPROT_ZEBRA] = "zebra", + [RTPROT_BIRD] = "bird", + [RTPROT_BABEL] = "babel", [RTPROT_DNROUTED] = "dnrouted", - [RTPROT_XORP] = "xorp", - [RTPROT_NTK] = "ntk", - [RTPROT_DHCP] = "dhcp", + [RTPROT_XORP] = "xorp", + [RTPROT_NTK] = "ntk", + [RTPROT_DHCP] = "dhcp", }; @@ -149,9 +149,9 @@ static void rtnl_rtprot_initialize(void) rtnl_rtprot_tab, 256); } -const char * rtnl_rtprot_n2a(int id, char *buf, int len) +const char *rtnl_rtprot_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id < 0 || id >= 256) { snprintf(buf, len, "%u", id); return buf; } @@ -167,7 +167,7 @@ const char * rtnl_rtprot_n2a(int id, char *buf, int len) int rtnl_rtprot_a2n(__u32 *id, const char *arg) { - static char *cache = NULL; + static char *cache; static unsigned long res; char *end; int i; @@ -180,7 +180,7 @@ int rtnl_rtprot_a2n(__u32 *id, const char *arg) if (!rtnl_rtprot_init) rtnl_rtprot_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { if (rtnl_rtprot_tab[i] && strcmp(rtnl_rtprot_tab[i], arg) == 0) { cache = rtnl_rtprot_tab[i]; @@ -197,8 +197,13 @@ int rtnl_rtprot_a2n(__u32 *id, const char *arg) return 0; } -static char * rtnl_rtscope_tab[256] = { - "global", + +static char *rtnl_rtscope_tab[256] = { + [RT_SCOPE_UNIVERSE] = "global", + [RT_SCOPE_NOWHERE] = "nowhere", + [RT_SCOPE_HOST] = "host", + [RT_SCOPE_LINK] = "link", + [RT_SCOPE_SITE] = "site", }; static int rtnl_rtscope_init; @@ -206,33 +211,32 @@ static int rtnl_rtscope_init; static void rtnl_rtscope_initialize(void) { rtnl_rtscope_init = 1; - rtnl_rtscope_tab[RT_SCOPE_NOWHERE] = "nowhere"; - rtnl_rtscope_tab[RT_SCOPE_HOST] = "host"; - rtnl_rtscope_tab[RT_SCOPE_LINK] = "link"; - rtnl_rtscope_tab[RT_SCOPE_SITE] = "site"; rtnl_tab_initialize(CONFDIR "/rt_scopes", rtnl_rtscope_tab, 256); } const char *rtnl_rtscope_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } + if (!rtnl_rtscope_tab[id]) { if (!rtnl_rtscope_init) rtnl_rtscope_initialize(); } + if (rtnl_rtscope_tab[id]) return rtnl_rtscope_tab[id]; + snprintf(buf, len, "%d", id); return buf; } int rtnl_rtscope_a2n(__u32 *id, const char *arg) { - static const char *cache = NULL; + static const char *cache; static unsigned long res; char *end; int i; @@ -245,7 +249,7 @@ int rtnl_rtscope_a2n(__u32 *id, const char *arg) if (!rtnl_rtscope_init) rtnl_rtscope_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { if (rtnl_rtscope_tab[i] && strcmp(rtnl_rtscope_tab[i], arg) == 0) { cache = rtnl_rtscope_tab[i]; @@ -263,7 +267,7 @@ int rtnl_rtscope_a2n(__u32 *id, const char *arg) } -static char * rtnl_rtrealm_tab[256] = { +static char *rtnl_rtrealm_tab[256] = { "unknown", }; @@ -278,7 +282,7 @@ static void rtnl_rtrealm_initialize(void) const char *rtnl_rtrealm_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } @@ -295,7 +299,7 @@ const char *rtnl_rtrealm_n2a(int id, char *buf, int len) int rtnl_rtrealm_a2n(__u32 *id, const char *arg) { - static char *cache = NULL; + static char *cache; static unsigned long res; char *end; int i; @@ -308,7 +312,7 @@ int rtnl_rtrealm_a2n(__u32 *id, const char *arg) if (!rtnl_rtrealm_init) rtnl_rtrealm_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { if (rtnl_rtrealm_tab[i] && strcmp(rtnl_rtrealm_tab[i], arg) == 0) { cache = rtnl_rtrealm_tab[i]; @@ -330,7 +334,7 @@ static struct rtnl_hash_entry dflt_table_entry = { .name = "default" }; static struct rtnl_hash_entry main_table_entry = { .name = "main" }; static struct rtnl_hash_entry local_table_entry = { .name = "local" }; -static struct rtnl_hash_entry * rtnl_rttable_hash[256] = { +static struct rtnl_hash_entry *rtnl_rttable_hash[256] = { [RT_TABLE_DEFAULT] = &dflt_table_entry, [RT_TABLE_MAIN] = &main_table_entry, [RT_TABLE_LOCAL] = &local_table_entry, @@ -370,13 +374,14 @@ static void rtnl_rttable_initialize(void) if (strcmp(de->d_name + len - 5, ".conf")) continue; - snprintf(path, sizeof(path), CONFDIR "/rt_tables.d/%s", de->d_name); + snprintf(path, sizeof(path), + CONFDIR "/rt_tables.d/%s", de->d_name); rtnl_hash_initialize(path, rtnl_rttable_hash, 256); } closedir(d); } -const char * rtnl_rttable_n2a(__u32 id, char *buf, int len) +const char *rtnl_rttable_n2a(__u32 id, char *buf, int len) { struct rtnl_hash_entry *entry; @@ -397,7 +402,7 @@ const char * rtnl_rttable_n2a(__u32 id, char *buf, int len) int rtnl_rttable_a2n(__u32 *id, const char *arg) { - static const char *cache = NULL; + static const char *cache; static unsigned long res; struct rtnl_hash_entry *entry; char *end; @@ -411,7 +416,7 @@ int rtnl_rttable_a2n(__u32 *id, const char *arg) if (!rtnl_rttable_init) rtnl_rttable_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { entry = rtnl_rttable_hash[i]; while (entry && strcmp(entry->name, arg)) entry = entry->next; @@ -431,7 +436,7 @@ int rtnl_rttable_a2n(__u32 *id, const char *arg) } -static char * rtnl_rtdsfield_tab[256] = { +static char *rtnl_rtdsfield_tab[256] = { "0", }; @@ -446,7 +451,7 @@ static void rtnl_rtdsfield_initialize(void) const char *rtnl_dsfield_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } @@ -463,7 +468,7 @@ const char *rtnl_dsfield_n2a(int id, char *buf, int len) int rtnl_dsfield_a2n(__u32 *id, const char *arg) { - static char *cache = NULL; + static char *cache; static unsigned long res; char *end; int i; @@ -476,7 +481,7 @@ int rtnl_dsfield_a2n(__u32 *id, const char *arg) if (!rtnl_rtdsfield_init) rtnl_rtdsfield_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { if (rtnl_rtdsfield_tab[i] && strcmp(rtnl_rtdsfield_tab[i], arg) == 0) { cache = rtnl_rtdsfield_tab[i]; @@ -494,9 +499,11 @@ int rtnl_dsfield_a2n(__u32 *id, const char *arg) } -static struct rtnl_hash_entry dflt_group_entry = { .id = 0, .name = "default" }; +static struct rtnl_hash_entry dflt_group_entry = { + .id = 0, .name = "default" +}; -static struct rtnl_hash_entry * rtnl_group_hash[256] = { +static struct rtnl_hash_entry *rtnl_group_hash[256] = { [0] = &dflt_group_entry, }; @@ -511,7 +518,7 @@ static void rtnl_group_initialize(void) int rtnl_group_a2n(int *id, const char *arg) { - static const char *cache = NULL; + static const char *cache; static unsigned long res; struct rtnl_hash_entry *entry; char *end; @@ -525,7 +532,7 @@ int rtnl_group_a2n(int *id, const char *arg) if (!rtnl_group_init) rtnl_group_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { entry = rtnl_group_hash[i]; while (entry && strcmp(entry->name, arg)) entry = entry->next; @@ -552,11 +559,10 @@ const char *rtnl_group_n2a(int id, char *buf, int len) if (!rtnl_group_init) rtnl_group_initialize(); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { entry = rtnl_group_hash[i]; - if (entry && entry->id == id) { + if (entry && entry->id == id) return entry->name; - } } snprintf(buf, len, "%d", id); @@ -615,7 +621,7 @@ const char *nl_proto_n2a(int id, char *buf, int len) int nl_proto_a2n(__u32 *id, const char *arg) { - static char *cache = NULL; + static char *cache; static unsigned long res; char *end; int i; |