bug#62385: POSIX behavior of readlink, realpath

Collin Funk <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <[email protected]>
Hi Paul,

I should have waited a few minutes before pushing. Oops...

Paul Eggert <[email protected]> writes:

> On 2025-08-03 11:08, Collin Funk wrote:
>
>> +  readlink will behave as if the -v option is used if the
>> +  POSIXLY_CORRECT environment variable is defined.
>
> This isn't true if -q/--quiet/-s/--silent is specified. I would reword
> this to something like "readlink now defaults to being verbose if
> POSIXLY_CORRECT is set."

True, that is more accurate.

> The --usage message and doc/coreutils.texi should be updated to match
> the new behavior.

I added a brief mention in doc/coreutils.texi. I guess it could be made
more explicit by mentioning under --silent and --quiet as well.

I only saw POSIXLY_CORRECT mentioned in the --help message for 'df' and
'du' for the block size difference. So I assumed it was not nessecary.

How about the wording and formatting of the attatched patch?

> There's a spurious empty line inserted into readlink.c.

I rewrote v2 based on v1 and left that. Oops.

Collin
0001-readlink-improve-documentation-for-POSIXLY_CORRECT-i.patch (text/x-patch, 3 KB)
From 2ff3c65e940f152a7b56395a5828c052f30dba50 Mon Sep 17 00:00:00 2001
Message-ID: <2ff3c65e940f152a7b56395a5828c052f30dba50.1754249985.git.collin.funk1@gmail.com>
From: Collin Funk <[email protected]>
Date: Sun, 3 Aug 2025 12:33:55 -0700
Subject: [PATCH] readlink: improve documentation for POSIXLY_CORRECT in --help

* NEWS: Improve wording to not imply POSIXLY_CORRECT=1 readlink -q will
be verbose.
* src/readlink.c (usage): Mention the affect of POSIXLY_CORRECT on
-s (--silent), -q (--quiet), and -v (--verbose) in the help message.
(main): Remove spurious newline added by previous commit.
* doc/coreutils.texi (readlink invocation): Mention that -s (--silent)
and -q (--quiet) are not the default when POSIXLY_CORRECT is set.
---
 NEWS               | 4 ++--
 doc/coreutils.texi | 6 +++++-
 src/readlink.c     | 7 ++++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 9839aeb87..a9132bbcf 100644
--- a/NEWS
+++ b/NEWS
@@ -7,8 +7,8 @@ GNU coreutils NEWS                                    -*- outline -*-
   'factor' is now much faster at identifying large prime numbers,
   and significantly faster on composite numbers greater than 2^128.
 
-  readlink will behave as if the -v option is used if the
-  POSIXLY_CORRECT environment variable is defined.
+  readlink now defaults to being verbose if the POSIXLY_CORRECT
+  environment variable is set.
 
 ** Bug fixes
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index f268c9249..c5ecf2376 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11462,7 +11462,11 @@ @node readlink invocation
 @opindex -q
 @opindex --silent
 @opindex --quiet
-Suppress most error messages.  On by default.
+Suppress most error messages.
+
+@vindex POSIXLY_CORRECT
+This option is on by default if the @env{POSIXLY_CORRECT} environment
+variable is not set.
 
 @item -v
 @itemx --verbose
diff --git a/src/readlink.c b/src/readlink.c
index 9e7f2320a..e77818592 100644
--- a/src/readlink.c
+++ b/src/readlink.c
@@ -78,8 +78,10 @@ usage (int status)
                                 without requirements on components existence\n\
   -n, --no-newline              do not output the trailing delimiter\n\
   -q, --quiet\n\
-  -s, --silent                  suppress most error messages (on by default)\n\
-  -v, --verbose                 report error messages\n\
+  -s, --silent                  suppress most error messages (on by default\n\
+                                if POSIXLY_CORRECT is not set)\n\
+  -v, --verbose                 report error messages (on by default if\n\
+                                POSIXLY_CORRECT is set)\n\
   -z, --zero                    end each output line with NUL, not newline\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -163,7 +165,6 @@ main (int argc, char **argv)
       char *value = (can_mode != -1
                      ? canonicalize_filename_mode (fname, can_mode)
                      : areadlink_with_size (fname, 63));
-
       if (value)
         {
           fputs (value, stdout);
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.