From 50f086cb684355a25f22a92c4cee76365ac4945f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Sat, 3 Jul 2004 13:28:59 +0000 Subject: 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(). --- sysdeps/linux/glibtop_server.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'sysdeps/linux/glibtop_server.h') diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index a522cefb..ab1d32aa 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -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 #include @@ -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__ */ -- cgit v1.2.1