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

@@ -66,23 +66,12 @@ glibtop_open_s (glibtop *server, const char *program_name,
const unsigned flags)
{
char buffer [BUFSIZ], *p = buffer;
int fd, len;
server->name = program_name;
server->os_version_code = get_linux_version();
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);
for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) {