提交 f96eb335 编写于 作者: R Rich Felker

fix get_current_dir_name behavior

上级 61c2cf87
......@@ -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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册