use local vars instead of kargs directly in proc_args

This commit is contained in:
Doug MacEachern 2006-08-25 20:26:12 +00:00
parent 457212edcb
commit 1301c11251
1 changed files with 10 additions and 7 deletions

View File

@ -976,28 +976,31 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_t *procargs) sigar_proc_args_t *procargs)
{ {
#if defined(DARWIN) #if defined(DARWIN)
int status; int status, count;
sigar_kern_proc_args_t kargs; sigar_kern_proc_args_t kargs;
char *ptr, *end;
status = sigar_kern_proc_args_get(pid, &kargs); status = sigar_kern_proc_args_get(pid, &kargs);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;
} }
count = kargs.count;
ptr = kargs.ptr;
end = kargs.end;
sigar_proc_args_create(procargs); sigar_proc_args_create(procargs);
while ((kargs.ptr < kargs.end) && while ((ptr < end) && (count-- > 0)) {
(kargs.count-- > 0)) int alen = strlen(ptr)+1;
{
int alen = strlen(kargs.ptr)+1;
char *arg = malloc(alen); char *arg = malloc(alen);
SIGAR_PROC_ARGS_GROW(procargs); SIGAR_PROC_ARGS_GROW(procargs);
memcpy(arg, kargs.ptr, alen); memcpy(arg, ptr, alen);
procargs->data[procargs->number++] = arg; procargs->data[procargs->number++] = arg;
kargs.ptr += alen; ptr += alen;
} }
return SIGAR_OK; return SIGAR_OK;