From 24ee2482d3d3d2567ad1509e8bfa3c7509e142f0 Mon Sep 17 00:00:00 2001 From: dwmalone Date: Tue, 9 Mar 2004 11:57:28 +0000 Subject: Fix the easy warnings: 1) Avoid shadowing index. 2) Constness. 3) Missing prototype for ifcmd. 4) Missing include of string.h. 5) Avoid shadowing error function. 6) ANSI definition for main. --- usr.bin/systat/convtbl.c | 18 +++++++++--------- usr.bin/systat/convtbl.h | 4 ++-- usr.bin/systat/extern.h | 1 + usr.bin/systat/ifcmds.c | 3 ++- usr.bin/systat/ifstat.c | 37 ++++++++++++------------------------- usr.bin/systat/main.c | 4 +--- 6 files changed, 27 insertions(+), 40 deletions(-) (limited to 'usr.bin/systat') diff --git a/usr.bin/systat/convtbl.c b/usr.bin/systat/convtbl.c index fe3cd24..833ab30 100644 --- a/usr.bin/systat/convtbl.c +++ b/usr.bin/systat/convtbl.c @@ -55,24 +55,24 @@ get_tbl_ptr(const u_long size, const u_int scale) { struct convtbl *tbl_ptr = NULL; u_long tmp = 0; - u_int index = scale; + u_int idx = scale; /* If our index is out of range, default to auto-scaling. */ - if (index > SC_AUTO) - index = SC_AUTO; + if (idx > SC_AUTO) + idx = SC_AUTO; - if (index == SC_AUTO) + if (idx == SC_AUTO) /* * Simple but elegant algorithm. Count how many times * we can shift our size value right by a factor of ten, * incrementing an index each time. We then use the * index as the array index into the conversion table. */ - for (tmp = size, index = SC_KILOBYTE; - tmp >= MEGA && index <= SC_GIGABYTE; - tmp >>= 10, index++); + for (tmp = size, idx = SC_KILOBYTE; + tmp >= MEGA && idx <= SC_GIGABYTE; + tmp >>= 10, idx++); - tbl_ptr = &convtbl[index]; + tbl_ptr = &convtbl[idx]; return tbl_ptr; } @@ -87,7 +87,7 @@ convert(const u_long size, const u_int scale) } -char * +const char * get_string(const u_long size, const u_int scale) { struct convtbl *tp = NULL; diff --git a/usr.bin/systat/convtbl.h b/usr.bin/systat/convtbl.h index f1ad744..8d5ffee 100644 --- a/usr.bin/systat/convtbl.h +++ b/usr.bin/systat/convtbl.h @@ -55,13 +55,13 @@ struct convtbl { u_int mul; u_int scale; - char *str; + const char *str; }; extern struct convtbl convtbl[]; extern double convert(const u_long, const u_int); -extern char *get_string(const u_long, const u_int); +extern const char *get_string(const u_long, const u_int); #endif /* ! _CONVTBL_H_ */ /* diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index c8dd62b..84af89c 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -108,6 +108,7 @@ void fetchpigs(void); void fetchswap(void); void fetchtcp(void); void getsysctl(const char *, void *, size_t); +int ifcmd(const char *cmd, const char *args); int initicmp(void); int initicmp6(void); int initifstat(void); diff --git a/usr.bin/systat/ifcmds.c b/usr.bin/systat/ifcmds.c index 49f215f..68c377e 100644 --- a/usr.bin/systat/ifcmds.c +++ b/usr.bin/systat/ifcmds.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -55,7 +56,7 @@ static int selectscale(const char *); int ifcmd(const char *cmd, const char *args) { - if (prefix((char *)cmd, (char *)"scale")) { + if (prefix(cmd, "scale")) { if (*args != '\0' && selectscale(args) != -1) ; else { diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c index 2235e25..26c81ce 100644 --- a/usr.bin/systat/ifstat.c +++ b/usr.bin/systat/ifstat.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -56,12 +57,12 @@ #define C4 60 /* 60-80 */ #define C5 80 /* Used for label positioning. */ -static int col0 = 0; -static int col1 = C1; -static int col2 = C2; -static int col3 = C3; -static int col4 = C4; -static int col5 = C5; +static const int col0 = 0; +static const int col1 = C1; +static const int col2 = C2; +static const int col3 = C3; +static const int col4 = C4; +static const int col5 = C5; SLIST_HEAD(, if_stat) curlist; @@ -245,7 +246,6 @@ fetchifstat(void) struct timeval tv, new_tv, old_tv; double elapsed = 0.0; u_int new_inb, new_outb, old_inb, old_outb = 0; - u_int error = 0; u_int we_need_to_sort_interface_list = 0; SLIST_FOREACH(ifp, &curlist, link) { @@ -257,8 +257,7 @@ fetchifstat(void) old_outb = ifp->if_mib.ifmd_data.ifi_obytes; ifp->tv_lastchanged = ifp->if_mib.ifmd_data.ifi_lastchange; - error = gettimeofday(&new_tv, (struct timezone *)0); - if (error) + if (gettimeofday(&new_tv, (struct timezone *)0) != 0) IFSTAT_ERR(2, "error getting time of day"); (void)getifmibdata(ifp->if_row, &ifp->if_mib); @@ -364,7 +363,6 @@ static unsigned int getifnum(void) { - int error = 0; u_int data = 0; size_t datalen = 0; static int name[] = { CTL_NET, @@ -374,13 +372,8 @@ getifnum(void) IFMIB_IFCOUNT }; datalen = sizeof(data); - error = sysctl(name, - 5, - (void *)&data, - (size_t *)&datalen, - (void *)NULL, - (size_t)0); - if (error) + if (sysctl(name, 5, (void *)&data, (size_t *)&datalen, (void *)NULL, + (size_t)0) != 0) IFSTAT_ERR(1, "sysctl error"); return data; } @@ -388,7 +381,6 @@ getifnum(void) static void getifmibdata(int row, struct ifmibdata *data) { - int error = 0; size_t datalen = 0; static int name[] = { CTL_NET, PF_LINK, @@ -399,13 +391,8 @@ getifmibdata(int row, struct ifmibdata *data) datalen = sizeof(*data); name[4] = row; - error = sysctl(name, - 6, - (void *)data, - (size_t *)&datalen, - (void *)NULL, - (size_t)0); - if (error) + if (sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, + (size_t)0) != 0) IFSTAT_ERR(2, "sysctl error getting interface data"); } diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 6826746..833a188 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -82,9 +82,7 @@ int use_kvm = 1; static WINDOW *wload; /* one line window for load average */ int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { char errbuf[_POSIX2_LINE_MAX], dummy; size_t size; -- cgit v1.1