]> Pileus Git - ~andy/linux/blobdiff - tools/perf/util/util.c
perf tools: Introduce filename__read_int helper
[~andy/linux] / tools / perf / util / util.c
index 8dc8cf39f4edc0f988c63a48daa47395a1c5ef87..c25e57b3acb2994d7d53b8089f1897030b71efb7 100644 (file)
@@ -394,3 +394,20 @@ 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;
+}