/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Read n bytes from a stream into a buffer
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
Sfio_t* f; /* read from this stream. */
size_t n; /* number of bytes to be read. */
#endif
{
SFMTXDECL(f);
if(!buf)
/* release peek lock */
SFMTXRETURN(f, 0);
}
else
{ /* actually read the data now */
if(n > 0)
f->here += n;
}
f->next += n;
SFMTXRETURN(f, n);
}
}
{ /* check stream mode */
SFMTXRETURN(f, (ssize_t)n);
}
{ if(r > (ssize_t)n)
r = (ssize_t)n;
if(s != f->next)
f->next += r;
s += r;
n -= r;
}
if(n <= 0) /* all done */
break;
/* exact IO is desirable for these cases */
if(SFDIRECT(f,n) ||
r = (ssize_t)n;
r = f->iosz; /* limit buffering */
else r = f->size; /* full buffering */
/* if read almost full size, then just do it direct */
r = (ssize_t)n;
/* read directly to user's buffer */
{ s += r;
n -= r;
if(r == 0 || n == 0) /* eof or eob */
break;
}
else goto do_filbuf;
}
else
{ do_filbuf:
if(justseek)
f->bits |= SF_JUSTSEEK;
if(SFFILBUF(f,-1) <= 0)
break;
}
}
r = s-begs;
SFMTXRETURN(f, r);
}