diff options
Diffstat (limited to 'tools/lib/api')
-rw-r--r-- | tools/lib/api/fs/fs.c | 21 | ||||
-rw-r--r-- | tools/lib/api/fs/fs.h | 2 |
2 files changed, 23 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 | ||
164 | FS__MOUNTPOINT(sysfs, FS__SYSFS); | 168 | FS__MOUNTPOINT(sysfs, FS__SYSFS); |
165 | FS__MOUNTPOINT(procfs, FS__PROCFS); | 169 | FS__MOUNTPOINT(procfs, FS__PROCFS); |
170 | |||
171 | int 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 | } | ||
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index cb7049551f33..4d0aef6e7163 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h | |||
@@ -11,4 +11,6 @@ | |||
11 | 11 | ||
12 | const char *sysfs__mountpoint(void); | 12 | const char *sysfs__mountpoint(void); |
13 | const char *procfs__mountpoint(void); | 13 | const char *procfs__mountpoint(void); |
14 | |||
15 | int filename__read_int(const char *filename, int *value); | ||
14 | #endif /* __API_FS__ */ | 16 | #endif /* __API_FS__ */ |