PR-4608716.ls.c.patch [plain text]
--- ls/ls.c.orig 2006-10-25 13:25:54.000000000 -0700
+++ ls/ls.c 2006-10-25 16:35:22.000000000 -0700
@@ -350,15 +350,17 @@
{
FTS *ftsp;
FTSENT *p, *chp;
- int ch_options;
+ int ch_options, save_errno;
if ((ftsp =
fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
err(EXIT_FAILURE, NULL);
display(NULL, fts_children(ftsp, 0));
- if (f_listdir)
- return;
+ if (f_listdir) {
+ (void)fts_close(ftsp);
+ return;
+ }
/*
* If not recursing down this tree and don't need stat info, just get
@@ -400,6 +402,12 @@
(void)fts_set(ftsp, p, FTS_SKIP);
break;
}
+
+ /* Only care about errno set by fts_read() */
+ save_errno = errno;
+ (void)fts_close(ftsp);
+ errno = save_errno;
+
if (errno)
err(EXIT_FAILURE, "fts_read");
}