get_process_info() fills the global handle structure and returns a
pointer to it, which is later passed to format_next_process() to print
each process on the screen.

Without casting back and forth between `struct handle *' and `caddr_t'
I find the code is easier to read.

No object change.

OK?


Index: machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.97
diff -u -p -r1.97 machine.c
--- machine.c   28 Jun 2019 13:35:05 -0000      1.97
+++ machine.c   6 Oct 2019 13:22:47 -0000
@@ -422,7 +422,7 @@ cmd_matches(struct kinfo_proc *proc, cha
        return 0;
 }
 
-caddr_t
+struct handle *
 get_process_info(struct system_info *si, struct process_select *sel,
     int (*compare) (const void *, const void *))
 {
@@ -501,7 +501,7 @@ get_process_info(struct system_info *si,
        /* pass back a handle */
        handle.next_proc = pref;
        handle.remaining = active_procs;
-       return ((caddr_t) & handle);
+       return &handle;
 }
 
 char fmt[MAX_COLS];    /* static area where result is built */
@@ -546,20 +546,18 @@ format_comm(struct kinfo_proc *kp)
 }
 
 char *
-format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t, int),
+format_next_process(struct handle *hndl, const char *(*get_userid)(uid_t, int),
     pid_t *pid, int show_threads)
 {
        char *p_wait;
        struct kinfo_proc *pp;
-       struct handle *hp;
        int cputime;
        double pct;
        char buf[16];
 
        /* find and remember the next proc structure */
-       hp = (struct handle *) hndl;
-       pp = *(hp->next_proc++);
-       hp->remaining--;
+       pp = *(hndl->next_proc++);
+       hndl->remaining--;
 
        cputime = pp->p_rtime_sec + ((pp->p_rtime_usec + 500000) / 1000000);
 
Index: machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.25
diff -u -p -r1.25 machine.h
--- machine.h   17 Nov 2018 23:10:08 -0000      1.25
+++ machine.h   6 Oct 2019 13:27:26 -0000
@@ -87,10 +87,11 @@ extern int      display_init(struct stat
 extern int      machine_init(struct statics *);
 extern char    *format_header(char *, int);
 extern void     get_system_info(struct system_info *);
-extern caddr_t
-get_process_info(struct system_info *, struct process_select *,
+extern struct handle
+*get_process_info(struct system_info *, struct process_select *,
                 int (*) (const void *, const void *));
-extern char    *format_next_process(caddr_t, const char *(*)(uid_t, int), 
pid_t *, int);
+extern char    *format_next_process(struct handle *,
+                const char *(*)(uid_t, int), pid_t *, int);
 extern uid_t    proc_owner(pid_t);
 
 extern struct kinfo_proc       *getprocs(int, int, int *);
Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.98
diff -u -p -r1.98 top.c
--- top.c       28 Nov 2018 22:00:30 -0000      1.98
+++ top.c       6 Oct 2019 13:28:04 -0000
@@ -336,7 +336,7 @@ main(int argc, char *argv[])
        int preset_argc = 0, ac = argc, active_procs, i, ncpuonline_now;
        sigset_t mask, oldmask;
        time_t curr_time;
-       caddr_t processes;
+       struct handle *processes;
 
        /* set the buffer for stdout */
 #ifdef DEBUG

Reply via email to