aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/api/fs/fs.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2014-12-11 11:17:46 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-12-11 11:17:46 -0500
commit3a351127cbc682c3a0ae7383c4ff6fd0e8fee83c (patch)
tree7764be99863cf2d9ca95f0f42336756f0e6dcbb7 /tools/lib/api/fs/fs.c
parent99d348a84c2118ed04c9b72168787f55e2fe33a5 (diff)
tools lib fs: Adopt filename__read_int from tools/perf/
Will be useful for new helpers to read sysctl values. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/api/fs/fs.c')
-rw-r--r--tools/lib/api/fs/fs.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index c1b49c36a951..b8d0df8878d1 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -7,6 +7,10 @@
7#include <stdlib.h> 7#include <stdlib.h>
8#include <string.h> 8#include <string.h>
9#include <sys/vfs.h> 9#include <sys/vfs.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <unistd.h>
10 14
11#include "debugfs.h" 15#include "debugfs.h"
12#include "fs.h" 16#include "fs.h"
@@ -163,3 +167,20 @@ const char *name##__mountpoint(void) \
163 167
164FS__MOUNTPOINT(sysfs, FS__SYSFS); 168FS__MOUNTPOINT(sysfs, FS__SYSFS);
165FS__MOUNTPOINT(procfs, FS__PROCFS); 169FS__MOUNTPOINT(procfs, FS__PROCFS);
170
171int filename__read_int(const char *filename, int *value)
172{
173 char line[64];
174 int fd = open(filename, O_RDONLY), err = -1;
175
176 if (fd < 0)
177 return -1;
178
179 if (read(fd, line, sizeof(line)) > 0) {
180 *value = atoi(line);
181 err = 0;
182 }
183
184 close(fd);
185 return err;
186}