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

@@ -21,8 +21,10 @@
Boston, MA 02111-1307, USA.
*/
#ifndef __GLIBTOP_SERVER_H__
#define __GLIBTOP_SERVER_H__
#ifndef __LINUX__GLIBTOP_SERVER_H__
#define __LINUX__GLIBTOP_SERVER_H__
#include <glibtop.h>
#include <glib.h>
@@ -36,8 +38,10 @@ G_BEGIN_DECLS
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
unsigned get_pageshift();
static inline char *
skip_token (const char *p)
{
@@ -55,6 +59,7 @@ skip_multiple_token (const char *p, size_t count)
return (char *)p;
}
static inline char *
skip_line (const char *p)
{
@@ -62,12 +67,29 @@ skip_line (const char *p)
return (char *) (*p ? p+1 : p);
}
unsigned long long
get_scaled(const char *buffer, const char *key);
/* aborts on error */
void
file_to_buffer(glibtop *server, char *buffer, const char *filename);
/* return < 0 on error, otherwise 0 on success */
int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid);
try_file_to_buffer(char *buffer, const char *format, ...);
/* some inline functions that wrap proc path
* as fast as macros :)
*/
static inline int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
return try_file_to_buffer(buffer, fmt, pid);
}
static inline int
proc_stat_to_buffer (char *buffer, pid_t pid)
@@ -87,6 +109,7 @@ proc_statm_to_buffer (char *buffer, pid_t pid)
return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
}
static inline char *
proc_stat_after_cmd (char *p)
{
@@ -121,4 +144,4 @@ proc_stat_after_cmd (char *p)
G_END_DECLS
#endif
#endif /* __LINUX__GLIBTOP_SERVER_H__ */