summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-11-01 21:40:01 +0000
committerJim Meyering <jim@meyering.net>2001-11-01 21:40:01 +0000
commit6fa5979ccb0a1bb10af49c6a2cf12afc76ca3459 (patch)
tree1fddb42e02907cd729c388295c79d5504a4c8f2d /src
parent866d4b9e5965485ad1dbb0ff26cc3ac575364ab9 (diff)
downloadcoreutils-6fa5979ccb0a1bb10af49c6a2cf12afc76ca3459.tar.xz
Include dirfd.h.
(print_dir): If dirfd fails, resort to using stat.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/ls.c b/src/ls.c
index 0d57cb51c..80db94a58 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -108,6 +108,7 @@ int wcwidth ();
#include "argmatch.h"
#include "dirname.h"
+#include "dirfd.h"
#include "error.h"
#include "hard-locale.h"
#include "hash.h"
@@ -2036,7 +2037,12 @@ print_dir (const char *name, const char *realname)
if (LOOP_DETECT)
{
struct stat dir_stat;
- if (fstat (dirfd (reading), &dir_stat) < 0)
+ int fd = dirfd (reading);
+
+ /* If dirfd failed, endure the overhead of using stat. */
+ if ((0 <= fd
+ ? fstat (fd, &dir_stat)
+ : stat (name, &dir_stat)) < 0)
{
error (0, errno, _("cannot determine device and inode of %s"),
quotearg_colon (name));