Merge branch 'stable/xen-pcifront-fixes' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / tools / perf / util / abspath.c
blob0e76affe9c362b3bd67171e8dcfa18f0c0373167
1 #include "cache.h"
3 static const char *get_pwd_cwd(void)
5 static char cwd[PATH_MAX + 1];
6 char *pwd;
7 struct stat cwd_stat, pwd_stat;
8 if (getcwd(cwd, PATH_MAX) == NULL)
9 return NULL;
10 pwd = getenv("PWD");
11 if (pwd && strcmp(pwd, cwd)) {
12 stat(cwd, &cwd_stat);
13 if (!stat(pwd, &pwd_stat) &&
14 pwd_stat.st_dev == cwd_stat.st_dev &&
15 pwd_stat.st_ino == cwd_stat.st_ino) {
16 strlcpy(cwd, pwd, PATH_MAX);
19 return cwd;
22 const char *make_nonrelative_path(const char *path)
24 static char buf[PATH_MAX + 1];
26 if (is_absolute_path(path)) {
27 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
28 die("Too long path: %.*s", 60, path);
29 } else {
30 const char *cwd = get_pwd_cwd();
31 if (!cwd)
32 die("Cannot determine the current working directory");
33 if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
34 die("Too long path: %.*s", 60, path);
36 return buf;