Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created August 11, 2009 10:13
Show Gist options
  • Select an option

  • Save methodmissing/165733 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/165733 to your computer and use it in GitHub Desktop.
static long
io_fread(ptr, len, fptr)
char *ptr;
long len;
OpenFile *fptr;
{
long n = len;
int c;
int saved_errno;
while (n > 0) {
c = read_buffered_data(ptr, n, fptr->f);
if (c < 0) goto eof;
if (c > 0) {
ptr += c;
if ((n -= c) <= 0) break;
}
rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr);
clearerr(fptr->f);
TRAP_BEG;
c = getc(fptr->f);
TRAP_END;
if (c == EOF) {
eof:
if (ferror(fptr->f)) {
switch (errno) {
case EINTR:
#if defined(ERESTART)
case ERESTART:
#endif
clearerr(fptr->f);
continue;
case EAGAIN:
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
#endif
if (len > n) {
clearerr(fptr->f);
}
saved_errno = errno;
rb_warning("nonblocking IO#read is obsolete; use IO#readpartial or IO#sysread");
errno = saved_errno;
}
if (len == n) return 0;
}
break;
}
*ptr++ = c;
n--;
}
return len - n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment