* 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[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.41 2004/05/22 15:19:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.44 2008/04/17 22:17:54 jhb Exp $");
#include "namespace.h"
#include <sys/types.h>
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);
int serrno = errno;
/* make sure stdio is set up */
- if (!__sdidinit)
- __sinit();
+ pthread_once(&__sdidinit, __sinit);
FLOCKFILE(fp);
ret = _fseeko(fp, offset, whence, 0);
*/
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 {
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
- memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
+ memset(&fp->_mbstate, 0, sizeof(mbstate_t));
return (0);
}
fp->_r -= n;
}
fp->_flags &= ~__SEOF;
+ memset(&fp->_mbstate, 0, sizeof(mbstate_t));
return (0);
/*
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);
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
- memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
- if (ltest && ret > LONG_MAX) {
- fp->_flags |= __SERR;
- errno = EOVERFLOW;
- return (-1);
- }
+ memset(&fp->_mbstate, 0, sizeof(mbstate_t));
return (0);
}