Re: mcedit problem (2)



On Friday, December 21, 2001 at 18:23, Pavel Roskin wrote:
> Hi, Bj?rn!
> 
> > > >404         for (;;) {
> > > >405             c = fgetc (f);
> > > >406             if (c == EOF) {
> > > >407                 if (errno == EINTR)
> > > >408                     continue;
> > > >---
> > > 
> > > I cannot reproduce this, but it is possible if previous system call was 
> > > interrupted.
>
> Exactly.  Just add "errno = EINTR" in the beginning of the function and 
> you have the problem.

The right fix is really this:

  for (;;) {
    c = fgetc(f);
    if (c == EOF) {
      if (ferror(f) && errno == EINTR)
        continue;

fgetc only changes errno if there's an error. Even if errno != 0, prior to
calling fgetc, fgetc won't change it. The only way to check for an error
is to use ferror(f). If ferror(f) is true then errno has been updated as
well.

Regards,

Oskar Liljeblad (oskar osk mine nu)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]