fix get_current_dir_name behavior
This commit is contained in:
parent
61c2cf877b
commit
f96eb335e1
1 changed files with 6 additions and 2 deletions
|
|
@ -2,11 +2,15 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
char *get_current_dir_name(void) {
|
char *get_current_dir_name(void) {
|
||||||
|
struct stat a, b;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
char* res = getenv("PWD");
|
char *res = getenv("PWD");
|
||||||
if(res && *res) return strdup(res);
|
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;
|
if(!getcwd(buf, sizeof(buf))) return NULL;
|
||||||
return strdup(buf);
|
return strdup(buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue