X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com Message-ID: <580D0638.8080605@gmx.de> Date: Sun, 23 Oct 2016 20:49:28 +0200 From: "Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via djgpp AT delorie DOT com]" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7 MIME-Version: 1.0 To: djgpp AT delorie DOT 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> <83d1irppmj DOT fsf AT gnu DOT org> In-Reply-To: <83d1irppmj.fsf@gnu.org> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:MufuLXoWigqHbd31C0L1zpe3+v22V+ib87aOvdkWCx3EP5Zq2QV ZimhsV6lXK0mZMZAU1fGaOl+glvsssTnLOjcRiAy+6WrRdjGgJ1I5ynNxgADii0kSRZNgUO ozKs3lhrXWF7VB7W2J8tC6cw97k4YbVtBtyOK96bwa2wRdpPLeAk+IsG/ykieWKDhS8WEEi j+XEB5nqyM2sPtBeIM50Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:O6OCXqrjj58=:14wTdNb3FQ8/pcoAVPl6go EDF5FvlDOnF4wzruIaBSzGxEikpTooCroliam611LXC9I57mx2Hr4J/H5sqVQvIimItofSuYd q5x+ryzGFqxWgTkS+ALvnPFyNwmFhPezZpSDaQkBw2lrTG1irgCwqx7akXpytXCTsOwqD2q8b 1B9g4E9sMO+7wWo0XogirIYb7o4xnW0OjDu59kRi/PwyG8A2UzidPJ/Unt+ah0VrBHxEEaptz Axa9P4NhPmeJnu39S4ZJ4KHh+6yo5Vwe0tb8h5nMUPDtxVH7r0FPgFQ+t0lJO+sGafYgM8/To Zhswf2dbjks6oENhOj+kAw485S8zJuR+L1o3nG+q2SK9IBD2PjDAny2Uu5nYX93mQ/LwkrDvQ pYglypajxP3uuN2+eUmu50jzQrNA5qSVGHcm2Qla5o2QRLJaWV3MBsiaVRe9Hk6h/nppm13oQ zAyCuZ/mJ89Y/J3Pw8/K5eMUknTPHKNu4ewRSEgVY9ReM4OrVHr30LOwKgB3FPiqbt6LgRNhf 1MNLmLTDfqGofVF5rCrhQZdAfKz98+qfpPeRB6xCRl4xcK3qcvfCRqP2oN+WTcRAbnLndh+fD CTo7cr0mv7r6w20/ExVs+EQlxRip8nnq/PaDz+xtPAjplSwpi5sq2GMGlatZ8REcldEMu2a0J vu6NVDYtK3VO0gHfwhmllLbWd+k/42CiIPJW3djjxJzDewt5JO82UML6YnhXN3H49ZvXdS/qK OX/V2IgueqcD8utLNJbdruTAXooymzsachiYJW2h7asPh+0s8snc5/zKnnf267NELadhPvZ/z b+KdPPI Reply-To: djgpp AT delorie DOT com Am 23.10.2016 08:04, schrieb Eli Zaretskii (eliz AT gnu DOT org) [via djgpp AT delorie DOT com]: > > 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. I think we have misunderstood. When I talked about open documentation I meant the documentation of DJGPP's open and fopen functions. And this documentation tells that it is possible to "open" a directory but that it is not possible neither to read nor to write to the directory. If DJGPP's implementations allow to "open" a directory in this sense it should only set an errno if it fails IMHO. Or it should not allow at all to "open" a directory because the OS does not support this. In the current condition I have to check if EACCES comes from a file or from a directory and reset it if it comes from a directory. Of course, I am not lobbying for removing this support. That would make porting efforts even more difficult. > > 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. No, the patch does not change '_open' at all. It changes 'open'. It records errno before '_open' is called and restores it if and only if the return value of '_open' does not finish 'open'. In this way, the rest of 'open' defines what value of errno will be. > > 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. I do not have preferences here as long as the check passes. I have choosen EISDIR because I have compiled grep on my linux box and inspected what the failing 'fread' returns and it is EISDIR. I have also installed mingw and msys 1.0 and tried to build grep but it failed and I had not the time to port grep to mingw. I have compiled grep-2.26 with cygwin, debian 8.2.0 and openSUSE 11.4 (my linux box). They all return EISDIR for the failing fread. These seems to indicate that EISDIR is the defacto value that have been choosen for this fread failure. > > 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. I do not think they check for EISDIR explicitly but for some range of error values and EACCES does not match. I will recheck if the test passes with the proposed error values by you and return. Regards, Juan M. Guerrero