15 static char bad_path[] =
"/bad-path/";
20 static const char *get_perf_dir(
void)
31 size_t len = (ret >=
size) ? size - 1 : ret;
39 static char *get_pathname(
void)
41 static char pathname_array[4][
PATH_MAX];
44 return pathname_array[3 & ++
idx];
47 static char *cleanup_path(
char *
path)
50 if (!
memcmp(path,
"./", 2)) {
58 static char *perf_vsnpath(
char *
buf,
size_t n,
const char *
fmt,
va_list args)
60 const char *perf_dir = get_perf_dir();
66 memcpy(buf, perf_dir, len);
69 len +=
vsnprintf(buf + len, n - len, fmt, args);
72 return cleanup_path(buf);
83 (
void)perf_vsnpath(path,
sizeof(path),
fmt, args);
99 return cleanup_path(pathname);
104 const char *perf_dir = get_perf_dir();
112 memcpy(pathname, perf_dir, len);
113 if (len && perf_dir[len-1] !=
'/')
114 pathname[len++] =
'/';
120 return cleanup_path(pathname);
124 static inline int chomp_trailing_dir_sep(
const char *path,
int len)
138 int path_len =
strlen(path), suffix_len =
strlen(suffix);
147 path_len = chomp_trailing_dir_sep(path, path_len);
148 suffix_len = chomp_trailing_dir_sep(suffix, suffix_len);
150 else if (path[--path_len] != suffix[--suffix_len])
154 if (path_len && !
is_dir_sep(path[path_len - 1]))
156 return strndup(path, chomp_trailing_dir_sep(path, path_len));