[uClibc]patch: Loop on EINTR in stdio

Michael Shmulevich michaels at jungo.com
Sat Jun 9 00:35:23 UTC 2001


To my taste, this goto backward is evil...
why not 

while(1)
{
    ....
    if(errno == EINTR)
      continue;
    ...
    break;
}

----- Original Message ----- 
From: "Johan Adolfsson" <johan.adolfsson at axis.com>
To: <uclibc at uclibc.org>
Sent: Thursday, June 07, 2001 12:36 PM
Subject: [uClibc]patch: Loop on EINTR in stdio


> 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;
> 
> 
> 
> 
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://uclibc.org/mailman/listinfo/uclibc
> 






More information about the uClibc mailing list