diff options
author | Rob Landley <rob@landley.net> | 2020-01-01 13:02:20 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-01-01 13:02:20 -0600 |
commit | 9c52df1131cf208df3e73cb440485d3673c6491a (patch) | |
tree | 9f92a13560c9dac0282c97d496cd85491d04bd63 /toys/posix/pwd.c | |
parent | 7a9073f942b83d12d24415a92428e02aeb561a08 (diff) | |
download | toybox-9c52df1131cf208df3e73cb440485d3673c6491a.tar.gz |
Add MAYFORK to more pseudo-builtins.
This doesn't (yet) add shell builtin awareness to time, kill, or pwd,
just lets them run in the shell process.
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"); } |