From 9c52df1131cf208df3e73cb440485d3673c6491a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 1 Jan 2020 13:02:20 -0600 Subject: 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. --- toys/posix/pwd.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'toys/posix/pwd.c') 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"); } -- cgit v1.2.3