diff options
Diffstat (limited to 'tools/lib/api/fs')
| -rw-r--r-- | tools/lib/api/fs/fs.c | 20 | ||||
| -rw-r--r-- | tools/lib/api/fs/fs.h | 2 | ||||
| -rw-r--r-- | tools/lib/api/fs/tracing_path.c | 3 | 
3 files changed, 23 insertions, 2 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index ef78c22ff44d..ba7094b945ff 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -283,6 +283,11 @@ int filename__read_int(const char *filename, int *value)  	return err;  } +/* + * Parses @value out of @filename with strtoull. + * By using 0 for base, the strtoull detects the + * base automatically (see man strtoull). + */  int filename__read_ull(const char *filename, unsigned long long *value)  {  	char line[64]; @@ -292,7 +297,7 @@ int filename__read_ull(const char *filename, unsigned long long *value)  		return -1;  	if (read(fd, line, sizeof(line)) > 0) { -		*value = strtoull(line, NULL, 10); +		*value = strtoull(line, NULL, 0);  		if (*value != ULLONG_MAX)  			err = 0;  	} @@ -351,6 +356,19 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)  	return err;  } +int procfs__read_str(const char *entry, char **buf, size_t *sizep) +{ +	char path[PATH_MAX]; +	const char *procfs = procfs__mountpoint(); + +	if (!procfs) +		return -1; + +	snprintf(path, sizeof(path), "%s/%s", procfs, entry); + +	return filename__read_str(path, buf, sizep); +} +  int sysfs__read_ull(const char *entry, unsigned long long *value)  {  	char path[PATH_MAX]; diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index 9f6598098dc5..16c9c2ed7c5b 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h @@ -29,6 +29,8 @@ int filename__read_int(const char *filename, int *value);  int filename__read_ull(const char *filename, unsigned long long *value);  int filename__read_str(const char *filename, char **buf, size_t *sizep); +int procfs__read_str(const char *entry, char **buf, size_t *sizep); +  int sysctl__read_int(const char *sysctl, int *value);  int sysfs__read_int(const char *entry, int *value);  int sysfs__read_ull(const char *entry, unsigned long long *value); diff --git a/tools/lib/api/fs/tracing_path.c b/tools/lib/api/fs/tracing_path.c index a26bb5ea8283..251b7c342a87 100644 --- a/tools/lib/api/fs/tracing_path.c +++ b/tools/lib/api/fs/tracing_path.c @@ -5,6 +5,7 @@  #include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include <linux/string.h>  #include <errno.h>  #include <unistd.h>  #include "fs.h" @@ -118,7 +119,7 @@ static int strerror_open(int err, char *buf, size_t size, const char *filename)  	}  		break;  	default: -		snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf))); +		snprintf(buf, size, "%s", str_error_r(err, sbuf, sizeof(sbuf)));  		break;  	}  |