add getopt reset support
[musl] / src / misc / get_current_dir_name.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <limits.h>
4 #include <unistd.h>
5 #include <sys/stat.h>
6
7 char *get_current_dir_name(void) {
8         struct stat a, b;
9         char buf[PATH_MAX];
10         char *res = getenv("PWD");
11         if (res && *res && !stat(res, &a) && !stat(".", &b)
12             && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino))
13                 return strdup(res);
14         if(!getcwd(buf, sizeof(buf))) return NULL;
15         return strdup(buf);
16 }