bug#62385: POSIX behavior of readlink, realpath
Pádraig Brady <[email protected]>
| Newsgroups | gmane.comp.gnu.core-utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
On 03/08/2025 05:33, Collin Funk wrote: > Hi Eric, > > You said: > >> Among other things, I can see the following changes that coreutils >> will need to make to become compliant, or else we need to push back on >> the POSIX folks if we have strong reasons to complain that their >> specification will break things: >> >> POSIX wants 'readlink non-symlink' to output a diagnostic; that is, it >> looks like POSIX wants us to behave like '-v' is enabled by default >> (our current behavior of -q by default will be non-compliant). > > I have attached a patch that I think is correct for readlink. > > It is a bit more complex than just behaving the same as 'readlink -v' > previously would. This is because the behavior of non-POSIX > options. Here are some commands: > > $ touch file > $ ln -s symlink file > > # Example 1 > $ readlink -v file > readlink: file: Invalid argument > > # Example 2 > $ readlink -v -f file > /home/collin/file > > If 'readlink -v' where 'POSIXLY_CORRECT=1 readlink' then example 1 would > conform. I think that example 2 would violate POSIX. > > So, when POSIXLY_CORRECT is enabled we can call 'readlink', check for > errors, and then canonicalize if it is successful. I'd say any option apart from -n implicitly disables strict POSIX conformance, since those options are not in POSIX at all. So all I'd do is enable -v if POSIXLY_CORRECT is set. There is the argument for defaulting to -v, but I see FreeBSD does not output an error either if file is not a symlink, so it's probably best to only enable -v if POSIXLY_CORRECT is set. In NEWS this should be under "Changes in behavior" rather than "New Features". Thanks for following up on this. Padraig.