mcedit problem (2)

Pavel Roskin proski at gnu.org
Fri Dec 21 23:33:23 UTC 2001


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.

> > fgetc returns -1 on error and on end of file, so additional check needed.

It's interesting that "info glibc" (glibc-2.2.4) doesn't mention what
fgetc() returns if the call is interrupted before any single character has
been read.  I would prefer not to rely on the assumption that it's EOF
(maybe it's documented somewhere else, but it's better to play safe).

>  I've also tried to reproduce this w/o success. I think we need to call
> clearerr(_unlocked?) on line 408 above. (If found some usenet posts that
> indicated that this is indeed necessary on Solaris. (Sorry, I that was
> last week and I didn't save them.))

Actually, clearerr() would clear the EOF state from the descriptor, which
would not help.

What needs to be done is "errno = 0".  I'm committing this patch.

============================
--- ChangeLog
+++ ChangeLog
@@ -1 +1,6 @@
+2001-12-21  Pavel Roskin  <proski at gnu.org>
+
+	* syntax.c (read_one_line): Clear errno before using it.  Don't
+	use the result of fgetc() if errno is EINTR.
+
 2001-11-28  Andrew V. Samoilov  <kai at cmail.ru>
--- syntax.c
+++ syntax.c
@@ -401,11 +401,12 @@ static int read_one_line (char **line, F
 #else
     p = syntax_malloc (len);
 #endif
+    errno = 0;
     for (;;) {
 	c = fgetc (f);
+	if (errno == EINTR)
+	    continue;
 	if (c == EOF) {
-	    if (errno == EINTR)
-		continue;
 	    r = 0;
 	    break;
 	} else if (c == '\n') {
============================

-- 
Regards,
Pavel Roskin




More information about the mc-devel mailing list