]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/util/path.c
2 * I'm tired of doing "vsnprintf()" etc just to open a
3 * file, so here's a "return static buffer with printf"
6 * It's obviously not thread-safe. Sue me. But it's quite
7 * useful for doing things like
9 * f = open(mkpath("%s/%s.perf", base, name), O_RDONLY);
11 * which is what it's designed for.
17 static char bad_path
[] = "/bad-path/";
21 static char *get_pathname(void)
23 static char pathname_array
[4][PATH_MAX
];
26 return pathname_array
[3 & ++idx
];
29 static char *cleanup_path(char *path
)
32 if (!memcmp(path
, "./", 2)) {
40 char *mkpath(const char *fmt
, ...)
44 char *pathname
= get_pathname();
47 len
= vsnprintf(pathname
, PATH_MAX
, fmt
, args
);
51 return cleanup_path(pathname
);