[Toybox] macOS realpath test failures

Rob Landley rob at landley.net
Thu Jan 12 13:52:21 PST 2023


On 1/11/23 16:53, enh wrote:
> ah, which is probably because you won't typically have $PWD set on Android...
> 
>   // If this isn't an absolute path, start with cwd or $PWD.
>   if (*path != '/') {
>     if ((flags & ABS_KEEP) && (str = getenv("PWD")))
>       splitpath(path, splitpath(str, &todo));
>     else {
>       splitpath(path, splitpath(str = xgetcwd(), &todo));
>       free(str);
>     }

Which would explain the behavior difference, yes: getcwd() asks the OS for the
current path to "." which is always going to be fully resolved, which means
peeling off one member gives us the observed output.

>   } else splitpath(path, &todo);
> 
> mksh fakes it so `echo $PWD` works, but there's no _exported_ $PWD:

It's not faking it, it's setting the shell variable. But bash exports PWD by
default (and thus so does toybox), but mksh doesn't.

Toysh implemented the bash behavior and mksh... is mksh:

$ env -i bash --noprofile --norc -c 'declare -p PWD'
declare -x PWD="/home/landley/toybox/toybox"
$ env -i ./sh --noprofile --norc -c 'declare -p PWD'
declare -x PWD="/home/landley/toybox/toybox"
$ env -i mksh --noprofile --norc -c 'declare -p PWD'
mksh: mksh: --: unknown option

I added an "export PWD" to the test, does that fix it?

Rob


More information about the Toybox mailing list