X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Date: Sun, 23 Oct 2016 09:04:52 +0300 Message-Id: <83d1irppmj.fsf@gnu.org> From: "Eli Zaretskii (eliz AT gnu DOT org) [via djgpp AT delorie DOT com]" To: djgpp AT delorie DOT com In-reply-to: <580BCAA5.2000304@gmx.de> (djgpp@delorie.com) Subject: Re: A grep 2.26 test fails because fopen sets errno to EACCES when openning an existing directory. References: <580BCAA5 DOT 2000304 AT gmx DOT de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Date: Sat, 22 Oct 2016 22:23:01 +0200 > From: "Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via djgpp AT delorie DOT com]" > > While I was trying to port grep 2.26 I have observed that the implementation of > open retains errno to values that are generated by intermediary operations even > if the open operation performs well. > In this particular case an existing directory shall be open but errno is set to > EACCES by some DOS call and passed to the calling context that later uses this > errno to generate an error message. This is wrong IMHO. That's what DOS returns when you try to open a directory. > The calling context > is the grep code and not the djgpp library code. The documentation of the open > function clearly states that is at least possible to use the open function to > open a directory. Not on DOS, AFAIK. > Thus no errno number should be set as consequence of this > call if the directory exists. And this is the way linux works. On Unix, it is indeed possible to open a directory. But not on DOS. I see we've made 'open' to be able to do that, but '_open' should still error out with EACCES, because that's what DOS does. Not sure if your patch changes that. > I have changed fread and fwrite to return with EISDIR if the file pointer > corresponds to a directory I don't think EISDIR is right in this case, because Posix doesn't define that as one of the errno values returned by these functions. I think EBADF or ENXIO are better alternatives. > Of course, after having compiled grep with a changed library, the > check passes because fopen no longer fails with EACCES but the later > fread fails with EISDIR as it shall. Why does the test assume fread will fail with EISDIR? It doesn't on Unix, AFAIK.