This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] don't reset errno if no error occured


On 07/10/2010 04:34 PM, Ulrich Drepper wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 07/10/2010 07:18 AM, Matthias Klose wrote:
>   
>> [reported at https://launchpad.net/bugs/598299]
>>     
> This is just wrong.  Nobody must look ever at errno unless the return
> value of a function call says there has been an error.  If this is not
> the case errno can have any value.  Any code not expecting this is broken.
>   
Agreed.

Ulrich, the issue here is that we want to check whether an error
occurred *and* it's an EINTR. This is the code:

        // In general, no need to zero errno in advance if checking
        // for error first. However, C89/C99 (at variance with IEEE
        // 1003.1, f.i.) do not mandate that fclose must set errno
        // upon error.
        errno = 0;
        do
          __err = fclose(_M_cfile);
        while (__err && errno == EINTR);

thus, unless I made a mistake in searching the Standards, on non-Posix
systems does not seem safe to not zero errno in advance. Would it be
safe to leave out the zeroing for the glibc implementation? I'm asking
for fclose and for fflush.

In that case, we could just remove 'errno = 0' for the GNU/Linux targets
we (Matthias too) care about via a __GLIBC__ macro check, and everyone
we'll be happy.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]