| * I'm tired of doing "vsnprintf()" etc just to open a |
| * file, so here's a "return static buffer with printf" |
| * It's obviously not thread-safe. Sue me. But it's quite |
| * useful for doing things like |
| * f = open(mkpath("%s/%s.perf", base, name), O_RDONLY); |
| * which is what it's designed for. |
| static char bad_path[] = "/bad-path/"; |
| static char *get_pathname(void) |
| static char pathname_array[4][PATH_MAX]; |
| return pathname_array[3 & ++idx]; |
| static char *cleanup_path(char *path) |
| if (!memcmp(path, "./", 2)) { |
| char *mkpath(const char *fmt, ...) |
| char *pathname = get_pathname(); |
| len = vsnprintf(pathname, PATH_MAX, fmt, args); |
| return cleanup_path(pathname); |