diff options
author | Jiri Olsa <jolsa@kernel.org> | 2017-12-06 12:45:35 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-12-27 10:15:48 -0500 |
commit | 06c3f2aa9fc68e7f3fe3d83e7569d2a2801d9f99 (patch) | |
tree | 36061880d13768b6761cdf2e6aac9a76be5d15e1 | |
parent | 29734550c996c259ffa8d32198439d6fe4b51320 (diff) |
perf utils: Move is_directory() to path.h
So that it can be used more widely, like in the next patch, when it will
be used to fix a bug in 'perf test' handling of dirent.d_type ==
DT_UNKNOWN.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20171206174535.25380-1-jolsa@kernel.org
[ Split from a larger patch, removed needless includes in path.h ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-script.c | 14 | ||||
-rw-r--r-- | tools/perf/util/path.c | 14 | ||||
-rw-r--r-- | tools/perf/util/path.h | 3 |
3 files changed, 18 insertions, 13 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index fac6f053e4da..77e47cf39f2c 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "util/string2.h" | 26 | #include "util/string2.h" |
27 | #include "util/thread-stack.h" | 27 | #include "util/thread-stack.h" |
28 | #include "util/time-utils.h" | 28 | #include "util/time-utils.h" |
29 | #include "util/path.h" | ||
29 | #include "print_binary.h" | 30 | #include "print_binary.h" |
30 | #include <linux/bitmap.h> | 31 | #include <linux/bitmap.h> |
31 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
@@ -2401,19 +2402,6 @@ out: | |||
2401 | return rc; | 2402 | return rc; |
2402 | } | 2403 | } |
2403 | 2404 | ||
2404 | /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ | ||
2405 | static int is_directory(const char *base_path, const struct dirent *dent) | ||
2406 | { | ||
2407 | char path[PATH_MAX]; | ||
2408 | struct stat st; | ||
2409 | |||
2410 | sprintf(path, "%s/%s", base_path, dent->d_name); | ||
2411 | if (stat(path, &st)) | ||
2412 | return 0; | ||
2413 | |||
2414 | return S_ISDIR(st.st_mode); | ||
2415 | } | ||
2416 | |||
2417 | #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \ | 2405 | #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \ |
2418 | while ((lang_dirent = readdir(scripts_dir)) != NULL) \ | 2406 | while ((lang_dirent = readdir(scripts_dir)) != NULL) \ |
2419 | if ((lang_dirent->d_type == DT_DIR || \ | 2407 | if ((lang_dirent->d_type == DT_DIR || \ |
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 933f5c6bffb4..ca56ba2dd3da 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <sys/stat.h> | 20 | #include <sys/stat.h> |
21 | #include <dirent.h> | ||
21 | #include <unistd.h> | 22 | #include <unistd.h> |
22 | 23 | ||
23 | static char bad_path[] = "/bad-path/"; | 24 | static char bad_path[] = "/bad-path/"; |
@@ -77,3 +78,16 @@ bool is_regular_file(const char *file) | |||
77 | 78 | ||
78 | return S_ISREG(st.st_mode); | 79 | return S_ISREG(st.st_mode); |
79 | } | 80 | } |
81 | |||
82 | /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ | ||
83 | bool is_directory(const char *base_path, const struct dirent *dent) | ||
84 | { | ||
85 | char path[PATH_MAX]; | ||
86 | struct stat st; | ||
87 | |||
88 | sprintf(path, "%s/%s", base_path, dent->d_name); | ||
89 | if (stat(path, &st)) | ||
90 | return false; | ||
91 | |||
92 | return S_ISDIR(st.st_mode); | ||
93 | } | ||
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h index 14a254ada7eb..f014f905df50 100644 --- a/tools/perf/util/path.h +++ b/tools/perf/util/path.h | |||
@@ -2,9 +2,12 @@ | |||
2 | #ifndef _PERF_PATH_H | 2 | #ifndef _PERF_PATH_H |
3 | #define _PERF_PATH_H | 3 | #define _PERF_PATH_H |
4 | 4 | ||
5 | struct dirent; | ||
6 | |||
5 | int path__join(char *bf, size_t size, const char *path1, const char *path2); | 7 | int path__join(char *bf, size_t size, const char *path1, const char *path2); |
6 | int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3); | 8 | int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3); |
7 | 9 | ||
8 | bool is_regular_file(const char *file); | 10 | bool is_regular_file(const char *file); |
11 | bool is_directory(const char *base_path, const struct dirent *dent); | ||
9 | 12 | ||
10 | #endif /* _PERF_PATH_H */ | 13 | #endif /* _PERF_PATH_H */ |