summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>1999-12-19 14:37:49 +0000
committerMartin Baulig <martin@src.gnome.org>1999-12-19 14:37:49 +0000
commit339e1f4557a89739e56ef2e4bf81ad22fcaadd35 (patch)
treec21d0d13f6073653d5ac78cfac9a120064f4659d /sysdeps
parentda42214e866a2e0a36c1f10fd55a598c6b78ffc7 (diff)
downloadlibgtop-339e1f4557a89739e56ef2e4bf81ad22fcaadd35.tar.gz
Removed. (glibtop_get_proc_args_*): This now takes a `glibtop_array'
1999-12-12 Martin Baulig <martin@home-of-linux.org> * include/glibtop/procargs.h (glibtop_proc_args): Removed. (glibtop_get_proc_args_*): This now takes a `glibtop_array' parameter instead of a `glibtop_proc_args one and returns a `char **'.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/kernel/procargs.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/sysdeps/kernel/procargs.c b/sysdeps/kernel/procargs.c
index 3e20edcd..08fc6163 100644
--- a/sysdeps/kernel/procargs.c
+++ b/sysdeps/kernel/procargs.c
@@ -29,7 +29,7 @@
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_proc_args =
-(1L << GLIBTOP_PROC_ARGS_SIZE);
+(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE);
/* Init function. */
@@ -43,44 +43,46 @@ glibtop_init_proc_args_s (glibtop *server)
/* Provides detailed information about a process. */
-char *
-glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
- pid_t pid, unsigned max_len)
+char **
+glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid)
{
- char buffer [BUFSIZ];
- char *retval = NULL, *ptr;
- size_t total;
- int ret;
+ char *ptr = NULL, *pos, **ptrlist;
+ size_t count = 0, max_len, total;
+ int i, ret;
- memset (buf, 0, sizeof (glibtop_proc_args));
+ memset (array, 0, sizeof (glibtop_array));
- if (max_len > BUFSIZ)
- retval = ptr = glibtop_malloc_r (server, max_len+1);
- else
- ptr = buffer;
-
- if (!max_len)
- max_len = BUFSIZ;
+ max_len = PAGE_SIZE;
+ ptr = glibtop_malloc_r (server, max_len + 1);
ret = glibtop_get_proc_data_proc_args_s (server, pid, ptr, max_len);
if (ret < 0) {
- if (!retval) glibtop_free_r (server, retval);
+ glibtop_free_r (server, ptr);
return NULL;
}
total = ret;
+ ptr [total] = '\0';
- if (retval) {
- retval = glibtop_realloc_r (server, retval, total+1);
- } else {
- retval = glibtop_malloc_r (server, total+1);
- memcpy (retval, buffer, total);
+ for (i = 0; i <= total; i++) {
+ if (ptr [i]) continue;
+ count++;
}
- retval [total] = 0;
+ ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *));
+
+ for (i = 0, pos = ptr; i < count; i++) {
+ ptrlist [i] = glibtop_strdup_r (server, pos);
+ pos += strlen (pos) + 1;
+ }
+
+ ptrlist [count] = NULL;
+
+ glibtop_free_r (server, ptr);
- buf->size = total;
- buf->flags = _glibtop_sysdeps_proc_args;
+ array->number = count;
+ array->size = sizeof (char *);
+ array->flags = _glibtop_sysdeps_proc_args;
- return retval;
+ return ptrlist;
}