diff options
author | norly <ny-git@enpas.org> | 2013-02-15 00:10:58 +0000 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-02-15 00:10:58 +0000 |
commit | 2ddbfa53a31360e50565345a1ac08c0799c8243e (patch) | |
tree | 4425fb570559d1425f29c86effc66706b2ce1e91 /statuses/netif.c | |
parent | 9102c7c65421f2ef3e415c7e76a741657e34663b (diff) |
Reindent and restyle
Diffstat (limited to 'statuses/netif.c')
-rw-r--r-- | statuses/netif.c | 131 |
1 files changed, 64 insertions, 67 deletions
diff --git a/statuses/netif.c b/statuses/netif.c index d5cc803..581d279 100644 --- a/statuses/netif.c +++ b/statuses/netif.c @@ -7,76 +7,73 @@ #include "../config.h" #ifndef NETIF_BASEDIR - #define NETIF_BASEDIR "/sys/class/net/" + #define NETIF_BASEDIR "/sys/class/net/" #endif void status_netif(char *ifname) { - char ifpath[256]; - int ifpathlen; - - char stline[16]; - ssize_t stlen; - - double ifsum = 0.0; - int ifsumpower; - - - // Prepare path - ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname); - if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) - { - statusError("status_netif", - "ifpath buffer too small", - ifname); - return; - } - strcpy(ifpath, NETIF_BASEDIR); - strcat(ifpath, ifname); - - - // Is the interface up? - if (access(ifpath, F_OK)) - { - //printf(" ^fg(grey)[%s] ", ifname); - return; - } - - - strcpy(&ifpath[ifpathlen], "/carrier"); - stlen = fileRead(stline, sizeof(stline), ifpath); - if (stlen > 0) - { - if (stline[0] == '1') - { - fputs("^fg(yellow)", stdout); - } - else - { - //fputs("^fg(red)", stdout); - return; - } - } else { - return; - } - - strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes"); - stlen = fileRead(stline, sizeof(stline), ifpath); - if (stlen > 0) - ifsum = atof(stline); - - strcpy(&ifpath[ifpathlen], "/statistics/tx_bytes"); - stlen = fileRead(stline, sizeof(stline), ifpath); - if (stlen > 0) - ifsum += atof(stline); - - - for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++) - ifsum = ifsum / 1024; - - printf(" %s: %.*f %c ", ifname, - ifsumpower ? ifsumpower - 1 : ifsumpower, - ifsum, - powerToChar(ifsumpower)); + char ifpath[256]; + int ifpathlen; + + char stline[16]; + ssize_t stlen; + + double ifsum = 0.0; + int ifsumpower; + + + /* Prepare path */ + ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname); + if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) { + statusError("status_netif", + "ifpath buffer too small", + ifname); + return; + } + strcpy(ifpath, NETIF_BASEDIR); + strcat(ifpath, ifname); + + + /* Is the interface up? */ + if (access(ifpath, F_OK)) { + //printf(" ^fg(grey)[%s] ", ifname); + return; + } + + + strcpy(&ifpath[ifpathlen], "/carrier"); + stlen = fileRead(stline, sizeof(stline), ifpath); + if (stlen > 0) { + if (stline[0] == '1') { + fputs("^fg(yellow)", stdout); + } else { + //fputs("^fg(red)", stdout); + return; + } + } else { + return; + } + + strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes"); + stlen = fileRead(stline, sizeof(stline), ifpath); + if (stlen > 0) { + ifsum = atof(stline); + } + + strcpy(&ifpath[ifpathlen], "/statistics/tx_bytes"); + stlen = fileRead(stline, sizeof(stline), ifpath); + if (stlen > 0) { + ifsum += atof(stline); + } + + + for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++) { + ifsum = ifsum / 1024; + } + + printf(" %s: %.*f %c ", ifname, + ifsumpower ? ifsumpower - 1 : ifsumpower, + ifsum, + powerToChar(ifsumpower)); } |