Skip to content

Commit dfe96e3

Browse files
olsajirigregkh
authored andcommitted
perf utils: Move is_directory() to path.h
commit 06c3f2a upstream. 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 <[email protected]> Cc: David Ahern <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ Split from a larger patch, removed needless includes in path.h ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Ignat Korchagin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 75fc05a commit dfe96e3

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

tools/perf/builtin-script.c

+1-13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "util/string2.h"
2626
#include "util/thread-stack.h"
2727
#include "util/time-utils.h"
28+
#include "util/path.h"
2829
#include "print_binary.h"
2930
#include <linux/bitmap.h>
3031
#include <linux/kernel.h>
@@ -2129,19 +2130,6 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
21292130
return rc;
21302131
}
21312132

2132-
/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
2133-
static int is_directory(const char *base_path, const struct dirent *dent)
2134-
{
2135-
char path[PATH_MAX];
2136-
struct stat st;
2137-
2138-
sprintf(path, "%s/%s", base_path, dent->d_name);
2139-
if (stat(path, &st))
2140-
return 0;
2141-
2142-
return S_ISDIR(st.st_mode);
2143-
}
2144-
21452133
#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
21462134
while ((lang_dirent = readdir(scripts_dir)) != NULL) \
21472135
if ((lang_dirent->d_type == DT_DIR || \

tools/perf/util/path.c

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stdio.h>
1919
#include <sys/types.h>
2020
#include <sys/stat.h>
21+
#include <dirent.h>
2122
#include <unistd.h>
2223

2324
static char bad_path[] = "/bad-path/";
@@ -77,3 +78,16 @@ bool is_regular_file(const char *file)
7778

7879
return S_ISREG(st.st_mode);
7980
}
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+
}

tools/perf/util/path.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#ifndef _PERF_PATH_H
33
#define _PERF_PATH_H
44

5+
struct dirent;
6+
57
int path__join(char *bf, size_t size, const char *path1, const char *path2);
68
int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3);
79

810
bool is_regular_file(const char *file);
11+
bool is_directory(const char *base_path, const struct dirent *dent);
912

1013
#endif /* _PERF_PATH_H */

0 commit comments

Comments
 (0)