Using paths that are searchable but not completely readable
hga@xxxxxx 23 Apr 2020 12:29 UTC
From: Lassi Kortela <xxxxxx@lassi.io>
Date: Thursday, April 23, 2020 7:09 AM
> [...]
>
> <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>
>
> That page also has a warning about the possibility of getcwd() failing,
> I don't know how relevant this scenario is:
>> If a program is operating in a directory where some (grand)parent directory does not permit reading, getcwd() may fail, as in most implementations it must read the directory to determine the name of the file. This can occur if search, but not read, permission is granted in an intermediate directory, or if the program is placed in that directory by some more privileged process (for example, login). Including the [EACCES] error condition makes the reporting of the error consistent and warns the application developer that getcwd() can fail for reasons beyond the control of the application developer or user. Some implementations can avoid this occurrence (for example, by implementing getcwd() using pwd, where pwd is a set-user-root process), thus the error was made optional. Since this volume of POSIX.1-2017 permits the addition of other errors, this would be a common addition and yet one that applications could not be expected to deal with without this addition.
I've run into it in "real life" use of POSIX systems over the years, and
therefore include a bit of testing for it in my Chibi Scheme implementation.
- Harold