* 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.
static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__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 <errno.h>
* 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);
if (HASUB(fp)) {
FREEUB(fp);
if ((fp->_r = fp->_ur) != 0) {
- fp->_p = fp->_extra->_up;
+ fp->_p = fp->_up;
return (0);
}
}
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 */
}
return (0);
}
+
+int
+__srefill(FILE *fp)
+{
+ int ret;
+
+ if ((ret = __srefill0(fp)) <= 0)
+ return ret;
+ return __srefill1(fp);
+}