X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..6dccf0e0b5e80b7b6176e8d332e646175431bb3d:/stdio/FreeBSD/fseek.c diff --git a/stdio/FreeBSD/fseek.c b/stdio/FreeBSD/fseek.c index 3ff409b..9f45c9b 100644 --- a/stdio/FreeBSD/fseek.c +++ b/stdio/FreeBSD/fseek.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[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.40 2002/03/22 21:53:04 obrien Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.44 2008/04/17 22:17:54 jhb Exp $"); #include "namespace.h" #include @@ -64,8 +60,7 @@ fseek(fp, offset, whence) int serrno = errno; /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); + pthread_once(&__sdidinit, __sinit); FLOCKFILE(fp); ret = _fseeko(fp, (off_t)offset, whence, 1); @@ -85,8 +80,7 @@ fseeko(fp, offset, whence) int serrno = errno; /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); + pthread_once(&__sdidinit, __sinit); FLOCKFILE(fp); ret = _fseeko(fp, offset, whence, 0); @@ -237,7 +231,7 @@ _fseeko(fp, offset, whence, ltest) */ if (HASUB(fp)) { curoff += fp->_r; /* kill off ungetc */ - n = fp->_extra->_up - fp->_bf._base; + n = fp->_up - fp->_bf._base; curoff -= n; n += fp->_ur; } else { @@ -259,6 +253,7 @@ _fseeko(fp, offset, whence, ltest) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; + memset(&fp->_mbstate, 0, sizeof(mbstate_t)); return (0); } @@ -286,6 +281,7 @@ abspos: fp->_r -= n; } fp->_flags &= ~__SEOF; + memset(&fp->_mbstate, 0, sizeof(mbstate_t)); return (0); /* @@ -296,6 +292,11 @@ dumb: if (__sflush(fp) || (ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR) return (-1); + if (ltest && ret > LONG_MAX) { + fp->_flags |= __SERR; + errno = EOVERFLOW; + return (-1); + } /* success: clear EOF indicator and discard ungetc() data */ if (HASUB(fp)) FREEUB(fp); @@ -303,10 +304,6 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; - if (ltest && ret > LONG_MAX) { - fp->_flags |= __SERR; - errno = EOVERFLOW; - return (-1); - } + memset(&fp->_mbstate, 0, sizeof(mbstate_t)); return (0); }