[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stat vs. "-"

From: Jim Meyering
Subject: stat vs. "-"
Date: Tue, 15 Sep 2009 13:49:20 +0200

In looking at Pádraig's report of a tail test failure with ksh,
I wanted to see how ksh pipes differed from bash/zsh ones,
by doing this:

for i in sh zsh bash ksh; do printf "$i: "; $i -c ':|./stat --format=%F -';done
sh: fifo
zsh: fifo
bash: fifo
ksh: socket

But couldn't, because stat didn't accept "-" as meaning standard input.
Here's a patch to make it do that (and make the above print what's displayed):

diff --git a/src/stat.c b/src/stat.c
index 3302270..56d25e6 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -857,7 +857,15 @@ do_stat (char const *filename, bool terse, char const 
   struct stat statbuf;

-  if ((follow_links ? stat : lstat) (filename, &statbuf) != 0)
+  if (STREQ (filename, "-"))
+    {
+      if (fstat (STDIN_FILENO, &statbuf) != 0)
+        {
+          error (0, errno, _("cannot stat standard input"));
+          return false;
+        }
+    }
+  else if ((follow_links ? stat : lstat) (filename, &statbuf) != 0)
       error (0, errno, _("cannot stat %s"), quote (filename));
       return false;

This is just FYI.
Of course I'll add the usual NEWS, log and tests and post again later.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]