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

@@ -36,8 +36,6 @@ static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
int fd;
ssize_t len;
char buffer [BUFSIZ];
if(G_LIKELY(sysinfo.flags)) return;
@@ -46,21 +44,7 @@ init_sysinfo (glibtop *server)
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
/* load the file */
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
file_to_buffer(server, buffer, FILENAME);
/* cpuinfo records are seperated by a blank line */
gchar ** const processors = g_strsplit(buffer, "\n\n", 0);
@@ -97,8 +81,7 @@ init_sysinfo (glibtop *server)
/* the last key has no value and has not been added */
if(*p)
g_free(*p);
if(*p) g_free(*p);
/* just g_free instead of g_strvfree because we stole
the memory*/