about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-02-17 23:56:28 -0500
committerRich Felker <dalias@aerifal.cx>2012-02-17 23:56:28 -0500
commitf96eb335e1ea050b781904d589bf8413131bee48 (patch)
tree28de8f300ba73b17e129009f4e50e4ce67e8829a
parent61c2cf877ba7518a46d0391f119b3251e5a136b2 (diff)
downloadmusl-f96eb335e1ea050b781904d589bf8413131bee48.tar.gz
musl-f96eb335e1ea050b781904d589bf8413131bee48.tar.xz
musl-f96eb335e1ea050b781904d589bf8413131bee48.zip
fix get_current_dir_name behavior
-rw-r--r--src/misc/get_current_dir_name.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/misc/get_current_dir_name.c b/src/misc/get_current_dir_name.c
index 212edf31..e0f463b5 100644
--- a/src/misc/get_current_dir_name.c
+++ b/src/misc/get_current_dir_name.c
@@ -2,11 +2,15 @@
 #include <string.h>
 #include <limits.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 char *get_current_dir_name(void) {
+	struct stat a, b;
 	char buf[PATH_MAX];
-	char* res = getenv("PWD");
-	if(res && *res) return strdup(res);
+	char *res = getenv("PWD");
+	if (res && *res && !stat(res, &a) && !stat(".", &b)
+	    && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino))
+		return strdup(res);
 	if(!getcwd(buf, sizeof(buf))) return NULL;
 	return strdup(buf);
 }