[uClibc]patch: Loop on EINTR in stdio

Johan Adolfsson johan.adolfsson at axis.com
Thu Jun 7 10:36:08 UTC 2001


The following patch (indentation lost) will loop
on EINTR in _uClibc_fread (used by fread, fgets etc.)
glibc does that and without it I believe error handling 
from fgets() etc. is hard or impossible
to handle properly.

At least I had trouble with earlier version of uC-libc when
reading from a pipe to a program - when the program exists,
you may get an EINTR and you sometimes looses the last
bytes.

Does anyone see any problem with this solution?

/Johan

RCS file: /var/cvs/uClibc/libc/stdio/stdio.c,v
retrieving revision 1.23
diff -u -p -r1.23 stdio.c
--- stdio.c 2001/05/07 20:17:35 1.23
+++ stdio.c 2001/06/07 10:17:23
@@ -423,8 +423,12 @@ off_t _uClibc_fread(unsigned char *buf, 
  goto FROM_BUF;
  }
 
+/* Retry if EINTR */
+try:
  len = read(fp->fd, p, (unsigned) bytes);
  if (len < 0) {
+ if (errno == EINTR)
+ goto try;
  fp->mode |= __MODE_ERR;
  } else {
  p += len;







More information about the uClibc mailing list