diff options
Diffstat (limited to 'toys/posix/pwd.c')
-rw-r--r-- | toys/posix/pwd.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/toys/posix/pwd.c b/toys/posix/pwd.c index 4c6ae99b..c7dc78f7 100644 --- a/toys/posix/pwd.c +++ b/toys/posix/pwd.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/pwd.html -USE_PWD(NEWTOY(pwd, ">0LP[-LP]", TOYFLAG_BIN)) +USE_PWD(NEWTOY(pwd, ">0LP[-LP]", TOYFLAG_BIN|TOYFLAG_MAYFORK)) config PWD bool "pwd" @@ -26,7 +26,7 @@ void pwd_main(void) char *s, *pwd = getcwd(0, 0), *PWD; // Only use $PWD if it's an absolute path alias for cwd with no "." or ".." - if (!(toys.optflags & FLAG_P) && (s = PWD = getenv("PWD"))) { + if (!FLAG(P) && (s = PWD = getenv("PWD"))) { struct stat st1, st2; while (*s == '/') { @@ -37,18 +37,16 @@ void pwd_main(void) while (*s && *s != '/') s++; } if (!*s && s != PWD) s = PWD; - else s = NULL; + else s = 0; // If current directory exists, make sure it matches. if (s && pwd) if (stat(pwd, &st1) || stat(PWD, &st2) || st1.st_ino != st2.st_ino || - st1.st_dev != st2.st_dev) s = NULL; - } else s = NULL; + st1.st_dev != st2.st_dev) s = 0; + } else s = 0; // If -L didn't give us a valid path, use cwd. - if (!s && !(s = pwd)) perror_exit("xgetcwd"); - - xprintf("%s\n", s); - - if (CFG_TOYBOX_FREE) free(pwd); + if (s || (s = pwd)) puts(s); + free(pwd); + if (!s) perror_exit("xgetcwd"); } |