X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..refs/heads/master:/stdio/FreeBSD/refill.c diff --git a/stdio/FreeBSD/refill.c b/stdio/FreeBSD/refill.c index edd8bb6..7daa062 100644 --- a/stdio/FreeBSD/refill.c +++ b/stdio/FreeBSD/refill.c @@ -13,10 +13,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -38,7 +34,7 @@ static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD: src/lib/libc/stdio/refill.c,v 1.18 2002/08/13 09:30:41 tjr Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/stdio/refill.c,v 1.20 2008/04/17 22:17:54 jhb Exp $"); #include "namespace.h" #include @@ -68,13 +64,12 @@ lflush(FILE *fp) * Refill a stdio buffer. * Return EOF on eof or error, 0 otherwise. */ -int -__srefill(FILE *fp) +__private_extern__ int +__srefill0(FILE *fp) { /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); + pthread_once(&__sdidinit, __sinit); ORIENT(fp, -1); @@ -110,7 +105,7 @@ __srefill(FILE *fp) if (HASUB(fp)) { FREEUB(fp); if ((fp->_r = fp->_ur) != 0) { - fp->_p = fp->_extra->_up; + fp->_p = fp->_up; return (0); } } @@ -134,6 +129,13 @@ __srefill(FILE *fp) if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) __sflush(fp); } + return (1); +} + +__private_extern__ int +__srefill1(FILE *fp) +{ + fp->_p = fp->_bf._base; fp->_r = _sread(fp, (char *)fp->_p, fp->_bf._size); fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ @@ -148,3 +150,13 @@ __srefill(FILE *fp) } return (0); } + +int +__srefill(FILE *fp) +{ + int ret; + + if ((ret = __srefill0(fp)) <= 0) + return ret; + return __srefill1(fp); +}