Skip to content

Commit

Permalink
tools lib fs: Adopt filename__read_int from tools/perf/
Browse files Browse the repository at this point in the history
Will be useful for new helpers to read sysctl values.

Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Don Zickus <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Dec 11, 2014
1 parent 99d348a commit 3a35112
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
21 changes: 21 additions & 0 deletions tools/lib/api/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions tools/lib/api/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
17 changes: 0 additions & 17 deletions tools/perf/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3a35112

Please sign in to comment.