summaryrefslogtreecommitdiff
path: root/sysdeps/linux/glibtop_private.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/linux/glibtop_private.c')
-rw-r--r--sysdeps/linux/glibtop_private.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c
index ac1a0e19..1029173c 100644
--- a/sysdeps/linux/glibtop_private.c
+++ b/sysdeps/linux/glibtop_private.c
@@ -17,27 +17,31 @@
unsigned long long
get_scaled(const char *buffer, const char *key)
{
- const char *ptr;
+ const char *ptr = buffer;;
char *next;
- unsigned long long value = 0;
+ unsigned long long value;
+
+ if (key) {
+ if (G_LIKELY((ptr = strstr(buffer, key))))
+ ptr += strlen(key);
+ else {
+ g_warning("Could not read key '%s' in buffer '%s'",
+ key, buffer);
+ return 0;
+ }
+ }
- if (G_LIKELY((ptr = strstr(buffer, key))))
- {
- ptr += strlen(key);
- value = strtoull(ptr, &next, 0);
-
- for ( ; *next; ++next) {
- if (*next == 'k') {
- value *= 1024;
- break;
- } else if (*next == 'M') {
- value *= 1024 * 1024;
- break;
- }
+ value = strtoull(ptr, &next, 0);
+
+ for ( ; *next; ++next) {
+ if (*next == 'k') {
+ value *= 1024;
+ break;
+ } else if (*next == 'M') {
+ value *= 1024 * 1024;
+ break;
}
- } else
- g_warning("Could not read key '%s' in buffer '%s'",
- key, buffer);
+ }
return value;
}