From bdf2bc7eb0039f992b46fe141c5e6f7c4baa1ba4 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Thu, 27 Jun 1996 22:14:19 +0000 Subject: (proc_stat_list_clone): New function. --- libps/proclist.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'libps') diff --git a/libps/proclist.c b/libps/proclist.c index 3e44eeac..2dfcfe7d 100644 --- a/libps/proclist.c +++ b/libps/proclist.c @@ -22,12 +22,11 @@ #include #include #include +#include #include "ps.h" #include "common.h" -/* ---------------------------------------------------------------- */ - /* Creates a new proc_stat_list_t for processes from CONTEXT, which is returned in PP, and returns 0, or else returns ENOMEM if there wasn't enough memory. */ @@ -54,9 +53,34 @@ proc_stat_list_free (struct proc_stat_list *pp) FREE (pp->proc_stats); FREE (pp); } - -/* ---------------------------------------------------------------- */ +/* Returns a copy of PP in COPY, or an error. */ +error_t +proc_stat_list_clone (struct proc_stat_list *pp, struct proc_stat_list **copy) +{ + struct proc_stat_list *new = NEW (struct proc_stat_list); + struct proc_stat **procs = NEWVEC (struct proc_stat *, pp->num_procs); + + if (!new || !procs) + { + if (new) + free (new); + if (procs) + free (procs); + return ENOMEM; + } + + bcopy (pp->proc_stats, procs, pp->num_procs); + + new->proc_stats = procs; + new->num_procs = pp->num_procs; + new->alloced = pp->num_procs; + new->context = pp->context; + *copy = new; + + return 0; +} + /* Make sure there are at least AMOUNT new locations allocated in PP's proc_stat array (but without changing NUM_PROCS). Returns ENOMEM if a memory allocation error occurred, 0 otherwise. */ -- cgit v1.2.3