summaryrefslogtreecommitdiff
path: root/sysdeps/linux/glibtop_server.c
blob: 73075036d881b57302ffc98be29e1ed14dc06d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string.h>
#include <stdlib.h>

unsigned long long
get_scaled(const char *buffer, const char *key)
{
	const char    *ptr;
	char	      *next;
	const size_t len = strlen(key);
	unsigned long long value = 0;

	if ((ptr = strstr(buffer, key)))
	{
		ptr += len;
		value = strtoull(ptr, &next, 0);
		if (strchr(next, 'k'))
			value *= 1024;
		else if (strchr(next, 'M'))
			value *= 1024 * 1024;
	}
	return value;
}