tools lib fs: Adopt filename__read_int from tools/perf/
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 11 Dec 2014 16:17:46 +0000 (13:17 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 11 Dec 2014 16:17:46 +0000 (13:17 -0300)
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>
tools/lib/api/fs/fs.c
tools/lib/api/fs/fs.h
tools/perf/util/util.c
tools/perf/util/util.h

index c1b49c36a951d74b1c12b417b20428b0f4326e70..b8d0df8878d1e8847c0c62dfb999fb5f1f95854e 100644 (file)
@@ -7,6 +7,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include "debugfs.h"
 #include "fs.h"
@@ -163,3 +167,20 @@ const char *name##__mountpoint(void)       \
 
 FS__MOUNTPOINT(sysfs,  FS__SYSFS);
 FS__MOUNTPOINT(procfs, FS__PROCFS);
+
+int filename__read_int(const char *filename, int *value)
+{
+       char line[64];
+       int fd = open(filename, O_RDONLY), err = -1;
+
+       if (fd < 0)
+               return -1;
+
+       if (read(fd, line, sizeof(line)) > 0) {
+               *value = atoi(line);
+               err = 0;
+       }
+
+       close(fd);
+       return err;
+}
index cb7049551f335d6a7dbcb108933ba8e9d16e5e59..4d0aef6e71639f3e43bbf5b5e3e3c041de48f87d 100644 (file)
@@ -11,4 +11,6 @@
 
 const char *sysfs__mountpoint(void);
 const char *procfs__mountpoint(void);
+
+int filename__read_int(const char *filename, int *value);
 #endif /* __API_FS__ */
index d5eab3f3323ff42e4ac133878248b091a359f835..41125e5b011e6e21e4a2de3f959984a704e0fa34 100644 (file)
@@ -442,23 +442,6 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
        return (unsigned long) -1;
 }
 
-int filename__read_int(const char *filename, int *value)
-{
-       char line[64];
-       int fd = open(filename, O_RDONLY), err = -1;
-
-       if (fd < 0)
-               return -1;
-
-       if (read(fd, line, sizeof(line)) > 0) {
-               *value = atoi(line);
-               err = 0;
-       }
-
-       close(fd);
-       return err;
-}
-
 int filename__read_str(const char *filename, char **buf, size_t *sizep)
 {
        size_t size = 0, alloc_size = 0;
index abc445ee4f6063a25d77411741e8cba33d6f9bfb..008b361b175882afcfda818b156624b8ca212cf3 100644 (file)
@@ -343,7 +343,6 @@ char *get_srcline(struct dso *dso, unsigned long addr, struct symbol *sym,
                  bool show_sym);
 void free_srcline(char *srcline);
 
-int filename__read_int(const char *filename, int *value);
 int filename__read_str(const char *filename, char **buf, size_t *sizep);
 int perf_event_paranoid(void);