summaryrefslogtreecommitdiff
path: root/sysdeps/linux/glibtop_server.h
diff options
context:
space:
mode:
authorMartin Baulig <martin@src.gnome.org>1998-08-16 18:46:53 +0000
committerMartin Baulig <martin@src.gnome.org>1998-08-16 18:46:53 +0000
commit59bb8d0ced4e3a255bb77e07b5abb4d8aead05f8 (patch)
treec6400967a6a4b2ead897b6d164f7c6deb3649e79 /sysdeps/linux/glibtop_server.h
parent739ce693dcc33b3ec3c5c75d4c7b8f200f2608a8 (diff)
downloadlibgtop-59bb8d0ced4e3a255bb77e07b5abb4d8aead05f8.tar.gz
Major code cleanups. We now use open () and read ().
Diffstat (limited to 'sysdeps/linux/glibtop_server.h')
-rw-r--r--sysdeps/linux/glibtop_server.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h
index 2d3abe49..7526b661 100644
--- a/sysdeps/linux/glibtop_server.h
+++ b/sysdeps/linux/glibtop_server.h
@@ -27,6 +27,8 @@
__BEGIN_DECLS
+#ifdef _IN_LIBGTOP
+
static inline char *
skip_token (const char *p)
{
@@ -36,12 +38,74 @@ skip_token (const char *p)
}
static inline char *
+skip_multiple_token (const char *p, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ p = skip_token (p);
+
+ return (char *)p;
+}
+
+static inline char *
skip_line (const char *p)
{
while (*p != '\n') p++;
return (char *) p++;
}
+static inline int
+proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
+{
+ char filename [BUFSIZ];
+ int fd, len;
+
+ sprintf (filename, fmt, pid);
+
+ fd = open (filename, O_RDONLY);
+ if (fd < 0) return -1;
+
+ len = read (fd, buffer, BUFSIZ-1);
+ if (len < 0) return -1;
+
+ close (fd);
+
+ buffer [len] = '\0';
+
+ return 0;
+}
+
+static inline int
+proc_stat_to_buffer (char *buffer, pid_t pid)
+{
+ return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
+}
+
+static inline int
+proc_status_to_buffer (char *buffer, pid_t pid)
+{
+ return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
+}
+
+static inline int
+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)
+{
+ p = strrchr (p, ')');
+ if (!p) return p;
+
+ *p++ = '\0';
+ return p;
+}
+
+#endif
+
#define GLIBTOP_SUID_CPU 0
#define GLIBTOP_SUID_MEM 0
#define GLIBTOP_SUID_SWAP 0