Make the return value a char *' instead of a const char *'.

1998-12-09  Martin Baulig  <martin@home-of-linux.org>

	* include/glibtop/procargs.h (glibtop_get_proc_args): Make the
	return value a `char *' instead of a `const char *'.
This commit is contained in:
Martin Baulig
1998-12-09 11:38:49 +00:00
committed by Martin Baulig
parent ee9812e9af
commit 1520ee7083
10 changed files with 90 additions and 12 deletions

View File

@@ -24,7 +24,8 @@
#include <glibtop/xmalloc.h>
#include <glibtop/procargs.h>
static const unsigned long _glibtop_sysdeps_proc_args = 0;
static const unsigned long _glibtop_sysdeps_proc_args =
(1 << GLIBTOP_PROC_ARGS_SIZE);
/* Init function. */
@@ -36,10 +37,55 @@ glibtop_init_proc_args_s (glibtop *server)
/* Provides detailed information about a process. */
const char *
char *
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
char fn [BUFSIZ], buffer [BUFSIZ];
int cmdline, len, total = 0;
char *retval = NULL;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
memset (buf, 0, sizeof (glibtop_proc_args));
return NULL;
sprintf (fn, "/proc/%d/cmdline", pid);
cmdline = open (fn, O_RDONLY);
if (cmdline < 0) return NULL;
if (max_len) {
retval = glibtop_malloc_r (server, max_len+1);
len = read (cmdline, retval, max_len);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
return retval;
}
while (1) {
len = read (cmdline, buffer, BUFSIZ-1);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
if (len == 0)
break;
retval = glibtop_realloc_r (server, retval, total+len+1);
memcpy (retval+total, buffer, len);
*(retval+total+len) = 0;
total += len;
}
close (cmdline);
buf->size = total;
buf->flags = _glibtop_sysdeps_proc_args;
return retval;
}