From d2a857bf67b221b3b40293f5fdb918fb5bb77494 Mon Sep 17 00:00:00 2001 From: eadler Date: Mon, 21 May 2018 03:36:16 +0000 Subject: [PATCH] top(1): fix several more warnings --- usr.bin/top/commands.c | 4 ++-- usr.bin/top/display.c | 30 +++++++++--------------------- usr.bin/top/machine.c | 29 +++++++++++++++-------------- usr.bin/top/screen.c | 3 --- usr.bin/top/top.c | 38 +++++++++++++++++--------------------- usr.bin/top/top.h | 2 ++ usr.bin/top/utils.c | 7 +++---- 7 files changed, 48 insertions(+), 65 deletions(-) diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index 419591e96db5..56caa51c8bc5 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -326,8 +326,8 @@ static int err_compar(const void *p1, const void *p2) { int result; - struct errs * g1 = (struct errs *)p1; - struct errs * g2 = (struct errs *)p2; + const struct errs * const g1 = (const struct errs * const)p1; + const struct errs * const g2 = (const struct errs * const)p2; diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index f293f4676dce..a8bc9037eacf 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -66,7 +66,7 @@ static int display_width = MAX_COLS; /* things initialized by display_init and used thruout */ /* buffer of proc information lines for display updating */ -char *screenbuf = NULL; +static char *screenbuf = NULL; static char **procstate_names; static char **cpustate_names; @@ -656,13 +656,10 @@ int *stats; * Assumptions: cursor is on "lastline" * for i_arc ONLY: cursor is on the previous line */ -char arc_buffer[MAX_COLS]; +static char arc_buffer[MAX_COLS]; void -i_arc(stats) - -int *stats; - +i_arc(int *stats) { if (arc_names == NULL) return; @@ -698,13 +695,10 @@ int *stats; * Assumptions: cursor is on "lastline" * for i_carc ONLY: cursor is on the previous line */ -char carc_buffer[MAX_COLS]; +static char carc_buffer[MAX_COLS]; void -i_carc(stats) - -int *stats; - +i_carc(int *stats) { if (carc_names == NULL) return; @@ -740,13 +734,10 @@ int *stats; * for i_swap ONLY: cursor is on the previous line */ -char swap_buffer[MAX_COLS]; +static char swap_buffer[MAX_COLS]; void -i_swap(stats) - -int *stats; - +i_swap(int *stats) { fputs("\nSwap: ", stdout); lastline++; @@ -757,10 +748,7 @@ int *stats; } void -u_swap(stats) - -int *stats; - +u_swap(int *stats) { static char new[MAX_COLS]; @@ -790,8 +778,8 @@ static int msglen = 0; void i_message() - { + while (lastline < y_message) { fputc('\n', stdout); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 7de9e3e4e5c8..ddfd86a29c95 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -124,7 +124,7 @@ static char up_header[] = /* the extra nulls in the string "run" are for adding a slash and the processor number when needed */ -char *state_abbrev[] = { +static char *state_abbrev[] = { "", "START", "RUN\0\0\0", "SLEEP", "STOP", "ZOMB", "WAIT", "LOCK" }; @@ -151,8 +151,8 @@ static long cp_diff[CPUSTATES]; /* these are for detailing the process states */ -int process_states[8]; -char *procstatenames[] = { +static int process_states[8]; +static char *procstatenames[] = { "", " starting, ", " running, ", " sleeping, ", " stopped, ", " zombie, ", " waiting, ", " lock, ", NULL @@ -160,33 +160,33 @@ char *procstatenames[] = { /* these are for detailing the cpu states */ -int cpu_states[CPUSTATES]; -char *cpustatenames[] = { +static int cpu_states[CPUSTATES]; +static char *cpustatenames[] = { "user", "nice", "system", "interrupt", "idle", NULL }; /* these are for detailing the memory statistics */ -int memory_stats[7]; -char *memorynames[] = { +static int memory_stats[7]; +static char *memorynames[] = { "K Active, ", "K Inact, ", "K Laundry, ", "K Wired, ", "K Buf, ", "K Free", NULL }; -int arc_stats[7]; -char *arcnames[] = { +static int arc_stats[7]; +static char *arcnames[] = { "K Total, ", "K MFU, ", "K MRU, ", "K Anon, ", "K Header, ", "K Other", NULL }; -int carc_stats[4]; -char *carcnames[] = { +static int carc_stats[4]; +static char *carcnames[] = { "K Compressed, ", "K Uncompressed, ", ":1 Ratio, ", NULL }; -int swap_stats[7]; -char *swapnames[] = { +static int swap_stats[7]; +static char *swapnames[] = { "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out", NULL }; @@ -933,7 +933,8 @@ format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags) size_t state; struct rusage ru, *rup; long p_tot, s_tot; - char *proc_fmt, thr_buf[6]; + char *proc_fmt; + char thr_buf[6]; char jid_buf[TOP_JID_LEN + 1], swap_buf[TOP_SWAP_LEN + 1]; char *cmdbuf = NULL; char **args; diff --git a/usr.bin/top/screen.c b/usr.bin/top/screen.c index c1ef7da890a4..4f05bda7f96d 100644 --- a/usr.bin/top/screen.c +++ b/usr.bin/top/screen.c @@ -32,9 +32,6 @@ #include "screen.h" #include "boolean.h" -extern char *myname; - - int overstrike; int screen_length; int screen_width; diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 3f684e2bc1df..4ce7edad6716 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,6 +1,3 @@ -char *copyright = - "Copyright (c) 1984 through 1996, William LeFebvre"; - /* * Top users/processes display for Unix * @@ -43,10 +40,13 @@ char *copyright = /* Size of the stdio buffer given to stdout */ #define Buffersize 2048 +char *copyright = + "Copyright (c) 1984 through 1996, William LeFebvre"; + typedef void sigret_t; /* The buffer that stdio will use */ -char stdoutbuf[Buffersize]; +static char stdoutbuf[Buffersize]; /* build Signal masks */ #define Smask(s) (1 << ((s) - 1)) @@ -69,34 +69,30 @@ static int max_topn; /* maximum displayable processes */ /* miscellaneous things */ struct process_select ps; -char *myname = "top"; -jmp_buf jmp_int; +const char * myname = "top"; char *username(int); time_t time(time_t *tloc); -caddr_t get_process_info(struct system_info *si, struct process_select *sel, - int (*compare)(const void *, const void *)); - /* different routines for displaying the user's identification */ /* (values assigned to get_userid) */ char *username(int); char *itoa7(int); /* pointers to display routines */ -void (*d_loadave)(int mpid, double *avenrun) = i_loadave; -void (*d_procstates)(int total, int *brkdn) = i_procstates; -void (*d_cpustates)(int *states) = i_cpustates; -void (*d_memory)(int *stats) = i_memory; -void (*d_arc)(int *stats) = i_arc; -void (*d_carc)(int *stats) = i_carc; -void (*d_swap)(int *stats) = i_swap; -void (*d_message)(void) = i_message; -void (*d_header)(char *text) = i_header; -void (*d_process)(int line, char *thisline) = i_process; +static void (*d_loadave)(int mpid, double *avenrun) = i_loadave; +static void (*d_procstates)(int total, int *brkdn) = i_procstates; +static void (*d_cpustates)(int *states) = i_cpustates; +static void (*d_memory)(int *stats) = i_memory; +static void (*d_arc)(int *stats) = i_arc; +static void (*d_carc)(int *stats) = i_carc; +static void (*d_swap)(int *stats) = i_swap; +static void (*d_message)(void) = i_message; +static void (*d_header)(char *text) = i_header; +static void (*d_process)(int line, char *thisline) = i_process; -void reset_display(void); +static void reset_display(void); static void reset_uids() @@ -1177,7 +1173,7 @@ char *argv[]; * screen will get redrawn. */ -void +static void reset_display() { diff --git a/usr.bin/top/top.h b/usr.bin/top/top.h index fb57177fc4d9..62be7e495fc6 100644 --- a/usr.bin/top/top.h +++ b/usr.bin/top/top.h @@ -46,6 +46,8 @@ extern enum displaymodes displaymode; extern int pcpu_stats; extern int overstrike; +extern const char * myname; + extern int (*compares[])(const void*, const void*); char* kill_procs(char *); diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c index afb4de849f86..bbd4892cf878 100644 --- a/usr.bin/top/utils.c +++ b/usr.bin/top/utils.c @@ -16,6 +16,7 @@ */ #include "top.h" +#include "utils.h" #include #include @@ -428,10 +429,8 @@ int amt; return(ret); } -char *format_k2(amt) - -unsigned long long amt; - +char * +format_k2(unsigned long long amt) { static char retarray[NUM_STRINGS][16]; static int index = 0;