X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/1f2f436a38f7ae2d39a943ad2898d8fed4ed2e58..refs/heads/master:/stdio/FreeBSD/refill.c diff --git a/stdio/FreeBSD/refill.c b/stdio/FreeBSD/refill.c index a7d486f..7daa062 100644 --- a/stdio/FreeBSD/refill.c +++ b/stdio/FreeBSD/refill.c @@ -64,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); @@ -130,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 */ @@ -144,3 +150,13 @@ __srefill(FILE *fp) } return (0); } + +int +__srefill(FILE *fp) +{ + int ret; + + if ((ret = __srefill0(fp)) <= 0) + return ret; + return __srefill1(fp); +}