<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/db5464df4b5bdf43c6db78af51c88d987c9055ab">https://github.com/macports/macports-legacy-support/commit/db5464df4b5bdf43c6db78af51c88d987c9055ab</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit db5464df4b5bdf43c6db78af51c88d987c9055ab
</span>Author: Fred Wright <fw@fwright.net>
AuthorDate: Fri Feb 16 19:47:10 2024 -0800
<span style='display:block; white-space:pre;color:#404040;'> fdopendir: Fix some incorrect expected failures
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This fixes multiple cases where the incorrect errno was being returned
</span><span style='display:block; white-space:pre;color:#404040;'> on failures, as well as one case where an expected failure didn't fail
</span><span style='display:block; white-space:pre;color:#404040;'> (closed fd on 10.4). One case was observable with the old tests when
</span><span style='display:block; white-space:pre;color:#404040;'> stdin was a pipe rather than a tty or pty, and then additional cases
</span><span style='display:block; white-space:pre;color:#404040;'> were discovered by additional tests motivated by that case.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> It now checks for a valid open directory fd at the start, and
</span><span style='display:block; white-space:pre;color:#404040;'> returns appropriate errors when not.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> TESTED:
</span><span style='display:block; white-space:pre;color:#404040;'> All tests now pass, including ones added in a subsequent commit.
</span><span style='display:block; white-space:pre;color:#404040;'> Tested on 10.4-10.5 ppc, 10.4-10.6 i386, 10.4-12.x x86_64, 11.x-14.x
</span><span style='display:block; white-space:pre;color:#404040;'> arm64.
</span>---
src/fdopendir.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/fdopendir.c b/src/fdopendir.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 8c4e62c..586be29 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -23,6 +23,7 @@
</span> #include "common-priv.h"
#include <dirent.h>
<span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/stat.h>
</span>
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#define __dd_fd dd_fd
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -36,19 +37,26 @@
</span> */
DIR *fdopendir(int dirfd) {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ DIR *dir;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ struct stat dirstat;
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- /* Check dirfd here (for macos-10.4, see _ATCALL() and best_fchdir()) */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Fail if dirfd isn't a valid open fd */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (fstat(dirfd, &dirstat) < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if (dirfd < 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- errno = EBADF;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Fail if dirfd isn't a directory */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!S_ISDIR(dirstat.st_mode)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ errno = ENOTDIR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return NULL;
</span> }
/* Open given directory fd safely for iteration via readdir */
<span style='display:block; white-space:pre;background:#ffe0e0;'>- DIR *dir = _ATCALL(dirfd, ".", NULL, opendir("."));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!dir)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dir = _ATCALL(dirfd, ".", NULL, opendir("."));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!dir) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
/*
* Replace underlying fd with supplied dirfd
</pre><pre style='margin:0'>
</pre>