Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
06c3f2aa 29734550

+18 -13
+1 -13
tools/perf/builtin-script.c
··· 26 26 #include "util/string2.h" 27 27 #include "util/thread-stack.h" 28 28 #include "util/time-utils.h" 29 + #include "util/path.h" 29 30 #include "print_binary.h" 30 31 #include <linux/bitmap.h> 31 32 #include <linux/kernel.h> ··· 2400 2399 out: 2401 2400 free(str); 2402 2401 return rc; 2403 - } 2404 - 2405 - /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ 2406 - static int is_directory(const char *base_path, const struct dirent *dent) 2407 - { 2408 - char path[PATH_MAX]; 2409 - struct stat st; 2410 - 2411 - sprintf(path, "%s/%s", base_path, dent->d_name); 2412 - if (stat(path, &st)) 2413 - return 0; 2414 - 2415 - return S_ISDIR(st.st_mode); 2416 2402 } 2417 2403 2418 2404 #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
+14
tools/perf/util/path.c
··· 18 18 #include <stdio.h> 19 19 #include <sys/types.h> 20 20 #include <sys/stat.h> 21 + #include <dirent.h> 21 22 #include <unistd.h> 22 23 23 24 static char bad_path[] = "/bad-path/"; ··· 77 76 return false; 78 77 79 78 return S_ISREG(st.st_mode); 79 + } 80 + 81 + /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ 82 + bool is_directory(const char *base_path, const struct dirent *dent) 83 + { 84 + char path[PATH_MAX]; 85 + struct stat st; 86 + 87 + sprintf(path, "%s/%s", base_path, dent->d_name); 88 + if (stat(path, &st)) 89 + return false; 90 + 91 + return S_ISDIR(st.st_mode); 80 92 }
+3
tools/perf/util/path.h
··· 2 2 #ifndef _PERF_PATH_H 3 3 #define _PERF_PATH_H 4 4 5 + struct dirent; 6 + 5 7 int path__join(char *bf, size_t size, const char *path1, const char *path2); 6 8 int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3); 7 9 8 10 bool is_regular_file(const char *file); 11 + bool is_directory(const char *base_path, const struct dirent *dent); 9 12 10 13 #endif /* _PERF_PATH_H */