Added. These functions are commonly used. Misc cleanups.

* glibtop_server.h:
	* glibtop_server.c: (try_file_to_buffer), (file_to_buffer): Added. These
	functions are commonly used. Misc cleanups.

	* cpu.c: (glibtop_get_cpu_s):
	* loadavg.c: (glibtop_get_loadavg_s):
	* mem.c: (glibtop_get_mem_s):
	* open.c: (glibtop_open_s):
	* swap.c: (glibtop_get_swap_s):
	* sysinfo.c: (init_sysinfo):
	* uptime.c: (glibtop_get_uptime_s): Replaced open/read/close by file_to_buffer().
This commit is contained in:
Benoît Dejean
2004-07-03 13:28:59 +00:00
parent 8eae848c3f
commit 50f086cb68
10 changed files with 92 additions and 118 deletions

View File

@@ -52,23 +52,12 @@ void
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
fd = open (MEMINFO, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", MEMINFO);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", MEMINFO);
close (fd);
buffer [len] = '\0';
file_to_buffer(server, buffer, MEMINFO);
/* Kernel 2.6 with multiple lines */
@@ -78,17 +67,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buf->flags = _glibtop_sysdeps_swap;
fd = open (PROC_STAT, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", PROC_STAT);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", PROC_STAT);
close (fd);
buffer [len] = '\0';
file_to_buffer(server, buffer, PROC_STAT);
p = strstr (buffer, "\nswap");
if (p == NULL) return;